move OutputInput() to Hypothesis class

This commit is contained in:
Hieu Hoang 2014-12-28 22:09:38 +05:30
parent af0d0f02e1
commit f865e7e43c
6 changed files with 25 additions and 24 deletions

View File

@ -312,7 +312,7 @@ public:
}
if (addWordAlignInfo) {
stringstream wordAlignment;
IOWrapper::OutputAlignment(wordAlignment, hypo);
hypo->OutputAlignment(wordAlignment);
vector<xmlrpc_c::value> alignments;
string alignmentPair;
while (wordAlignment >> alignmentPair) {
@ -475,7 +475,8 @@ public:
if ((int)edges.size() > 0) {
stringstream wordAlignment;
IOWrapper::OutputAlignment(wordAlignment, edges[0]);
const Hypothesis *edge = edges[0];
edge->OutputAlignment(wordAlignment);
vector<xmlrpc_c::value> alignments;
string alignmentPair;
while (wordAlignment >> alignmentPair) {

View File

@ -472,5 +472,22 @@ void Hypothesis::OutputAlignment(ostream &out, const AlignmentInfo &ai, size_t s
}
void Hypothesis::OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo)
{
if (hypo->GetPrevHypo()) {
OutputInput(map, hypo->GetPrevHypo());
map[hypo->GetCurrSourceWordsRange().GetStartPos()] = &hypo->GetTranslationOption().GetInputPath().GetPhrase();
}
}
void Hypothesis::OutputInput(std::ostream& os) const
{
size_t len = this->GetInput().GetSize();
std::vector<const Phrase*> inp_phrases(len, 0);
OutputInput(inp_phrases, this);
for (size_t i=0; i<len; ++i)
if (inp_phrases[i]) os << *inp_phrases[i];
}
}

View File

@ -274,6 +274,9 @@ public:
static void OutputAlignment(std::ostream &out, const std::vector<const Hypothesis *> &edges);
static void OutputAlignment(std::ostream &out, const Moses::AlignmentInfo &ai, size_t sourceOffset, size_t targetOffset);
void OutputInput(std::ostream& os) const;
static void OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo);
};
std::ostream& operator<<(std::ostream& out, const Hypothesis& hypothesis);

View File

@ -593,24 +593,6 @@ void IOWrapper::OutputBestHypo(const std::vector<Word>& mbrBestHypo, long /*tra
out << endl;
}
void IOWrapper::OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo)
{
if (hypo->GetPrevHypo()) {
OutputInput(map, hypo->GetPrevHypo());
map[hypo->GetCurrSourceWordsRange().GetStartPos()] = &hypo->GetTranslationOption().GetInputPath().GetPhrase();
}
}
void IOWrapper::OutputInput(std::ostream& os, const Hypothesis* hypo)
{
size_t len = hypo->GetInput().GetSize();
std::vector<const Phrase*> inp_phrases(len, 0);
OutputInput(inp_phrases, hypo);
for (size_t i=0; i<len; ++i)
if (inp_phrases[i]) os << *inp_phrases[i];
}
void IOWrapper::OutputBestHypo(const Hypothesis *hypo, long /*translationId*/, char reportSegmentation, bool reportAllFactors)
{
if (hypo != NULL) {
@ -624,7 +606,7 @@ void IOWrapper::OutputBestHypo(const Hypothesis *hypo, long /*translationId*/, c
}
if (StaticData::Instance().IsPathRecoveryEnabled()) {
OutputInput(cout, hypo);
hypo->OutputInput(cout);
cout << "||| ";
}
OutputBestSurface(cout, hypo, *m_outputFactorOrder, reportSegmentation, reportAllFactors);

View File

@ -177,8 +177,6 @@ public:
void OutputBestHypo(const std::vector<Moses::Word>& mbrBestHypo, long /*translationId*/,
char reportSegmentation, bool reportAllFactors, std::ostream& out);
void OutputBestHypo(const Moses::TrellisPath &path, long /*translationId*/,char reportSegmentation, bool reportAllFactors, std::ostream &out);
void OutputInput(std::ostream& os, const Moses::Hypothesis* hypo);
void OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo);
void OutputPassthroughInformation(std::string& passthrough, const Moses::Hypothesis* hypo);
void OutputPassthroughInformation(std::ostream& os, const Moses::Hypothesis* hypo);

View File

@ -117,7 +117,7 @@ void TranslationTask::RunPb()
out << bestHypo->GetTotalScore() << ' ';
}
if (staticData.IsPathRecoveryEnabled()) {
m_ioWrapper.OutputInput(out, bestHypo);
bestHypo->OutputInput(out);
out << "||| ";
}