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

Made function getAsFeature to get element from hyp or ref depending on wether...

Made function getAsFeature to get element from hyp or ref depending on wether its column is predicted or not
parent a0ee9eda
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,7 @@ class Config
String & getLastNotEmptyHyp(int colIndex, int lineIndex);
const String & getLastNotEmptyHypConst(int colIndex, int lineIndex) const;
const String & getLastNotEmptyConst(int colIndex, int lineIndex) const;
const String & getAsFeature(int colIndex, int lineIndex) const;
ValueIterator getIterator(int colIndex, int lineIndex, int hypothesisIndex);
ConstValueIterator getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const;
......@@ -82,6 +83,7 @@ class Config
const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const;
String & getLastNotEmptyHyp(const std::string & colName, int lineIndex);
const String & getLastNotEmptyHypConst(const std::string & colName, int lineIndex) const;
const String & getAsFeature(const std::string & colName, int lineIndex) const;
String & getFirstEmpty(int colIndex, int lineIndex);
String & getFirstEmpty(const std::string & colName, int lineIndex);
bool hasCharacter(int letterIndex) const;
......
......@@ -91,20 +91,20 @@ void Config::print(FILE * dest) const
}
for (unsigned int i = 0; i < getNbColumns()-1; i++)
{
auto & colContent = isPredicted(getColName(i)) ? getLastNotEmptyHypConst(i, getFirstLineIndex()+line) : getLastNotEmptyConst(i, getFirstLineIndex()+line);
auto & colContent = getAsFeature(i, getFirstLineIndex()+line);
std::string valueToPrint = colContent;
try
{
if (getColName(i) == headColName)
if (valueToPrint != "0")
valueToPrint = getLastNotEmptyConst(idColName, std::stoi(valueToPrint));
valueToPrint = getAsFeature(idColName, std::stoi(valueToPrint));
} catch(std::exception &) {}
if (valueToPrint.empty())
valueToPrint = "_";
currentSequence.emplace_back(fmt::format("{}{}", valueToPrint, i < getNbColumns()-2 ? "\t" : "\n"));
}
auto & eosColContent = isPredicted(EOSColName) ? getLastNotEmptyHypConst(EOSColName, getFirstLineIndex()+line) : getLastNotEmptyConst(EOSColName, getFirstLineIndex()+line);
auto & eosColContent = getAsFeature(EOSColName, getFirstLineIndex()+line);
if (eosColContent == EOSSymbol1)
flushCurrentSequence();
}
......@@ -142,14 +142,14 @@ void Config::printForDebug(FILE * dest) const
toPrint.back().emplace_back(line == (int)wordIndex ? "=>" : "");
for (unsigned int i = 0; i < getNbColumns(); i++)
{
auto & colContent = isPredicted(getColName(i)) ? getLastNotEmptyHypConst(i, line) : getLastNotEmptyConst(i, line);
auto & colContent = getAsFeature(i, line);
std::string toPrintCol = colContent;
try
{
if (getColName(i) == headColName)
if (toPrintCol != "0")
toPrintCol = getLastNotEmptyConst(idColName, std::stoi(toPrintCol));
} catch(std::exception &) {}
toPrintCol = getAsFeature(idColName, std::stoi(toPrintCol));
} catch(std::exception & e) {util::myThrow(fmt::format("toPrintCol='{}' {}", toPrintCol, e.what()));}
toPrint.back().emplace_back(util::shrink(toPrintCol, maxWordLength));
}
}
......@@ -178,7 +178,7 @@ void Config::printForDebug(FILE * dest) const
if (hasColIndex(idColName))
{
if (has(idColName, s, 0))
stackStr += getLastNotEmptyConst(idColName, s);
stackStr += getAsFeature(idColName, s);
else
stackStr += "?";
}
......@@ -267,6 +267,19 @@ const Config::String & Config::getLastNotEmptyHypConst(int colIndex, int lineInd
return lines[baseIndex+1];
}
const Config::String & Config::getAsFeature(int colIndex, int lineIndex) const
{
if (isPredicted(getColName(colIndex)))
return getLastNotEmptyHypConst(colIndex, lineIndex);
return getLastNotEmptyConst(colIndex, lineIndex);
}
const Config::String & Config::getAsFeature(const std::string & colName, int lineIndex) const
{
return getAsFeature(getColIndex(colName), lineIndex);
}
Config::String & Config::getLastNotEmpty(const std::string & colName, int lineIndex)
{
return getLastNotEmpty(getColIndex(colName), lineIndex);
......
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