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
Branches
No related tags found
No related merge requests found
...@@ -67,6 +67,7 @@ class Config ...@@ -67,6 +67,7 @@ class Config
String & getLastNotEmptyHyp(int colIndex, int lineIndex); String & getLastNotEmptyHyp(int colIndex, int lineIndex);
const String & getLastNotEmptyHypConst(int colIndex, int lineIndex) const; const String & getLastNotEmptyHypConst(int colIndex, int lineIndex) const;
const String & getLastNotEmptyConst(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); ValueIterator getIterator(int colIndex, int lineIndex, int hypothesisIndex);
ConstValueIterator getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const; ConstValueIterator getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const;
...@@ -82,6 +83,7 @@ class Config ...@@ -82,6 +83,7 @@ class Config
const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const; const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const;
String & getLastNotEmptyHyp(const std::string & colName, int lineIndex); String & getLastNotEmptyHyp(const std::string & colName, int lineIndex);
const String & getLastNotEmptyHypConst(const std::string & colName, int lineIndex) const; 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(int colIndex, int lineIndex);
String & getFirstEmpty(const std::string & colName, int lineIndex); String & getFirstEmpty(const std::string & colName, int lineIndex);
bool hasCharacter(int letterIndex) const; bool hasCharacter(int letterIndex) const;
......
...@@ -91,20 +91,20 @@ void Config::print(FILE * dest) const ...@@ -91,20 +91,20 @@ void Config::print(FILE * dest) const
} }
for (unsigned int i = 0; i < getNbColumns()-1; i++) 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; std::string valueToPrint = colContent;
try try
{ {
if (getColName(i) == headColName) if (getColName(i) == headColName)
if (valueToPrint != "0") if (valueToPrint != "0")
valueToPrint = getLastNotEmptyConst(idColName, std::stoi(valueToPrint)); valueToPrint = getAsFeature(idColName, std::stoi(valueToPrint));
} catch(std::exception &) {} } catch(std::exception &) {}
if (valueToPrint.empty()) if (valueToPrint.empty())
valueToPrint = "_"; valueToPrint = "_";
currentSequence.emplace_back(fmt::format("{}{}", valueToPrint, i < getNbColumns()-2 ? "\t" : "\n")); 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) if (eosColContent == EOSSymbol1)
flushCurrentSequence(); flushCurrentSequence();
} }
...@@ -142,14 +142,14 @@ void Config::printForDebug(FILE * dest) const ...@@ -142,14 +142,14 @@ void Config::printForDebug(FILE * dest) const
toPrint.back().emplace_back(line == (int)wordIndex ? "=>" : ""); toPrint.back().emplace_back(line == (int)wordIndex ? "=>" : "");
for (unsigned int i = 0; i < getNbColumns(); i++) 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; std::string toPrintCol = colContent;
try try
{ {
if (getColName(i) == headColName) if (getColName(i) == headColName)
if (toPrintCol != "0") if (toPrintCol != "0")
toPrintCol = getLastNotEmptyConst(idColName, std::stoi(toPrintCol)); toPrintCol = getAsFeature(idColName, std::stoi(toPrintCol));
} catch(std::exception &) {} } catch(std::exception & e) {util::myThrow(fmt::format("toPrintCol='{}' {}", toPrintCol, e.what()));}
toPrint.back().emplace_back(util::shrink(toPrintCol, maxWordLength)); toPrint.back().emplace_back(util::shrink(toPrintCol, maxWordLength));
} }
} }
...@@ -178,7 +178,7 @@ void Config::printForDebug(FILE * dest) const ...@@ -178,7 +178,7 @@ void Config::printForDebug(FILE * dest) const
if (hasColIndex(idColName)) if (hasColIndex(idColName))
{ {
if (has(idColName, s, 0)) if (has(idColName, s, 0))
stackStr += getLastNotEmptyConst(idColName, s); stackStr += getAsFeature(idColName, s);
else else
stackStr += "?"; stackStr += "?";
} }
...@@ -267,6 +267,19 @@ const Config::String & Config::getLastNotEmptyHypConst(int colIndex, int lineInd ...@@ -267,6 +267,19 @@ const Config::String & Config::getLastNotEmptyHypConst(int colIndex, int lineInd
return lines[baseIndex+1]; 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) Config::String & Config::getLastNotEmpty(const std::string & colName, int lineIndex)
{ {
return getLastNotEmpty(getColIndex(colName), lineIndex); return getLastNotEmpty(getColIndex(colName), lineIndex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment