From ffca1378172da2061d56101f8b0a3461d64a13e1 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Mon, 8 Feb 2021 14:02:51 +0100 Subject: [PATCH] Fixed filing of columns rawRange --- reading_machine/src/Action.cpp | 15 +++++++++------ reading_machine/src/Transition.cpp | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/reading_machine/src/Action.cpp b/reading_machine/src/Action.cpp index c158808..75ca4fa 100644 --- a/reading_machine/src/Action.cpp +++ b/reading_machine/src/Action.cpp @@ -80,9 +80,6 @@ Action Action::consumeCharacterIndex(const util::utf8string & consumed) { auto apply = [consumed](Config & config, Action &) { - config.getLastNotEmptyHyp(Config::rawRangeStartColName, config.getWordIndex()) = fmt::format("{}", config.getCharacterIndex()); - config.getLastNotEmptyHyp(Config::rawRangeEndColName, config.getWordIndex()) = fmt::format("{}", config.getCharacterIndex() + consumed.size()); - config.moveCharacterIndex(consumed.size()); }; @@ -586,8 +583,7 @@ Action Action::addCharsToCol(const std::string & col, int n, Config::Object obje { if (util::isEmpty(config.getAsFeature(Config::rawRangeStartColName, index))) config.getLastNotEmptyHyp(Config::rawRangeStartColName, index) = fmt::format("{}", config.getCharacterIndex()); - if (util::isEmpty(config.getAsFeature(Config::rawRangeEndColName, index))) - config.getLastNotEmptyHyp(Config::rawRangeEndColName, index) = fmt::format("{}", config.getCharacterIndex()); + config.getLastNotEmptyHyp(Config::rawRangeEndColName, index) = fmt::format("{}", config.getCharacterIndex()); int curEndValue = std::stoi(config.getAsFeature(Config::rawRangeEndColName, index)); config.getLastNotEmptyHyp(Config::rawRangeEndColName, index) = fmt::format("{}", curEndValue+n); } @@ -753,8 +749,15 @@ Action Action::updateIds(int bufferIndex) if (config.has(0,firstIndexOfSentence,0)) { std::string textMetadata = "# text = "; - for (auto i = std::stoi(config.getAsFeature(Config::rawRangeStartColName, firstIndexOfSentence)); i < std::stoi(config.getAsFeature(Config::rawRangeEndColName, lineIndex)); i++) + int firstIndex = 0; + int lastIndex = 0; + try {firstIndex = std::stoi(config.getAsFeature(Config::rawRangeStartColName, firstIndexOfSentence));} + catch (std::exception & e) {util::myThrow(fmt::format("{} : '{}'", e.what(), config.getAsFeature(Config::rawRangeStartColName, firstIndexOfSentence)));} + try {lastIndex = std::stoi(config.getAsFeature(Config::rawRangeEndColName, lineIndex));} + catch (std::exception & e) {util::myThrow(fmt::format("{} : '{}'", e.what(), config.getAsFeature(Config::rawRangeEndColName, lineIndex)));} + for (auto i = firstIndex; i < lastIndex; i++) textMetadata = fmt::format("{}{}", textMetadata, config.getLetter(i)); + config.getLastNotEmptyHyp(Config::commentsColName, firstIndexOfSentence) = fmt::format("{}\n# sent_id = {}", textMetadata, config.getAsFeature(Config::sentIdColName, firstIndexOfSentence)); } }; diff --git a/reading_machine/src/Transition.cpp b/reading_machine/src/Transition.cpp index 1b8d309..db34591 100644 --- a/reading_machine/src/Transition.cpp +++ b/reading_machine/src/Transition.cpp @@ -317,7 +317,11 @@ void Transition::initSplitWord(std::vector<std::string> words) sequence.emplace_back(Action::addCharsToCol("FORM", consumedWord.size(), Config::Object::Buffer, 0)); sequence.emplace_back(Action::consumeCharacterIndex(consumedWord)); 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::setMultiwordIds(words.size()-1)); costDynamic = [words](const Config & config) -- GitLab