diff --git a/reading_machine/src/Action.cpp b/reading_machine/src/Action.cpp index ecbcff7e220bd04769adc1a9ea3fbdcf3072538a..6cf16785636a7d8e1a2b820ae8217292e0331511 100644 --- a/reading_machine/src/Action.cpp +++ b/reading_machine/src/Action.cpp @@ -205,6 +205,7 @@ Action Action::setRoot() auto apply = [](Config & config, Action & a) { int rootIndex = -1; + int firstSentenceIndex = -1; for (int i = config.getStack(0); true; --i) { @@ -220,6 +221,8 @@ Action Action::setRoot() if (config.getLastNotEmptyHypConst(Config::EOSColName, i) == Config::EOSSymbol1) break; + firstSentenceIndex = i; + if (util::isEmpty(config.getLastNotEmptyHypConst(Config::headColName, i))) { rootIndex = i; @@ -253,6 +256,11 @@ Action Action::setRoot() config.getFirstEmpty(Config::headColName, i) = std::to_string(rootIndex); } } + else + { + if (std::stoi(config.getLastNotEmptyHypConst(Config::headColName, i)) < firstSentenceIndex) + config.getFirstEmpty(Config::headColName, i) = std::to_string(rootIndex); + } } };