diff options
author | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-03-26 21:25:54 +0300 |
---|---|---|
committer | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-03-26 21:25:54 +0300 |
commit | 9dc75bfd8ad3092f08f7a6d2a6492323b7803e56 (patch) | |
tree | f13405e11bce5001e6718ae0089fdcf85d961c98 /moses/TranslationTask.cpp | |
parent | 4410e9225a5bd495fc6d097b206290beb59f4839 (diff) |
Managers and feature functions now have access to the entire TranslationTask, not just the InputType.
Diffstat (limited to 'moses/TranslationTask.cpp')
-rw-r--r-- | moses/TranslationTask.cpp | 111 |
1 files changed, 72 insertions, 39 deletions
diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index 2b0d47baa..9100cd3ed 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -25,6 +25,16 @@ namespace Moses boost::shared_ptr<TranslationTask> TranslationTask +::create(boost::shared_ptr<InputType> const& source) +{ + boost::shared_ptr<IOWrapper> nix; + boost::shared_ptr<TranslationTask> ret(new TranslationTask(source, nix)); + ret->m_self = ret; + return ret; +} + +boost::shared_ptr<TranslationTask> +TranslationTask ::create(boost::shared_ptr<InputType> const& source, boost::shared_ptr<IOWrapper> const& ioWrapper) { @@ -42,6 +52,59 @@ TranslationTask TranslationTask::~TranslationTask() { } + +boost::shared_ptr<BaseManager> +TranslationTask +::SetupManager(SearchAlgorithm algo) +{ + boost::shared_ptr<BaseManager> manager; + StaticData const& staticData = StaticData::Instance(); + if (algo == DefaultSearchAlgorithm) algo = staticData.GetSearchAlgorithm(); + + if (!staticData.IsSyntax(algo)) + manager.reset(new Manager(this->self())); // phrase-based + + else if (algo == SyntaxF2S || algo == SyntaxT2S) + { // STSG-based tree-to-string / forest-to-string decoding (ask Phil Williams) + typedef Syntax::F2S::RuleMatcherCallback Callback; + typedef Syntax::F2S::RuleMatcherHyperTree<Callback> RuleMatcher; + manager.reset(new Syntax::F2S::Manager<RuleMatcher>(this->self())); + } + + else if (algo == SyntaxS2T) + { // new-style string-to-tree decoding (ask Phil Williams) + S2TParsingAlgorithm algorithm = staticData.GetS2TParsingAlgorithm(); + if (algorithm == RecursiveCYKPlus) + { + typedef Syntax::S2T::EagerParserCallback Callback; + typedef Syntax::S2T::RecursiveCYKPlusParser<Callback> Parser; + manager.reset(new Syntax::S2T::Manager<Parser>(this->self())); + } + else if (algorithm == Scope3) + { + typedef Syntax::S2T::StandardParserCallback Callback; + typedef Syntax::S2T::Scope3Parser<Callback> Parser; + manager.reset(new Syntax::S2T::Manager<Parser>(this->self())); + } + else UTIL_THROW2("ERROR: unhandled S2T parsing algorithm"); + } + + else if (algo == SyntaxT2S_SCFG) + { // SCFG-based tree-to-string decoding (ask Phil Williams) + typedef Syntax::F2S::RuleMatcherCallback Callback; + typedef Syntax::T2S::RuleMatcherSCFG<Callback> RuleMatcher; + manager.reset(new Syntax::T2S::Manager<RuleMatcher>(this->self())); + } + + else if (algo == ChartIncremental) // Ken's incremental decoding + manager.reset(new Incremental::Manager(this->self())); + + else // original SCFG manager + manager.reset(new ChartManager(this->self())); + + return manager; +} + void TranslationTask::Run() { UTIL_THROW_IF2(!m_source || !m_ioWrapper, @@ -69,52 +132,22 @@ void TranslationTask::Run() Timer initTime; initTime.start(); - // which manager - boost::scoped_ptr<BaseManager> manager; - - if (!staticData.IsSyntax()) { - // phrase-based - manager.reset(new Manager(*m_source)); - } else if (staticData.GetSearchAlgorithm() == SyntaxF2S || - staticData.GetSearchAlgorithm() == SyntaxT2S) { - // STSG-based tree-to-string / forest-to-string decoding (ask Phil Williams) - typedef Syntax::F2S::RuleMatcherCallback Callback; - typedef Syntax::F2S::RuleMatcherHyperTree<Callback> RuleMatcher; - manager.reset(new Syntax::F2S::Manager<RuleMatcher>(*m_source)); - } else if (staticData.GetSearchAlgorithm() == SyntaxS2T) { - // new-style string-to-tree decoding (ask Phil Williams) - S2TParsingAlgorithm algorithm = staticData.GetS2TParsingAlgorithm(); - if (algorithm == RecursiveCYKPlus) { - typedef Syntax::S2T::EagerParserCallback Callback; - typedef Syntax::S2T::RecursiveCYKPlusParser<Callback> Parser; - manager.reset(new Syntax::S2T::Manager<Parser>(*m_source)); - } else if (algorithm == Scope3) { - typedef Syntax::S2T::StandardParserCallback Callback; - typedef Syntax::S2T::Scope3Parser<Callback> Parser; - manager.reset(new Syntax::S2T::Manager<Parser>(*m_source)); - } else { - UTIL_THROW2("ERROR: unhandled S2T parsing algorithm"); - } - } else if (staticData.GetSearchAlgorithm() == SyntaxT2S_SCFG) { - // SCFG-based tree-to-string decoding (ask Phil Williams) - typedef Syntax::F2S::RuleMatcherCallback Callback; - typedef Syntax::T2S::RuleMatcherSCFG<Callback> RuleMatcher; - manager.reset(new Syntax::T2S::Manager<RuleMatcher>(*m_source)); - } else if (staticData.GetSearchAlgorithm() == ChartIncremental) { - // Ken's incremental decoding - manager.reset(new Incremental::Manager(*m_source)); - } else { - // original SCFG manager - manager.reset(new ChartManager(*m_source)); - } + boost::shared_ptr<BaseManager> manager = SetupManager(); VERBOSE(1, "Line " << translationId << ": Initialize search took " << initTime << " seconds total" << endl); manager->Decode(); - OutputCollector* ocoll; + // new: stop here if m_ioWrapper is NULL. This means that the + // owner of the TranslationTask will take care of the output + // oh, and by the way, all the output should be handled by the + // output wrapper along the lines of *m_iwWrapper << *manager; + // Just sayin' ... + if (m_ioWrapper == NULL) return; + // we are done with search, let's look what we got + OutputCollector* ocoll; Timer additionalReportingTime; additionalReportingTime.start(); |