Added -report-all-factors, so that stdout is more verbose.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@300 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
bojar 2006-07-26 00:01:05 +00:00
parent 34cbaaf61a
commit b0f7cb32cb
10 changed files with 41 additions and 20 deletions

View File

@ -65,24 +65,28 @@ InputType*IOCommandLine::GetInput(InputType* in)
} }
// help fn // help fn
void OutputSurface(std::ostream &out, const Phrase &phrase) void OutputSurface(std::ostream &out, const Phrase &phrase, bool reportAllFactors)
{ {
size_t size = phrase.GetSize(); if (reportAllFactors == true) {
for (size_t pos = 0 ; pos < size ; pos++) out << phrase;
{ } else {
const Factor *factor = phrase.GetFactor(pos, Surface); size_t size = phrase.GetSize();
if (factor != NULL) { for (size_t pos = 0 ; pos < size ; pos++)
out << *factor << " "; {
const Factor *factor = phrase.GetFactor(pos, Surface);
if (factor != NULL) {
out << *factor << " ";
}
} }
} }
} }
void OutputSurface(std::ostream &out, const Hypothesis *hypo, bool reportSourceSpan) void OutputSurface(std::ostream &out, const Hypothesis *hypo, bool reportSourceSpan, bool reportAllFactors)
{ {
if ( hypo != NULL) if ( hypo != NULL)
{ {
OutputSurface(out, hypo->GetPrevHypo(), reportSourceSpan); OutputSurface(out, hypo->GetPrevHypo(), reportSourceSpan, reportAllFactors);
OutputSurface(out, hypo->GetPhrase()); OutputSurface(out, hypo->GetPhrase(), reportAllFactors);
if (reportSourceSpan == true if (reportSourceSpan == true
&& hypo->GetPhrase().GetSize() > 0) { && hypo->GetPhrase().GetSize() > 0) {
@ -101,14 +105,14 @@ void IOCommandLine::Backtrack(const Hypothesis *hypo){
} }
} }
void IOCommandLine::SetOutput(const Hypothesis *hypo, long /*translationId*/, bool reportSourceSpan) void IOCommandLine::SetOutput(const Hypothesis *hypo, long /*translationId*/, bool reportSourceSpan, bool reportAllFactors)
{ {
if (hypo != NULL) if (hypo != NULL)
{ {
TRACE_ERR("BEST HYPO: " << *hypo << endl); TRACE_ERR("BEST HYPO: " << *hypo << endl);
Backtrack(hypo); Backtrack(hypo);
OutputSurface(cout, hypo, reportSourceSpan); OutputSurface(cout, hypo, reportSourceSpan, reportAllFactors);
} }
else else
{ {
@ -132,7 +136,7 @@ void IOCommandLine::SetNBest(const LatticePathList &nBestList, long translationI
for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--) for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--)
{ {
const LatticeEdge &edge = *edges[currEdge]; const LatticeEdge &edge = *edges[currEdge];
OutputSurface(m_nBestFile, edge.GetTargetPhrase()); OutputSurface(m_nBestFile, edge.GetTargetPhrase(), false); // false for not reporting all factors
} }
m_nBestFile << " ||| "; m_nBestFile << " ||| ";

View File

@ -59,7 +59,7 @@ public:
, const std::string &nBestFilePath); , const std::string &nBestFilePath);
InputType* GetInput(InputType*); InputType* GetInput(InputType*);
void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan); void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan, bool reportAllFactors);
void SetNBest(const LatticePathList &nBestList, long translationId); void SetNBest(const LatticePathList &nBestList, long translationId);
void Backtrack(const Hypothesis *hypo); void Backtrack(const Hypothesis *hypo);
}; };

View File

@ -104,7 +104,7 @@ InputType *IOMySQL::GetInput(InputType*)
return NULL; return NULL;
} }
void IOMySQL::SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan) void IOMySQL::SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan, bool reportAllFactors)
{ {
//m_threadMySQL->SetTranslation(hypo, translationId); //m_threadMySQL->SetTranslation(hypo, translationId);
} }

View File

@ -69,7 +69,7 @@ public:
~IOMySQL(); ~IOMySQL();
void Connect(mysqlpp::Connection &conn); void Connect(mysqlpp::Connection &conn);
InputType *GetInput(InputType*); InputType *GetInput(InputType*);
void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan); void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan, bool reportAllFactors);
void SetNBest(const LatticePathList &nBestList, long translationId) void SetNBest(const LatticePathList &nBestList, long translationId)
{ {
} }

View File

@ -111,7 +111,10 @@ int main(int argc, char* argv[])
staticData.InitializeBeforeSentenceProcessing(*source); staticData.InitializeBeforeSentenceProcessing(*source);
Manager manager(*source, *translationOptionCollection, staticData); Manager manager(*source, *translationOptionCollection, staticData);
manager.ProcessSentence(); manager.ProcessSentence();
inputOutput->SetOutput(manager.GetBestHypothesis(), source->GetTranslationId(), staticData.GetReportSourceSpan()); inputOutput->SetOutput(manager.GetBestHypothesis(), source->GetTranslationId(),
staticData.GetReportSourceSpan(),
staticData.GetReportAllFactors()
);
// n-best // n-best
size_t nBestSize = staticData.GetNBestSize(); size_t nBestSize = staticData.GetNBestSize();

View File

@ -38,7 +38,7 @@ class InputOutput
public: public:
InputOutput(); InputOutput();
virtual InputType* GetInput(InputType*) = 0; virtual InputType* GetInput(InputType*) = 0;
virtual void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan) = 0; virtual void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan, bool reportAllFactors) = 0;
virtual void SetNBest(const LatticePathList &nBestList, long translationId) = 0; virtual void SetNBest(const LatticePathList &nBestList, long translationId) = 0;
virtual ~InputOutput(); virtual ~InputOutput();
virtual void Release(InputType*); virtual void Release(InputType*);

View File

@ -64,6 +64,7 @@ Parameter::Parameter()
AddParam("stack"); AddParam("stack");
AddParam("verbose"); AddParam("verbose");
AddParam("report-source-span"); AddParam("report-source-span");
AddParam("report-all-factors");
AddParam("drop-unknown"); AddParam("drop-unknown");
AddParam("inputtype"); AddParam("inputtype");
} }
@ -256,6 +257,7 @@ bool Parameter::LoadParam(int argc, char* argv[])
OverwriteParam("-s", "stack", argc, argv); OverwriteParam("-s", "stack", argc, argv);
OverwriteParam("-v", "verbose", argc, argv); OverwriteParam("-v", "verbose", argc, argv);
OverwriteParam("-report-source-span", "report-source-span", argc, argv); OverwriteParam("-report-source-span", "report-source-span", argc, argv);
OverwriteParam("-report-all-factors", "report-all-factors", argc, argv);
OverwriteParam("-drop-unknown", "drop-unknown", argc, argv); OverwriteParam("-drop-unknown", "drop-unknown", argc, argv);
OverwriteParam("-inputtype","inputtype",argc,argv); OverwriteParam("-inputtype","inputtype",argc,argv);
// check if parameters make sense // check if parameters make sense

View File

@ -93,6 +93,13 @@ bool StaticData::LoadParameters(int argc, char* argv[])
m_reportSourceSpan = false; m_reportSourceSpan = false;
// print all factors of output translations
if (m_parameter.GetParam("report-all-factors").size() > 0)
m_reportAllFactors = Scan<bool>(m_parameter.GetParam("report-all-factors")[0]);
else
m_reportAllFactors = false;
//input-factors //input-factors
const vector<string> &inputFactorVector = m_parameter.GetParam("input-factors"); const vector<string> &inputFactorVector = m_parameter.GetParam("input-factors");
for(size_t i=0; i<inputFactorVector.size(); i++) for(size_t i=0; i<inputFactorVector.size(); i++)

View File

@ -81,6 +81,7 @@ protected:
size_t m_verboseLevel; size_t m_verboseLevel;
bool m_reportSourceSpan; bool m_reportSourceSpan;
bool m_reportAllFactors;
public: public:
StaticData(); StaticData();
@ -209,6 +210,10 @@ public:
{ {
return m_reportSourceSpan; return m_reportSourceSpan;
} }
bool GetReportAllFactors() const
{
return m_reportAllFactors;
}
// for mert // for mert
size_t GetNBestSize() const size_t GetNBestSize() const

View File

@ -101,7 +101,7 @@ std::string Word::ToString(const FactorArray &factorArray)
const Factor *factor = factorArray[currFactor]; const Factor *factor = factorArray[currFactor];
if (factor != NULL) if (factor != NULL)
{ {
strme << *factor << ","; strme << *factor << "|";
} }
} }
string str = strme.str(); string str = strme.str();
@ -121,7 +121,7 @@ ostream& operator<<(ostream& out, const Word& word)
const Factor *factor = word.GetFactor(factorType); const Factor *factor = word.GetFactor(factorType);
if (factor != NULL) if (factor != NULL)
{ {
strme << *factor << ","; strme << *factor << "|";
} }
} }
string str = strme.str(); string str = strme.str();