diff options
author | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-12-15 19:42:41 +0300 |
---|---|---|
committer | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-12-15 19:42:41 +0300 |
commit | 4e77665d30224653e4fa1a818e8100a6188fac2d (patch) | |
tree | 2412ccb40527226e03ff9503826a2c99f5189406 /moses/ChartManager.cpp | |
parent | e4eb201c52be74fee74399a6f35fcbe8eb85d834 (diff) | |
parent | dfd6cd2dd7fb2451b899c0ee84172d2e4e291f77 (diff) |
better handling of cache-based models with inconsistent parametersdynamic-models
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 44f3ab75f..ed0ad91c9 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 |