diff --git a/reading_machine/include/Action.hpp b/reading_machine/include/Action.hpp index 4afd9e6ff7a085c38a70a6aa6adc176ee263557e..a9b1517ab557f68317acd234407bf1136ad7f22d 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 da2a3beb551a8f2158ba1d34db1d7804b701e377..e5287bdb4e8834f3e2fc8f30fc8df95917b7584f 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 7717179acde5e28b8ca8d28d33f0e037e3a3bf3e..f32925c3fee73c1d786951fcd9a975114f02980b 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));