From d848584f522993b8c72d2e23acaf625e3f812b01 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Thu, 11 Feb 2021 22:12:09 +0100
Subject: [PATCH] Fixed bug with splitword

---
 reading_machine/include/Action.hpp |  1 +
 reading_machine/src/Action.cpp     | 22 ++++++++++++++++++++++
 reading_machine/src/Transition.cpp |  4 ++--
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/reading_machine/include/Action.hpp b/reading_machine/include/Action.hpp
index 4afd9e6..a9b1517 100644
--- a/reading_machine/include/Action.hpp
+++ b/reading_machine/include/Action.hpp
@@ -65,6 +65,7 @@ class Action
   static Action setRootUpdateIdsEmptyStackIfSentChanged();
   static Action deprel(std::string value);
   static Action transformSuffix(std::string fromCol, Config::Object fromObj, int fromIndex, std::string toCol, Config::Object toObj, int toIndex, util::utf8string toRemove, util::utf8string toAdd);
+  static Action copyContent(std::string fromCol, Config::Object fromObj, int fromIndex, std::string toCol, Config::Object toObj, int toIndex);
   static Action uppercase(std::string col, Config::Object obj, int index);
   static Action uppercaseIndex(std::string col, Config::Object obj, int index, int inIndex);
   static Action lowercase(std::string col, Config::Object obj, int index);
diff --git a/reading_machine/src/Action.cpp b/reading_machine/src/Action.cpp
index da2a3be..e5287bd 100644
--- a/reading_machine/src/Action.cpp
+++ b/reading_machine/src/Action.cpp
@@ -1013,6 +1013,28 @@ Action Action::transformSuffix(std::string fromCol, Config::Object fromObj, int
   return {Type::Write, apply, undo, appliable}; 
 }
 
+Action Action::copyContent(std::string fromCol, Config::Object fromObj, int fromIndex, std::string toCol, Config::Object toObj, int toIndex)
+{
+  auto apply = [fromCol, fromObj, fromIndex, toCol, toObj, toIndex](Config & config, Action & a)
+  {
+    auto empty = util::utf8string();
+    transformSuffix(fromCol, fromObj, fromIndex, toCol, toObj, toIndex, empty, empty).apply(config, a);
+  };
+
+  auto undo = [toCol, toObj, toIndex, fromCol, fromObj, fromIndex](Config & config, Action & a)
+  {
+    auto empty = util::utf8string();
+    transformSuffix(fromCol, fromObj, fromIndex, toCol, toObj, toIndex, empty, empty).undo(config, a);
+  };
+
+  auto appliable = [](const Config &, const Action &)
+  {
+    return true;
+  };
+
+  return {Type::Write, apply, undo, appliable}; 
+}
+
 Action Action::uppercase(std::string col, Config::Object obj, int index)
 {
   auto apply = [col, obj, index](Config & config, Action & a)
diff --git a/reading_machine/src/Transition.cpp b/reading_machine/src/Transition.cpp
index 7717179..f32925c 100644
--- a/reading_machine/src/Transition.cpp
+++ b/reading_machine/src/Transition.cpp
@@ -319,8 +319,8 @@ void Transition::initSplitWord(std::vector<std::string> words)
   for (unsigned int i = 1; i < words.size(); i++)
   {
     sequence.emplace_back(Action::addHypothesisRelativeRelaxed("FORM", Config::Object::Buffer, i, words[i]));
-    sequence.emplace_back(Action::transformSuffix(Config::rawRangeStartColName, Config::Object::Buffer, 0, Config::rawRangeStartColName, Config::Object::Buffer, i, util::utf8string(), util::utf8string()));
-    sequence.emplace_back(Action::transformSuffix(Config::rawRangeEndColName, Config::Object::Buffer, 0, Config::rawRangeEndColName, Config::Object::Buffer, i, util::utf8string(), util::utf8string()));
+    sequence.emplace_back(Action::copyContent(Config::rawRangeStartColName, Config::Object::Buffer, 0, Config::rawRangeStartColName, Config::Object::Buffer, i));
+    sequence.emplace_back(Action::copyContent(Config::rawRangeEndColName, Config::Object::Buffer, 0, Config::rawRangeEndColName, Config::Object::Buffer, i));
   }
   sequence.emplace_back(Action::setMultiwordIds(words.size()-1));
 
-- 
GitLab