diff options
author | Phil Williams <philip.williams@mac.com> | 2014-12-30 19:52:18 +0300 |
---|---|---|
committer | Phil Williams <philip.williams@mac.com> | 2014-12-30 19:52:18 +0300 |
commit | b7650b2d8b8c819f57ff9c7fb956d2edecd19a97 (patch) | |
tree | 5987aba08e9f97e2a355eff308ec1e8dfedf2de4 | |
parent | c9d49f22a5016e8262cf6a780a07f5c6f50a344b (diff) |
Move OutputBest() from Syntax::S2T::Manager to Syntax::Manager
-rw-r--r-- | moses/Syntax/Manager.cpp | 29 | ||||
-rw-r--r-- | moses/Syntax/Manager.h | 8 | ||||
-rw-r--r-- | moses/Syntax/S2T/Manager-inl.h | 34 | ||||
-rw-r--r-- | moses/Syntax/S2T/Manager.h | 1 |
4 files changed, 34 insertions, 38 deletions
diff --git a/moses/Syntax/Manager.cpp b/moses/Syntax/Manager.cpp index 3e99b9c9d..5db9e66fb 100644 --- a/moses/Syntax/Manager.cpp +++ b/moses/Syntax/Manager.cpp @@ -17,6 +17,35 @@ Manager::Manager(const InputType &source) { } +void Manager::OutputBest(OutputCollector *collector) const +{ + if (!collector) { + return; + } + std::ostringstream out; + FixPrecision(out); + const SHyperedge *best = GetBestSHyperedge(); + if (best == NULL) { + VERBOSE(1, "NO BEST TRANSLATION" << std::endl); + if (StaticData::Instance().GetOutputHypoScore()) { + out << "0 "; + } + } else { + if (StaticData::Instance().GetOutputHypoScore()) { + out << best->score << " "; + } + Phrase yield = GetOneBestTargetYield(*best); + // delete 1st & last + UTIL_THROW_IF2(yield.GetSize() < 2, + "Output phrase should have contained at least 2 words (beginning and end-of-sentence)"); + yield.RemoveWord(0); + yield.RemoveWord(yield.GetSize()-1); + out << yield.GetStringRep(StaticData::Instance().GetOutputFactorOrder()); + out << '\n'; + } + collector->Write(m_source.GetTranslationId(), out.str()); +} + void Manager::OutputNBest(OutputCollector *collector) const { if (collector) { diff --git a/moses/Syntax/Manager.h b/moses/Syntax/Manager.h index 3216a9aa4..8868a0380 100644 --- a/moses/Syntax/Manager.h +++ b/moses/Syntax/Manager.h @@ -18,25 +18,27 @@ class Manager : public BaseManager // Virtual functions from Moses::BaseManager that are implemented the same // way for all Syntax managers. + void OutputBest(OutputCollector *collector) const; void OutputNBest(OutputCollector *collector) const; void OutputUnknowns(OutputCollector *collector) const; // Virtual functions from Moses::BaseManager that are no-ops for all Syntax // managers. - void OutputLatticeSamples(OutputCollector *collector) const {} void OutputAlignment(OutputCollector *collector) const {} void OutputDetailedTreeFragmentsTranslationReport( OutputCollector *collector) const {} - void OutputWordGraph(OutputCollector *collector) const {} + void OutputLatticeSamples(OutputCollector *collector) const {} void OutputSearchGraph(OutputCollector *collector) const {} - void OutputSearchGraphSLF() const {} void OutputSearchGraphHypergraph() const {} + void OutputSearchGraphSLF() const {} + void OutputWordGraph(OutputCollector *collector) const {} // Syntax-specific virtual functions that derived classes must implement. virtual void ExtractKBest( std::size_t k, std::vector<boost::shared_ptr<KBestExtractor::Derivation> > &kBestList, bool onlyDistinct=false) const = 0; + virtual const SHyperedge *GetBestSHyperedge() const = 0; protected: std::set<Word> m_oovs; diff --git a/moses/Syntax/S2T/Manager-inl.h b/moses/Syntax/S2T/Manager-inl.h index 46b2ab91c..4d0136fe1 100644 --- a/moses/Syntax/S2T/Manager-inl.h +++ b/moses/Syntax/S2T/Manager-inl.h @@ -389,40 +389,6 @@ void Manager<Parser>::RecombineAndSort(const std::vector<SHyperedge*> &buffer, } template<typename Parser> -void Manager<Parser>::OutputBest(OutputCollector *collector) const -{ - if (!collector) { - return; - } - - const Syntax::SHyperedge *best = GetBestSHyperedge(); - const long translationId = m_source.GetTranslationId(); - - std::ostringstream out; - FixPrecision(out); - if (best == NULL) { - VERBOSE(1, "NO BEST TRANSLATION" << std::endl); - if (StaticData::Instance().GetOutputHypoScore()) { - out << "0 "; - } - } else { - if (StaticData::Instance().GetOutputHypoScore()) { - out << best->score << " "; - } - Phrase yield = Syntax::GetOneBestTargetYield(*best); - // delete 1st & last - UTIL_THROW_IF2(yield.GetSize() < 2, - "Output phrase should have contained at least 2 words (beginning and end-of-sentence)"); - yield.RemoveWord(0); - yield.RemoveWord(yield.GetSize()-1); - out << yield.GetStringRep(StaticData::Instance().GetOutputFactorOrder()); - out << '\n'; - } - collector->Write(translationId, out.str()); - -} - -template<typename Parser> void Manager<Parser>::OutputDetailedTranslationReport( OutputCollector *collector) const { diff --git a/moses/Syntax/S2T/Manager.h b/moses/Syntax/S2T/Manager.h index 82eaf90e7..47cca43d6 100644 --- a/moses/Syntax/S2T/Manager.h +++ b/moses/Syntax/S2T/Manager.h @@ -42,7 +42,6 @@ class Manager : public Syntax::Manager std::vector<boost::shared_ptr<KBestExtractor::Derivation> > &kBestList, bool onlyDistinct=false) const; - void OutputBest(OutputCollector *collector) const; void OutputDetailedTranslationReport(OutputCollector *collector) const; private: |