From 35d05a121ea58c905f7ba36ba4c81c5554179f20 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Sat, 19 Oct 2019 20:44:31 +0200
Subject: [PATCH] Fixed eos when its ref

---
 transition_machine/include/Config.hpp |  1 +
 transition_machine/src/Config.cpp     | 34 +++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/transition_machine/include/Config.hpp b/transition_machine/include/Config.hpp
index b80b047..bf7327a 100644
--- a/transition_machine/include/Config.hpp
+++ b/transition_machine/include/Config.hpp
@@ -100,6 +100,7 @@ class Config
     /// @return The name of this Tape.
     const std::string & getName();
     void setKnown(bool known);
+    bool getKnown();
     /// @brief Move the head of this tape.
     ///
     /// @param mvt The relative movement to apply to the head.
diff --git a/transition_machine/src/Config.cpp b/transition_machine/src/Config.cpp
index d790e39..82a3867 100644
--- a/transition_machine/src/Config.cpp
+++ b/transition_machine/src/Config.cpp
@@ -264,6 +264,14 @@ void Config::fillTapesWithInput()
     while (tape.hypSize() < maxTapeSize)
       tape.addToHyp("");
   }
+
+  auto & eos = getTape(ProgramParameters::sequenceDelimiterTape);
+  for (int i = 0; i < eos.hypSize(); i++)
+  {
+    eos.setHyp(i, "_");
+    if (eos.getRef(i).empty())
+      eos.setRef(i, "_");
+  }
 }
 
 void Config::printForDebug(FILE * output)
@@ -371,10 +379,23 @@ void Config::printAsOutput(FILE * output, int dataIndex, int realIndex, bool for
 
   ProgramOutput::instance.addLine(output, toPrint, realIndex);
 
+  auto & eos = getTape(ProgramParameters::sequenceDelimiterTape);
+
   if (!ProgramParameters::delayedOutput)
   {
-    auto eos = forceRef ?  getTape(ProgramParameters::sequenceDelimiterTape).getRef(dataIndex-head) : getTape(ProgramParameters::sequenceDelimiterTape)[dataIndex-head];
-    if (eos == ProgramParameters::sequenceDelimiter)
+    std::string eosStr;
+    if (forceRef)
+    {
+      eosStr = eos.getRef(dataIndex-head);
+    }
+    else
+    {
+      eosStr = eos.getHyp(dataIndex-head);
+      if (eosStr.empty())
+        eosStr = eos[dataIndex-head];
+    }
+
+    if (eosStr == ProgramParameters::sequenceDelimiter)
       fprintf(output, "\n");
   }
 
@@ -463,6 +484,11 @@ const std::string & Config::Tape::operator[](int relativeIndex)
   return getHyp(relativeIndex);
 }
 
+bool Config::Tape::getKnown()
+{
+  return isKnown;
+}
+
 float Config::Tape::getEntropy(int relativeIndex)
 {
   if(isKnown)
@@ -888,10 +914,10 @@ void Config::updateIdsInSequence()
   int sentenceEnd = stackHasIndex(0) ? stackGetElem(0) : getHead();
   auto & eos = getTape(ProgramParameters::sequenceDelimiterTape);
   auto & ids = getTape("ID");
-  while (sentenceEnd >= 0 && eos[sentenceEnd-getHead()] != ProgramParameters::sequenceDelimiter)
+  while (sentenceEnd >= 0 && eos.getHyp(sentenceEnd-getHead()) != ProgramParameters::sequenceDelimiter)
     sentenceEnd--;
   int sentenceStart = std::max(0,sentenceEnd-1);
-  while (sentenceStart >= 0 && eos[sentenceStart-getHead()] != ProgramParameters::sequenceDelimiter)
+  while (sentenceStart >= 0 && eos.getHyp(sentenceStart-getHead()) != ProgramParameters::sequenceDelimiter)
     sentenceStart--;
   sentenceStart++;
 
-- 
GitLab