From c1698081b2c46c793ec604e6758d321a6c50cd70 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Thu, 14 May 2020 18:12:59 +0200 Subject: [PATCH] Fixed transitions cost --- reading_machine/src/Transition.cpp | 10 +++++++--- reading_machine/src/TransitionSet.cpp | 19 ------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/reading_machine/src/Transition.cpp b/reading_machine/src/Transition.cpp index 28aae30..2dd88ee 100644 --- a/reading_machine/src/Transition.cpp +++ b/reading_machine/src/Transition.cpp @@ -317,7 +317,7 @@ void Transition::initEagerRight_rel(std::string label) if (config.getConst(Config::EOSColName, config.getStack(0), 0) == Config::EOSSymbol1) return std::numeric_limits<int>::max(); - int cost = getNbLinkedWith(0, config.getStackSize()-1, Config::Object::Stack, config.getWordIndex(), config); + int cost = getNbLinkedWith(1, config.getStackSize()-1, Config::Object::Stack, config.getWordIndex(), config); if (bufferGovIndex != std::to_string(stackIndex)) ++cost; @@ -347,7 +347,7 @@ void Transition::initEagerRight() if (config.getConst(Config::EOSColName, config.getStack(0), 0) == Config::EOSSymbol1) return std::numeric_limits<int>::max(); - int cost = getNbLinkedWith(0, config.getStackSize()-1, Config::Object::Stack, config.getWordIndex(), config); + int cost = getNbLinkedWith(1, config.getStackSize()-1, Config::Object::Stack, config.getWordIndex(), config); if (bufferGovIndex != std::to_string(stackIndex)) ++cost; @@ -429,6 +429,7 @@ void Transition::initDeprel(std::string label) int Transition::getNbLinkedWith(int firstIndex, int lastIndex, Config::Object object, int withIndex, const Config & config) { auto govIndex = config.getConst(Config::headColName, withIndex, 0); + auto govIndexPredicted = config.getAsFeature(Config::headColName, withIndex); int nbLinkedWith = 0; @@ -442,8 +443,11 @@ int Transition::getNbLinkedWith(int firstIndex, int lastIndex, Config::Object ob continue; auto otherGovIndex = config.getConst(Config::headColName, index, 0); + auto otherGovIndexPredicted = config.getAsFeature(Config::headColName, index); - if (govIndex == std::to_string(index) || otherGovIndex == std::to_string(withIndex)) + if (govIndex == std::to_string(index) and util::isEmpty(govIndexPredicted)) + ++nbLinkedWith; + if (otherGovIndex == std::to_string(withIndex) and util::isEmpty(otherGovIndexPredicted)) ++nbLinkedWith; } diff --git a/reading_machine/src/TransitionSet.cpp b/reading_machine/src/TransitionSet.cpp index 66da993..5701c70 100644 --- a/reading_machine/src/TransitionSet.cpp +++ b/reading_machine/src/TransitionSet.cpp @@ -102,25 +102,6 @@ Transition * TransitionSet::getBestAppliableTransition(const Config & c) } } - if (!result) - { - for (unsigned int i = 0; i < transitions.size(); i++) - { - fmt::print(stderr, "{}\n", transitions[i].getName()); - if (!transitions[i].appliable(c)) - { - fmt::print(stderr, "not appliable\n"); - continue; - } - - fmt::print(stderr, "appliable\n"); - - int cost = transitions[i].getCost(c); - - fmt::print(stderr, "cost {}\n", cost); - } - } - return result; } -- GitLab