diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-10 14:28:47 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-10 14:28:47 +0300 |
commit | 99cfba8769cc84416c953693f7ccdf98c688423e (patch) | |
tree | 501d595cd5f6f448bcb71a38899fa2224c7a7a4a /moses/Incremental.cpp | |
parent | fad3ef687a2ed3c40c6da5e9909a9576cb5cb3a3 (diff) |
move OutputBest() to Incremental::Manager
Diffstat (limited to 'moses/Incremental.cpp')
-rw-r--r-- | moses/Incremental.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/moses/Incremental.cpp b/moses/Incremental.cpp index 51806656c..e54591fc6 100644 --- a/moses/Incremental.cpp +++ b/moses/Incremental.cpp @@ -283,6 +283,20 @@ const std::vector<search::Applied> &Manager::GetNBest() const return *completed_nbest_; } +void Manager::OutputBest(OutputCollector *collector) const +{ + const long translationId = m_source.GetTranslationId(); + const std::vector<search::Applied> &nbest = GetNBest(); + if (!nbest.empty()) { + OutputBestHypo(collector, nbest[0], translationId); + } + else { + OutputBestNone(collector, translationId); + } + +} + + void Manager::OutputNBest(OutputCollector *collector) const { if (collector == NULL) { @@ -465,6 +479,38 @@ void Manager::OutputTreeFragmentsTranslationOptions(std::ostream &out, } } +void Manager::OutputBestHypo(OutputCollector *collector, search::Applied applied, long translationId) const +{ + if (collector == NULL) return; + std::ostringstream out; + FixPrecision(out); + if (StaticData::Instance().GetOutputHypoScore()) { + out << applied.GetScore() << ' '; + } + Phrase outPhrase; + Incremental::ToPhrase(applied, outPhrase); + // delete 1st & last + UTIL_THROW_IF2(outPhrase.GetSize() < 2, + "Output phrase should have contained at least 2 words (beginning and end-of-sentence)"); + outPhrase.RemoveWord(0); + outPhrase.RemoveWord(outPhrase.GetSize() - 1); + out << outPhrase.GetStringRep(StaticData::Instance().GetOutputFactorOrder()); + out << '\n'; + collector->Write(translationId, out.str()); + + VERBOSE(1,"BEST TRANSLATION: " << outPhrase << "[total=" << applied.GetScore() << "]" << std::endl); +} + +void Manager::OutputBestNone(OutputCollector *collector, long translationId) const +{ + if (collector == NULL) return; + if (StaticData::Instance().GetOutputHypoScore()) { + collector->Write(translationId, "0 \n"); + } else { + collector->Write(translationId, "\n"); + } +} + namespace { |