diff options
author | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-03-26 19:37:04 +0300 |
---|---|---|
committer | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-03-26 19:37:04 +0300 |
commit | b3ff4ff13ac35293dcdb272f99b52388b560cb65 (patch) | |
tree | 1333c33a8a1ea4b8d4168ed17d8e20516fd2e737 /moses | |
parent | d364211d9088667ddb98136e0c9a29b913c31717 (diff) |
Managers have now access to the entire translation task.
Diffstat (limited to 'moses')
-rw-r--r-- | moses/BaseManager.cpp | 14 | ||||
-rw-r--r-- | moses/BaseManager.h | 18 | ||||
-rw-r--r-- | moses/Manager.cpp | 29 | ||||
-rw-r--r-- | moses/Manager.h | 8 | ||||
-rw-r--r-- | moses/Syntax/F2S/Manager-inl.h | 9 | ||||
-rw-r--r-- | moses/Syntax/F2S/Manager.h | 9 | ||||
-rw-r--r-- | moses/Syntax/Manager.cpp | 7 | ||||
-rw-r--r-- | moses/Syntax/Manager.h | 2 | ||||
-rw-r--r-- | moses/Syntax/S2T/Manager-inl.h | 12 | ||||
-rw-r--r-- | moses/Syntax/S2T/Manager.h | 2 | ||||
-rw-r--r-- | moses/Syntax/T2S/Manager-inl.h | 6 | ||||
-rw-r--r-- | moses/Syntax/T2S/Manager.h | 2 | ||||
-rw-r--r-- | moses/TypeDef.h | 11 |
13 files changed, 77 insertions, 52 deletions
diff --git a/moses/BaseManager.cpp b/moses/BaseManager.cpp index 2c57e8336..3d020da9c 100644 --- a/moses/BaseManager.cpp +++ b/moses/BaseManager.cpp @@ -4,11 +4,25 @@ #include "BaseManager.h" #include "moses/FF/StatelessFeatureFunction.h" #include "moses/FF/StatefulFeatureFunction.h" +#include "moses/TranslationTask.h" using namespace std; namespace Moses { + +BaseManager::BaseManager(ttasksptr const& ttask) + : m_ttask(ttask), m_source(*(ttask->GetSource().get())) +{ } + +const InputType& +BaseManager::GetSource() const +{ return m_source; } + + + + + /*** * print surface factor only for the given phrase */ diff --git a/moses/BaseManager.h b/moses/BaseManager.h index c0b6d22c1..d2a4ba6ef 100644 --- a/moses/BaseManager.h +++ b/moses/BaseManager.h @@ -1,3 +1,4 @@ +// -*- c++ -*- #pragma once #include <iostream> @@ -14,12 +15,12 @@ class OutputCollector; class BaseManager { protected: - const InputType &m_source; /**< source sentence to be translated */ - - BaseManager(const InputType &source) - :m_source(source) { - } + // const InputType &m_source; /**< source sentence to be translated */ + ttaskwptr m_ttask; + InputType const& m_source; + BaseManager(ttasksptr const& ttask); + // output typedef std::vector<std::pair<Moses::Word, Moses::WordsRange> > ApplicationContext; typedef std::set< std::pair<size_t, size_t> > Alignments; @@ -45,13 +46,10 @@ protected: } public: - virtual ~BaseManager() { - } + virtual ~BaseManager() { } //! the input sentence being decoded - const InputType& GetSource() const { - return m_source; - } + virtual const InputType& GetSource() const; virtual void Decode() = 0; // outputs diff --git a/moses/Manager.cpp b/moses/Manager.cpp index 0e8d5758a..fe8267626 100644 --- a/moses/Manager.cpp +++ b/moses/Manager.cpp @@ -59,28 +59,34 @@ using namespace std; namespace Moses { -Manager::Manager(InputType const& source) - :BaseManager(source) - ,m_transOptColl(source.CreateTranslationOptionCollection()) - ,interrupted_flag(0) - ,m_hypoId(0) + +Manager::Manager(ttasksptr const& ttask) + : BaseManager(ttask) + , interrupted_flag(0) + , m_hypoId(0) { + boost::shared_ptr<InputType> source = ttask->GetSource(); + m_transOptColl = source->CreateTranslationOptionCollection(); + const StaticData &staticData = StaticData::Instance(); SearchAlgorithm searchAlgorithm = staticData.GetSearchAlgorithm(); - m_search = Search::CreateSearch(*this, source, searchAlgorithm, *m_transOptColl); + m_search = Search::CreateSearch(*this, *source, searchAlgorithm, + *m_transOptColl); - StaticData::Instance().InitializeForInput(m_source); + StaticData::Instance().InitializeForInput(ttask); } Manager::~Manager() { delete m_transOptColl; delete m_search; - // this is a comment ... - - StaticData::Instance().CleanUpAfterSentenceProcessing(m_source); + StaticData::Instance().CleanUpAfterSentenceProcessing(m_ttask.lock()); } +const InputType& +Manager::GetSource() const +{ return m_source) ; } + /** * Main decoder loop that translates a sentence by expanding * hypotheses stack by stack, until the end of the sentence. @@ -121,7 +127,8 @@ void Manager::Decode() Timer searchTime; searchTime.start(); m_search->Decode(); - VERBOSE(1, "Line " << m_source.GetTranslationId() << ": Search took " << searchTime << " seconds" << endl); + VERBOSE(1, "Line " << m_source.GetTranslationId() + << ": Search took " << searchTime << " seconds" << endl); IFVERBOSE(2) { GetSentenceStats().StopTimeTotal(); TRACE_ERR(GetSentenceStats()); diff --git a/moses/Manager.h b/moses/Manager.h index 4de0f5f95..c611ef9dd 100644 --- a/moses/Manager.h +++ b/moses/Manager.h @@ -151,7 +151,8 @@ protected: void OutputAlignment(std::ostringstream &out, const TrellisPath &path) const; public: - Manager(InputType const& source); + // Manager(InputType const& source); + Manager(ttasksptr const& ttask); ~Manager(); const TranslationOptionCollection* getSntTranslationOptions(); @@ -180,9 +181,8 @@ public: void OutputSearchGraphAsSLF(long translationId, std::ostream &outputSearchGraphStream) const; void OutputSearchGraphAsHypergraph(std::ostream &outputSearchGraphStream) const; void GetSearchGraph(std::vector<SearchGraphNode>& searchGraph) const; - const InputType& GetSource() const { - return m_source; - } + + virtual const InputType& GetSource() const; /*** * to be called after processing a sentence (which may consist of more than just calling ProcessSentence() ) diff --git a/moses/Syntax/F2S/Manager-inl.h b/moses/Syntax/F2S/Manager-inl.h index a422e8085..6c289440c 100644 --- a/moses/Syntax/F2S/Manager-inl.h +++ b/moses/Syntax/F2S/Manager-inl.h @@ -1,3 +1,4 @@ +// -*- c++ -*- #pragma once #include "moses/DecodeGraph.h" @@ -32,13 +33,13 @@ namespace F2S { template<typename RuleMatcher> -Manager<RuleMatcher>::Manager(const InputType &source) - : Syntax::Manager(source) +Manager<RuleMatcher>::Manager(ttasksptr const& ttask) + : Syntax::Manager(ttask) { - if (const ForestInput *p = dynamic_cast<const ForestInput*>(&source)) { + if (const ForestInput *p = dynamic_cast<const ForestInput*>(&m_source)) { m_forest = p->GetForest(); m_rootVertex = p->GetRootVertex(); - } else if (const TreeInput *p = dynamic_cast<const TreeInput*>(&source)) { + } else if (const TreeInput *p = dynamic_cast<const TreeInput*>(&m_source)) { T2S::InputTreeBuilder builder; T2S::InputTree tmpTree; builder.Build(*p, "Q", tmpTree); diff --git a/moses/Syntax/F2S/Manager.h b/moses/Syntax/F2S/Manager.h index 3c7ff8da1..53f4cff13 100644 --- a/moses/Syntax/F2S/Manager.h +++ b/moses/Syntax/F2S/Manager.h @@ -30,17 +30,16 @@ template<typename RuleMatcher> class Manager : public Syntax::Manager { public: - Manager(const InputType &); + Manager(ttasksptr const& ttask); void Decode(); // Get the SHyperedge for the 1-best derivation. const SHyperedge *GetBestSHyperedge() const; - void ExtractKBest( - std::size_t k, - std::vector<boost::shared_ptr<KBestExtractor::Derivation> > &kBestList, - bool onlyDistinct=false) const; + typedef std::vector<boost::shared_ptr<KBestExtractor::Derivation> > kBestList_t; + void ExtractKBest(std::size_t k, kBestList_t& kBestList, + bool onlyDistinct=false) const; void OutputDetailedTranslationReport(OutputCollector *collector) const; diff --git a/moses/Syntax/Manager.cpp b/moses/Syntax/Manager.cpp index a11a0042f..f84890927 100644 --- a/moses/Syntax/Manager.cpp +++ b/moses/Syntax/Manager.cpp @@ -12,10 +12,9 @@ namespace Moses namespace Syntax { -Manager::Manager(const InputType &source) - : Moses::BaseManager(source) -{ -} +Manager::Manager(ttasksptr const& ttask) + : Moses::BaseManager(ttask) +{ } void Manager::OutputBest(OutputCollector *collector) const { diff --git a/moses/Syntax/Manager.h b/moses/Syntax/Manager.h index 8d814f604..ed36c7c1d 100644 --- a/moses/Syntax/Manager.h +++ b/moses/Syntax/Manager.h @@ -14,7 +14,7 @@ namespace Syntax class Manager : public BaseManager { public: - Manager(const InputType &); + Manager(ttasksptr const& ttask); // Virtual functions from Moses::BaseManager that are implemented the same // way for all Syntax managers. diff --git a/moses/Syntax/S2T/Manager-inl.h b/moses/Syntax/S2T/Manager-inl.h index 15594d589..ef08752b6 100644 --- a/moses/Syntax/S2T/Manager-inl.h +++ b/moses/Syntax/S2T/Manager-inl.h @@ -1,3 +1,4 @@ +// -*- c++ -*- #pragma once #include <iostream> @@ -30,12 +31,11 @@ namespace S2T { template<typename Parser> -Manager<Parser>::Manager(const InputType &source) - : Syntax::Manager(source) - , m_pchart(source.GetSize(), Parser::RequiresCompressedChart()) - , m_schart(source.GetSize()) -{ -} +Manager<Parser>::Manager(ttasksptr const& ttask) + : Syntax::Manager(ttask) + , m_pchart(m_source.GetSize(), Parser::RequiresCompressedChart()) + , m_schart(m_source.GetSize()) +{ } template<typename Parser> void Manager<Parser>::InitializeCharts() diff --git a/moses/Syntax/S2T/Manager.h b/moses/Syntax/S2T/Manager.h index 0961c8e77..711d6f9d8 100644 --- a/moses/Syntax/S2T/Manager.h +++ b/moses/Syntax/S2T/Manager.h @@ -30,7 +30,7 @@ template<typename Parser> class Manager : public Syntax::Manager { public: - Manager(const InputType &); + Manager(ttasksptr const& ttask); void Decode(); diff --git a/moses/Syntax/T2S/Manager-inl.h b/moses/Syntax/T2S/Manager-inl.h index c0df884e1..90ecb35bf 100644 --- a/moses/Syntax/T2S/Manager-inl.h +++ b/moses/Syntax/T2S/Manager-inl.h @@ -27,10 +27,10 @@ namespace T2S { template<typename RuleMatcher> -Manager<RuleMatcher>::Manager(const InputType &source) - : Syntax::Manager(source) +Manager<RuleMatcher>::Manager(ttasksptr const& ttask) + : Syntax::Manager(ttask) { - if (const TreeInput *p = dynamic_cast<const TreeInput*>(&source)) { + if (const TreeInput *p = dynamic_cast<const TreeInput*>(&m_source)) { // Construct the InputTree. InputTreeBuilder builder; builder.Build(*p, "Q", m_inputTree); diff --git a/moses/Syntax/T2S/Manager.h b/moses/Syntax/T2S/Manager.h index c8421477c..b2036aba0 100644 --- a/moses/Syntax/T2S/Manager.h +++ b/moses/Syntax/T2S/Manager.h @@ -30,7 +30,7 @@ template<typename RuleMatcher> class Manager : public Syntax::Manager { public: - Manager(const InputType &); + Manager(ttasksptr const& ttask); void Decode(); diff --git a/moses/TypeDef.h b/moses/TypeDef.h index a47a6e2fe..66536909f 100644 --- a/moses/TypeDef.h +++ b/moses/TypeDef.h @@ -25,6 +25,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <string> #include <stdint.h> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + //! all the typedefs and enums goes here @@ -136,9 +139,9 @@ enum DictionaryFind { // model is phrase-based or syntax-based. If you add a syntax-based search // algorithm here then you should also update StaticData::IsSyntax(). enum SearchAlgorithm { - Normal = 0 + Normal = 0 ,CubePruning = 1 - //,CubeGrowing = 2 + //,CubeGrowing = 2 ,CYKPlus = 3 ,NormalBatch = 4 ,ChartIncremental = 5 @@ -146,6 +149,7 @@ enum SearchAlgorithm { ,SyntaxT2S = 7 ,SyntaxT2S_SCFG = 8 ,SyntaxF2S = 9 + ,DefaultSearchAlgorithm = 777 // means: use StaticData.m_searchAlgorithm }; enum SourceLabelOverlap { @@ -179,5 +183,8 @@ typedef std::vector<FactorType> FactorList; typedef std::pair<std::vector<std::string const*>,WordAlignments > StringWordAlignmentCand; +class TranslationTask; +typedef boost::shared_ptr<TranslationTask> ttasksptr; +typedef boost::weak_ptr<TranslationTask> ttaskwptr; } |