diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-10 15:47:23 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-10 15:47:23 +0300 |
commit | 81640945d09b22ff297673c9c685cab9f344b266 (patch) | |
tree | 4359333fa4fdbf9a28d7519517fa9220c6c72d79 /moses/ChartManager.cpp | |
parent | 99cfba8769cc84416c953693f7ccdf98c688423e (diff) |
move OutputBest() to ChartManager
Diffstat (limited to 'moses/ChartManager.cpp')
-rw-r--r-- | moses/ChartManager.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/moses/ChartManager.cpp b/moses/ChartManager.cpp index 568920b27..55707b530 100644 --- a/moses/ChartManager.cpp +++ b/moses/ChartManager.cpp @@ -300,6 +300,16 @@ void ChartManager::OutputSearchGraphMoses(std::ostream &outputSearchGraphStream) WriteSearchGraph(writer); } +void ChartManager::OutputBest(OutputCollector *collector) const +{ + const ChartHypothesis *bestHypo = GetBestHypothesis(); + if (collector && bestHypo) { + const size_t translationId = m_source.GetTranslationId(); + const ChartHypothesis *bestHypo = GetBestHypothesis(); + OutputBestHypo(collector, bestHypo, translationId); + } +} + void ChartManager::OutputNBest(OutputCollector *collector) const { const StaticData &staticData = StaticData::Instance(); @@ -807,4 +817,61 @@ void ChartManager::OutputSearchGraphHypergraph() const } } +void ChartManager::OutputBestHypo(OutputCollector *collector, const ChartHypothesis *hypo, long translationId) const +{ + if (!collector) + return; + std::ostringstream out; + FixPrecision(out); + if (hypo != NULL) { + VERBOSE(1,"BEST TRANSLATION: " << *hypo << endl); + VERBOSE(3,"Best path: "); + Backtrack(hypo); + VERBOSE(3,"0" << std::endl); + + if (StaticData::Instance().GetOutputHypoScore()) { + out << hypo->GetTotalScore() << " "; + } + + if (StaticData::Instance().IsPathRecoveryEnabled()) { + out << "||| "; + } + Phrase outPhrase(ARRAY_SIZE_INCR); + hypo->GetOutputPhrase(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); + + const std::vector<FactorType> outputFactorOrder = StaticData::Instance().GetOutputFactorOrder(); + string output = outPhrase.GetStringRep(outputFactorOrder); + out << output << endl; + } else { + VERBOSE(1, "NO BEST TRANSLATION" << endl); + + if (StaticData::Instance().GetOutputHypoScore()) { + out << "0 "; + } + + out << endl; + } + collector->Write(translationId, out.str()); +} + +void ChartManager::Backtrack(const ChartHypothesis *hypo) const +{ + const vector<const ChartHypothesis*> &prevHypos = hypo->GetPrevHypos(); + + vector<const ChartHypothesis*>::const_iterator iter; + for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { + const ChartHypothesis *prevHypo = *iter; + + VERBOSE(3,prevHypo->GetId() << " <= "); + Backtrack(prevHypo); + } +} + } // namespace Moses |