Skip to content
Snippets Groups Projects
Commit 5b2017a1 authored by Franck Dary's avatar Franck Dary
Browse files

Fixed updating and added function to move throught tokens

parent cfee03e4
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,12 @@ int main(int argc, char * argv[]) ...@@ -13,6 +13,12 @@ int main(int argc, char * argv[])
SubConfig config(goldConfig); SubConfig config(goldConfig);
while (config.moveWordIndex(1))
{
if (config.needsUpdate())
config.update();
}
fmt::print(stderr, "ok\n"); fmt::print(stderr, "ok\n");
std::scanf("%*c"); std::scanf("%*c");
......
...@@ -77,6 +77,10 @@ class Config ...@@ -77,6 +77,10 @@ class Config
void addToHistory(const std::string & transition); void addToHistory(const std::string & transition);
void addToStack(std::size_t index); void addToStack(std::size_t index);
bool isComment(std::size_t lineIndex) const; 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 #endif
...@@ -19,6 +19,7 @@ class SubConfig : public Config ...@@ -19,6 +19,7 @@ class SubConfig : public Config
SubConfig(BaseConfig & model); SubConfig(BaseConfig & model);
bool update(); bool update();
bool needsUpdate();
std::size_t getNbColumns() const override; std::size_t getNbColumns() const override;
std::size_t getColIndex(const std::string & colName) const override; std::size_t getColIndex(const std::string & colName) const override;
bool hasColIndex(const std::string & colName) const override; bool hasColIndex(const std::string & colName) const override;
......
...@@ -124,6 +124,9 @@ BaseConfig::BaseConfig(std::string_view mcdFilename, std::string_view tsvFilenam ...@@ -124,6 +124,9 @@ BaseConfig::BaseConfig(std::string_view mcdFilename, std::string_view tsvFilenam
if (not tsvFilename.empty()) if (not tsvFilename.empty())
readTSVInput(tsvFilename); readTSVInput(tsvFilename);
if (isComment(wordIndex))
moveWordIndex(1);
} }
std::size_t BaseConfig::getNbColumns() const std::size_t BaseConfig::getNbColumns() const
......
...@@ -84,9 +84,9 @@ void Config::printForDebug(FILE * dest) const ...@@ -84,9 +84,9 @@ void Config::printForDebug(FILE * dest) const
int firstLineToPrint = wordIndex; int firstLineToPrint = wordIndex;
int lastLineToPrint = wordIndex; int lastLineToPrint = wordIndex;
while (wordIndex-firstLineToPrint < windowSize and has(0, firstLineToPrint, 0)) while (wordIndex-firstLineToPrint < windowSize and has(0, firstLineToPrint-1, 0))
--firstLineToPrint; --firstLineToPrint;
while (lastLineToPrint - wordIndex < windowSize and has(0, lastLineToPrint, 0)) while (lastLineToPrint - wordIndex < windowSize and has(0, lastLineToPrint+1, 0))
++lastLineToPrint; ++lastLineToPrint;
std::vector<std::vector<std::string>> toPrint; std::vector<std::vector<std::string>> toPrint;
...@@ -220,6 +220,43 @@ util::utf8char Config::getLetter(int letterIndex) const ...@@ -220,6 +220,43 @@ util::utf8char Config::getLetter(int letterIndex) const
bool Config::isComment(std::size_t lineIndex) const bool Config::isComment(std::size_t lineIndex) const
{ {
auto iter = getConstIterator(0, lineIndex, 0); 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;
} }
...@@ -9,6 +9,11 @@ SubConfig::SubConfig(BaseConfig & model) : Config(model.rawInput), model(model) ...@@ -9,6 +9,11 @@ SubConfig::SubConfig(BaseConfig & model) : Config(model.rawInput), model(model)
update(); update();
} }
bool SubConfig::needsUpdate()
{
return wordIndex-firstLineIndex >= 0.8*getNbLines();
}
bool SubConfig::update() bool SubConfig::update()
{ {
unsigned int currentLastLineIndex = firstLineIndex + getNbLines(); unsigned int currentLastLineIndex = firstLineIndex + getNbLines();
...@@ -56,6 +61,9 @@ bool SubConfig::update() ...@@ -56,6 +61,9 @@ bool SubConfig::update()
util::myThrow("Update after a regression of wordIndex is not yet supported !"); util::myThrow("Update after a regression of wordIndex is not yet supported !");
} }
if (getNbLines() > newLineNumber)
resizeLines(newLineNumber);
firstLineIndex = newFirstLineIndex; firstLineIndex = newFirstLineIndex;
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment