From 993cb988b553379a33cfb2b816b606773b23b076 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Wed, 9 Oct 2019 22:16:39 +0200
Subject: [PATCH] Fixed floating word attachement in EOS

---
 transition_machine/src/ActionBank.cpp | 30 +++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/transition_machine/src/ActionBank.cpp b/transition_machine/src/ActionBank.cpp
index 1cdfba7..656e43f 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--)
         {
-- 
GitLab