diff --git a/dev/src/dev.cpp b/dev/src/dev.cpp index 3b496902b718df6f4f223b0ec50b6d99153691a3..3d1faed5c4efc6ec2994cc8fd2105024bf4ccc72 100644 --- a/dev/src/dev.cpp +++ b/dev/src/dev.cpp @@ -13,6 +13,12 @@ int main(int argc, char * argv[]) SubConfig config(goldConfig); + while (config.moveWordIndex(1)) + { + if (config.needsUpdate()) + config.update(); + } + fmt::print(stderr, "ok\n"); std::scanf("%*c"); diff --git a/reading_machine/include/Config.hpp b/reading_machine/include/Config.hpp index 08c273fc45ea78180973c7fb856b24ac7f7a7c47..12cb628389e328cf95769260bc56fdaf3f7465fa 100644 --- a/reading_machine/include/Config.hpp +++ b/reading_machine/include/Config.hpp @@ -77,6 +77,10 @@ class Config void addToHistory(const std::string & transition); void addToStack(std::size_t index); bool isComment(std::size_t lineIndex) const; + bool isMultiword(std::size_t lineIndex) const; + bool isEmptyNode(std::size_t lineIndex) const; + bool isToken(std::size_t lineIndex) const; + bool moveWordIndex(int relativeMovement); }; #endif diff --git a/reading_machine/include/SubConfig.hpp b/reading_machine/include/SubConfig.hpp index e8c8efe89118eeaaee9341ed6794accba4b3b71a..66725c8b4296c1b23bc7a3f41d4c7d7222004c4a 100644 --- a/reading_machine/include/SubConfig.hpp +++ b/reading_machine/include/SubConfig.hpp @@ -19,6 +19,7 @@ class SubConfig : public Config SubConfig(BaseConfig & model); bool update(); + bool needsUpdate(); std::size_t getNbColumns() const override; std::size_t getColIndex(const std::string & colName) const override; bool hasColIndex(const std::string & colName) const override; diff --git a/reading_machine/src/BaseConfig.cpp b/reading_machine/src/BaseConfig.cpp index 9a25963a405fea88d137a9ad4e892750e4b47eea..94352e6c2d92a53f54be17f7a86de9de93da26b7 100644 --- a/reading_machine/src/BaseConfig.cpp +++ b/reading_machine/src/BaseConfig.cpp @@ -124,6 +124,9 @@ BaseConfig::BaseConfig(std::string_view mcdFilename, std::string_view tsvFilenam if (not tsvFilename.empty()) readTSVInput(tsvFilename); + + if (isComment(wordIndex)) + moveWordIndex(1); } std::size_t BaseConfig::getNbColumns() const diff --git a/reading_machine/src/Config.cpp b/reading_machine/src/Config.cpp index 05084c551d207c83563c4d1054c7bd39393b0001..ed8d28727f2868d7bb2ebc57ecbd93ebb21a8581 100644 --- a/reading_machine/src/Config.cpp +++ b/reading_machine/src/Config.cpp @@ -84,9 +84,9 @@ void Config::printForDebug(FILE * dest) const int firstLineToPrint = wordIndex; int lastLineToPrint = wordIndex; - while (wordIndex-firstLineToPrint < windowSize and has(0, firstLineToPrint, 0)) + while (wordIndex-firstLineToPrint < windowSize and has(0, firstLineToPrint-1, 0)) --firstLineToPrint; - while (lastLineToPrint - wordIndex < windowSize and has(0, lastLineToPrint, 0)) + while (lastLineToPrint - wordIndex < windowSize and has(0, lastLineToPrint+1, 0)) ++lastLineToPrint; std::vector<std::vector<std::string>> toPrint; @@ -220,6 +220,43 @@ util::utf8char Config::getLetter(int letterIndex) const bool Config::isComment(std::size_t lineIndex) const { auto iter = getConstIterator(0, lineIndex, 0); - return !util::isEmpty(*iter) and iter->get()[0] == '#'; + return !iter->get().empty() and iter->get()[0] == '#'; +} + +bool Config::isMultiword(std::size_t lineIndex) const +{ + return hasColIndex("ID") && getConst("ID", lineIndex, 0).get().find('-') != std::string::npos; +} + +bool Config::isEmptyNode(std::size_t lineIndex) const +{ + return hasColIndex("ID") && getConst("ID", lineIndex, 0).get().find('.') != std::string::npos; +} + +bool Config::isToken(std::size_t lineIndex) const +{ + return !isComment(lineIndex) && !isMultiword(lineIndex) && !isEmptyNode(lineIndex); +} + +bool Config::moveWordIndex(int relativeMovement) +{ + int nbMovements = 0; + while (nbMovements != relativeMovement) + { + do + { + int oldVal = wordIndex; + relativeMovement > 0 ? wordIndex++ : wordIndex--; + if (!has(0,wordIndex,0)) + { + wordIndex = oldVal; + return false; + } + } + while (!isToken(wordIndex)); + nbMovements += relativeMovement > 0 ? 1 : -1; + } + + return true; } diff --git a/reading_machine/src/SubConfig.cpp b/reading_machine/src/SubConfig.cpp index cbe67ee11ec9243dea4208d3c820ad2a1a07b657..8ad29d3ea5bb4939bf5b186ef71b5c1b16c9a31c 100644 --- a/reading_machine/src/SubConfig.cpp +++ b/reading_machine/src/SubConfig.cpp @@ -9,6 +9,11 @@ SubConfig::SubConfig(BaseConfig & model) : Config(model.rawInput), model(model) update(); } +bool SubConfig::needsUpdate() +{ + return wordIndex-firstLineIndex >= 0.8*getNbLines(); +} + bool SubConfig::update() { unsigned int currentLastLineIndex = firstLineIndex + getNbLines(); @@ -56,6 +61,9 @@ bool SubConfig::update() util::myThrow("Update after a regression of wordIndex is not yet supported !"); } + if (getNbLines() > newLineNumber) + resizeLines(newLineNumber); + firstLineIndex = newFirstLineIndex; return true;