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

Improved printForDebug

parent fab4d2a1
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,18 @@ bool isEmpty(const std::basic_string<T> & s) ...@@ -54,6 +54,18 @@ bool isEmpty(const std::basic_string<T> & s)
return s.empty(); return s.empty();
} }
template <typename T>
std::size_t getSize(const std::vector<T> & s)
{
return s.size();
}
template <typename T>
std::size_t getSize(const boost::flyweight<T> & s)
{
return getSize(s.get());
}
template <typename T> template <typename T>
bool isEmpty(const boost::flyweight<T> & s) bool isEmpty(const boost::flyweight<T> & s)
{ {
......
...@@ -16,6 +16,9 @@ int main(int argc, char * argv[]) ...@@ -16,6 +16,9 @@ int main(int argc, char * argv[])
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
configs.emplace_back(config); configs.emplace_back(config);
configs[0].addToHistory("LEFT");
configs[0].addToHistory("RIGHT");
configs[0].wordIndex = 2000; configs[0].wordIndex = 2000;
configs[0].update(); configs[0].update();
configs[0].printForDebug(stdout); configs[0].printForDebug(stdout);
......
...@@ -71,7 +71,9 @@ class Config ...@@ -71,7 +71,9 @@ class Config
const String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const; const String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const;
String & getLastNotEmpty(const std::string & colName, int lineIndex); String & getLastNotEmpty(const std::string & colName, int lineIndex);
const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const; const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const;
void addToHistory(const String & transition); bool hasLetter(int letterIndex) const;
util::utf8char getLetter(int letterIndex) const;
void addToHistory(const std::string & transition);
}; };
#endif #endif
...@@ -75,6 +75,8 @@ void Config::print(FILE * dest) const ...@@ -75,6 +75,8 @@ void Config::print(FILE * dest) const
void Config::printForDebug(FILE * dest) const void Config::printForDebug(FILE * dest) const
{ {
static constexpr int windowSize = 5; static constexpr int windowSize = 5;
static constexpr int lettersWindowSize = 40;
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, 0))
...@@ -84,6 +86,11 @@ void Config::printForDebug(FILE * dest) const ...@@ -84,6 +86,11 @@ void Config::printForDebug(FILE * dest) const
std::vector<std::vector<std::string>> toPrint; std::vector<std::vector<std::string>> toPrint;
toPrint.emplace_back();
toPrint.back().emplace_back("");
for (unsigned int i = 0; i < getNbColumns(); i++)
toPrint.back().emplace_back(getColName(i));
for (int line = firstLineToPrint; line <= lastLineToPrint; line++) for (int line = firstLineToPrint; line <= lastLineToPrint; line++)
{ {
toPrint.emplace_back(); toPrint.emplace_back();
...@@ -97,14 +104,33 @@ void Config::printForDebug(FILE * dest) const ...@@ -97,14 +104,33 @@ void Config::printForDebug(FILE * dest) const
for (unsigned int col = 0; col < line.size()-1; col++) for (unsigned int col = 0; col < line.size()-1; col++)
colLength[col] = std::max((int)colLength[col], util::printedLength(line[col])); colLength[col] = std::max((int)colLength[col], util::printedLength(line[col]));
for (auto & line : toPrint) int lengthSum = 2*getNbColumns();
for (auto & val : colLength)
lengthSum += val;
std::string longLine = fmt::format("{:-<{}}", "", lengthSum);
std::string historyStr = "";
for (auto & h : history)
{ {
for (unsigned int col = 0; col < line.size()-1; col++) historyStr += h;
if (col == 0) historyStr += ",";
fmt::print(dest, "{:>{}}", line[col], colLength[col]); }
else if (!historyStr.empty())
fmt::print(dest, "{:<{}}{}", line[col], colLength[col], col == line.size()-2 ? "\n" : "\t"); historyStr.pop_back();
if (line.back() == EOSSymbol1) fmt::print(dest, "{}\n", longLine);
for (std::size_t index = characterIndex; index < util::getSize(rawInput) and index - characterIndex < lettersWindowSize; index++)
fmt::print(dest, "{}", getLetter(index));
fmt::print(dest, "\n{}\n", longLine);
fmt::print(dest, "wordIndex={} characterIndex={}\nhistory=({})\n", wordIndex, characterIndex, historyStr);
fmt::print(dest, "{}\n", longLine);
for (unsigned int line = 0; line < toPrint.size(); line++)
{
if (line == 1)
fmt::print(dest, "{}\n", longLine);
for (unsigned int col = 0; col < toPrint[line].size()-1; col++)
fmt::print(dest, "{}{:>{}}{}", toPrint[line][col], "", colLength[col]-util::printedLength(toPrint[line][col]), col == toPrint[line].size()-2 ? "\n" : "\t");
if (toPrint[line].back() == EOSSymbol1)
fmt::print(dest, "\n"); fmt::print(dest, "\n");
} }
} }
...@@ -151,8 +177,18 @@ Config::ConstValueIterator Config::getConstIterator(int colIndex, int lineIndex, ...@@ -151,8 +177,18 @@ Config::ConstValueIterator Config::getConstIterator(int colIndex, int lineIndex,
return lines.begin() + getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex) + hypothesisIndex; return lines.begin() + getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex) + hypothesisIndex;
} }
void Config::addToHistory(const Config::String & transition) void Config::addToHistory(const std::string & transition)
{
history.push_back(String(transition));
}
bool Config::hasLetter(int letterIndex) const
{
return letterIndex >= 0 and letterIndex < (int)util::getSize(rawInput);
}
util::utf8char Config::getLetter(int letterIndex) const
{ {
history.push_back(transition); return rawInput.get()[letterIndex];
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment