diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-28 19:39:38 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-28 19:39:38 +0300 |
commit | f865e7e43c8f593cce75ee7157d77c4b94e95814 (patch) | |
tree | 4c420e412bc357e3400fbd7ff6a204830990e58c | |
parent | af0d0f02e199e618b06dcbfa083f06e831f44146 (diff) |
move OutputInput() to Hypothesis class
-rw-r--r-- | contrib/server/mosesserver.cpp | 5 | ||||
-rw-r--r-- | moses/Hypothesis.cpp | 17 | ||||
-rw-r--r-- | moses/Hypothesis.h | 3 | ||||
-rw-r--r-- | moses/IOWrapper.cpp | 20 | ||||
-rw-r--r-- | moses/IOWrapper.h | 2 | ||||
-rw-r--r-- | moses/TranslationTask.cpp | 2 |
6 files changed, 25 insertions, 24 deletions
diff --git a/contrib/server/mosesserver.cpp b/contrib/server/mosesserver.cpp index a2e7b9183..ab6e3b7c0 100644 --- a/contrib/server/mosesserver.cpp +++ b/contrib/server/mosesserver.cpp @@ -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) { diff --git a/moses/Hypothesis.cpp b/moses/Hypothesis.cpp index 210ee6ea5..b0a24d736 100644 --- a/moses/Hypothesis.cpp +++ b/moses/Hypothesis.cpp @@ -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]; +} + } diff --git a/moses/Hypothesis.h b/moses/Hypothesis.h index 7449e0b79..8e160b11e 100644 --- a/moses/Hypothesis.h +++ b/moses/Hypothesis.h @@ -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); diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index f2926a86c..e7f1ba565 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -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); diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index 89e176da1..440c9d3c7 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -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); diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index d99ad4450..c72196173 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -117,7 +117,7 @@ void TranslationTask::RunPb() out << bestHypo->GetTotalScore() << ' '; } if (staticData.IsPathRecoveryEnabled()) { - m_ioWrapper.OutputInput(out, bestHypo); + bestHypo->OutputInput(out); out << "||| "; } |