diff --git a/transition_machine/src/ActionBank.cpp b/transition_machine/src/ActionBank.cpp index 1cdfba7c6baa404dec53c8b5039834ffffa6eb77..656e43f1bbc5d42c3ab9ab3a17647bbf57062500 100644 --- a/transition_machine/src/ActionBank.cpp +++ b/transition_machine/src/ActionBank.cpp @@ -595,6 +595,36 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na simpleBufferWrite(c, "GOV", "0", rootIndex-b0); simpleBufferWrite(c, "LABEL", "root", rootIndex-b0); + // Attaching floating words to new root + int sentenceEnd = b0; + auto & eos = c.getTape(ProgramParameters::sequenceDelimiterTape); + while (sentenceEnd >= 0 && eos[sentenceEnd-b0] != ProgramParameters::sequenceDelimiter) + sentenceEnd--; + int sentenceStart = std::max(0,sentenceEnd-1); + while (sentenceStart >= 0 && eos[sentenceStart-b0] != ProgramParameters::sequenceDelimiter) + sentenceStart--; + sentenceStart++; + + if (sentenceEnd < 0) + { + sentenceStart = 0; + sentenceEnd = eos.hypSize()-1; + } + + for (int i = sentenceStart; i <= sentenceEnd; i++) + { + if (split(ids.getRef(i-b0), '-').size() > 1) + continue; + if (split(ids.getRef(i-b0), '.').size() > 1) + continue; + if (govs.getHyp(i-b0).empty()) + { + simpleBufferWrite(c, "GOV", std::to_string(rootIndex-i), i-b0); + simpleBufferWrite(c, "LABEL", "_", i-b0); + ba.data += "+"+std::to_string(i-b0); + } + } + // Delete the arcs from the previous sentence to the new sentence for (int i = b0; i > c.stackTop(); i--) {