diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-02 22:09:10 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-02 22:09:10 +0300 |
commit | 3da84150959de4dc99edf3ee35665e81a23aae26 (patch) | |
tree | ee7c487a26f2d56f56763dd5fe8885f6d6130465 /moses/Incremental.cpp | |
parent | ba7afba9f6f325441387557ab8af487d5901f023 (diff) |
add OutputNBest() as abstract method to BaseManager. Tighten up framework
Diffstat (limited to 'moses/Incremental.cpp')
-rw-r--r-- | moses/Incremental.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/moses/Incremental.cpp b/moses/Incremental.cpp index 06c46b786..d366065a5 100644 --- a/moses/Incremental.cpp +++ b/moses/Incremental.cpp @@ -8,6 +8,7 @@ #include "moses/StaticData.h" #include "moses/Util.h" #include "moses/LM/Base.h" +#include "moses/OutputCollector.h" #include "lm/model.hh" #include "search/applied.hh" @@ -278,6 +279,47 @@ const std::vector<search::Applied> &Manager::ProcessSentence() return *completed_nbest_; } +void Manager::OutputNBest(OutputCollector *collector) const +{ + if (collector == NULL) { + return; + } + + OutputNBestList(collector, *completed_nbest_, source_.GetTranslationId()); +} + +void Manager::OutputNBestList(OutputCollector *collector, const std::vector<search::Applied> &nbest, long translationId) const +{ + const StaticData &staticData = StaticData::Instance(); + const std::vector<Moses::FactorType> &outputFactorOrder = staticData.GetOutputFactorOrder(); + + std::ostringstream out; + // wtf? copied from the original OutputNBestList + if (collector->OutputIsCout()) { + FixPrecision(out); + } + Phrase outputPhrase; + ScoreComponentCollection features; + for (std::vector<search::Applied>::const_iterator i = nbest.begin(); i != nbest.end(); ++i) { + Incremental::PhraseAndFeatures(*i, outputPhrase, features); + // <s> and </s> + UTIL_THROW_IF2(outputPhrase.GetSize() < 2, + "Output phrase should have contained at least 2 words (beginning and end-of-sentence)"); + + outputPhrase.RemoveWord(0); + outputPhrase.RemoveWord(outputPhrase.GetSize() - 1); + out << translationId << " ||| "; + OutputSurface(out, outputPhrase, outputFactorOrder, false); + out << " ||| "; + OutputAllFeatureScores(features, out); + out << " ||| " << i->GetScore() << '\n'; + } + out << std::flush; + assert(collector); + collector->Write(translationId, out.str()); +} + + namespace { |