From a45d405b651db8f7ef7c8c92435933237025629f Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Wed, 17 Feb 2021 15:18:03 +0100
Subject: [PATCH] Corrected problem where mcd was not propagated in lineByLine
 mode

---
 common/src/util.cpp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/common/src/util.cpp b/common/src/util.cpp
index f5717be..a30e4a3 100644
--- a/common/src/util.cpp
+++ b/common/src/util.cpp
@@ -376,6 +376,7 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename
 
   char lineBuffer[100000];
   bool inputHasBeenRead = false;
+  std::string mcdLine;
 
   sentences.emplace_back();
   while (!std::feof(file))
@@ -383,9 +384,12 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename
     if (lineBuffer != std::fgets(lineBuffer, 100000, file))
       break;
 
-    std::string_view line(lineBuffer);
+    std::string line(lineBuffer);
     sentences.back().emplace_back(line);
 
+    if (line.back() == '\n')
+      line.pop_back();
+
     if (line.size() < 3)
     {
       if (!inputHasBeenRead)
@@ -395,6 +399,12 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename
       continue;
     }
 
+    if (util::doIfNameMatch(std::regex("(?:(?:\\s|\\t)*)#(?:(?:\\s|\\t)*)global.columns(?:(?:\\s|\\t)*)=(?:(?:\\s|\\t)*)(.+)"), line, [&mcdLine, &line](const auto &)
+          {
+            mcdLine = line;
+          }))
+      continue;
+
     inputHasBeenRead = true;
   }
 
@@ -402,6 +412,10 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename
     sentences.pop_back();
 
   std::fclose(file);
+
+  if (not mcdLine.empty())
+    for (auto & sentence : sentences)
+     sentence.insert(sentence.begin(), mcdLine);
   
   return sentences;
 }
-- 
GitLab