diff options
author | heafield <heafield@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-10-06 14:31:09 +0400 |
---|---|---|
committer | heafield <heafield@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-10-06 14:31:09 +0400 |
commit | 9ba5460e53156bfc6e0ffb5779d829e53a926b61 (patch) | |
tree | 0c41b7d254682ae6d2474fe7b117aca43e689e2f /moses | |
parent | 6f22c2ae29a32fdd605e097f7d9cbb670bf69568 (diff) |
Apparently we wanted a sequential id after all. . . get one in a thread-safe way from the manager.
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@4302 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rw-r--r-- | moses/src/ChartCell.cpp | 2 | ||||
-rw-r--r-- | moses/src/ChartCell.h | 2 | ||||
-rw-r--r-- | moses/src/ChartHypothesis.cpp | 3 | ||||
-rw-r--r-- | moses/src/ChartHypothesis.h | 4 | ||||
-rw-r--r-- | moses/src/ChartHypothesisCollection.cpp | 14 | ||||
-rw-r--r-- | moses/src/ChartHypothesisCollection.h | 2 | ||||
-rw-r--r-- | moses/src/ChartManager.cpp | 5 | ||||
-rw-r--r-- | moses/src/ChartManager.h | 6 |
8 files changed, 22 insertions, 16 deletions
diff --git a/moses/src/ChartCell.cpp b/moses/src/ChartCell.cpp index cb5622b8a..ac5c47089 100644 --- a/moses/src/ChartCell.cpp +++ b/moses/src/ChartCell.cpp @@ -183,7 +183,7 @@ size_t ChartCell::GetSize() const return ret; } -void ChartCell::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<const ChartHypothesis *,bool> &reachable) const +void ChartCell::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<unsigned, bool> &reachable) const { std::map<Word, ChartHypothesisCollection>::const_iterator iterOutside; for (iterOutside = m_hypoColl.begin(); iterOutside != m_hypoColl.end(); ++iterOutside) { diff --git a/moses/src/ChartCell.h b/moses/src/ChartCell.h index d51399630..4ea148ff1 100644 --- a/moses/src/ChartCell.h +++ b/moses/src/ChartCell.h @@ -90,7 +90,7 @@ public: return m_coverage < compare.m_coverage; } - void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<const ChartHypothesis *,bool> &reachable) const; + void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<unsigned,bool> &reachable) const; }; diff --git a/moses/src/ChartHypothesis.cpp b/moses/src/ChartHypothesis.cpp index be27a4588..4b6f1fa03 100644 --- a/moses/src/ChartHypothesis.cpp +++ b/moses/src/ChartHypothesis.cpp @@ -51,8 +51,9 @@ ChartHypothesis::ChartHypothesis(const ChartTranslationOption &transOpt, ,m_currSourceWordsRange(transOpt.GetSourceWordsRange()) ,m_ffStates(manager.GetTranslationSystem()->GetStatefulFeatureFunctions().size()) ,m_arcList(NULL) - ,m_winningHypo(NULL) + ,m_winningHypo(NULL) ,m_manager(manager) + ,m_id(manager.GetNextHypoId()) { // underlying hypotheses for sub-spans m_numTargetTerminals = GetCurrTargetPhrase().GetNumTerminals(); diff --git a/moses/src/ChartHypothesis.h b/moses/src/ChartHypothesis.h index c3dfcb8e4..e88d76210 100644 --- a/moses/src/ChartHypothesis.h +++ b/moses/src/ChartHypothesis.h @@ -70,6 +70,8 @@ protected: ChartManager& m_manager; + unsigned m_id; /* pkoehn wants to log the order in which hypotheses were generated */ + size_t CalcPrefix(Phrase &ret, size_t size) const; size_t CalcSuffix(Phrase &ret, size_t size) const; @@ -97,7 +99,7 @@ public: ~ChartHypothesis(); - const ChartHypothesis *GetId() const { return this; } + unsigned GetId() const { return m_id; } const ChartTranslationOption &GetTranslationOption()const { return m_transOpt; diff --git a/moses/src/ChartHypothesisCollection.cpp b/moses/src/ChartHypothesisCollection.cpp index 835096493..531a60b20 100644 --- a/moses/src/ChartHypothesisCollection.cpp +++ b/moses/src/ChartHypothesisCollection.cpp @@ -254,24 +254,24 @@ void ChartHypothesisCollection::CleanupArcList() } } -void ChartHypothesisCollection::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<const ChartHypothesis *, bool> &reachable) const +void ChartHypothesisCollection::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<unsigned, bool> &reachable) const { HCType::const_iterator iter; for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) { ChartHypothesis &mainHypo = **iter; - if (StaticData::Instance().GetUnprunedSearchGraph() || + if (StaticData::Instance().GetUnprunedSearchGraph() || reachable.find(mainHypo.GetId()) != reachable.end()) { - outputSearchGraphStream << translationId << " " << mainHypo << endl; - } + outputSearchGraphStream << translationId << " " << mainHypo << endl; + } const ChartArcList *arcList = mainHypo.GetArcList(); if (arcList) { ChartArcList::const_iterator iterArc; for (iterArc = arcList->begin(); iterArc != arcList->end(); ++iterArc) { const ChartHypothesis &arc = **iterArc; - if (reachable.find(arc.GetId()) != reachable.end()) { - outputSearchGraphStream << translationId << " " << arc << endl; - } + if (reachable.find(arc.GetId()) != reachable.end()) { + outputSearchGraphStream << translationId << " " << arc << endl; + } } } } diff --git a/moses/src/ChartHypothesisCollection.h b/moses/src/ChartHypothesisCollection.h index 63839de1e..059686854 100644 --- a/moses/src/ChartHypothesisCollection.h +++ b/moses/src/ChartHypothesisCollection.h @@ -115,7 +115,7 @@ public: float GetBestScore() const { return m_bestScore; } - void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<const ChartHypothesis *,bool> &reachable) const; + void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream, const std::map<unsigned,bool> &reachable) const; }; diff --git a/moses/src/ChartManager.cpp b/moses/src/ChartManager.cpp index 2603fd1eb..a370858d7 100644 --- a/moses/src/ChartManager.cpp +++ b/moses/src/ChartManager.cpp @@ -42,6 +42,7 @@ ChartManager::ChartManager(InputType const& source, const TranslationSystem* sys ,m_transOptColl(source, system, m_hypoStackColl, m_ruleLookupManagers) ,m_system(system) ,m_start(clock()) + ,m_hypothesisId(0) { m_system->InitializeBeforeSentenceProcessing(source); const std::vector<PhraseDictionaryFeature*> &dictionaries = m_system->GetPhraseDictionaries(); @@ -200,7 +201,7 @@ void ChartManager::GetSearchGraph(long translationId, std::ostream &outputSearch size_t size = m_source.GetSize(); // which hypotheses are reachable? - std::map<const ChartHypothesis *,bool> reachable; + std::map<unsigned,bool> reachable; WordsRange fullRange(0, size-1); const ChartCell &lastCell = m_hypoStackColl.Get(fullRange); const ChartHypothesis *hypo = lastCell.GetBestHypothesis(); @@ -223,7 +224,7 @@ void ChartManager::GetSearchGraph(long translationId, std::ostream &outputSearch } } -void ChartManager::FindReachableHypotheses( const ChartHypothesis *hypo, std::map<const ChartHypothesis *,bool> &reachable ) const +void ChartManager::FindReachableHypotheses( const ChartHypothesis *hypo, std::map<unsigned,bool> &reachable ) const { // do not recurse, if already visited if (reachable.find(hypo->GetId()) != reachable.end()) diff --git a/moses/src/ChartManager.h b/moses/src/ChartManager.h index ccf1a0be4..6c380aa40 100644 --- a/moses/src/ChartManager.h +++ b/moses/src/ChartManager.h @@ -40,7 +40,7 @@ class ChartTrellisPathList; class ChartManager { -protected: +private: InputType const& m_source; /**< source sentence to be translated */ ChartCellCollection m_hypoStackColl; ChartTranslationOptionCollection m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */ @@ -48,6 +48,7 @@ protected: const TranslationSystem* m_system; clock_t m_start; /**< starting time, used for logging */ std::vector<ChartRuleLookupManager*> m_ruleLookupManagers; + unsigned m_hypothesisId; /* For handing out hypothesis ids to ChartHypothesis */ public: ChartManager(InputType const& source, const TranslationSystem* system); @@ -57,7 +58,7 @@ public: void CalcNBest(size_t count, ChartTrellisPathList &ret,bool onlyDistinct=0) const; void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const; - void FindReachableHypotheses( const ChartHypothesis *hypo, std::map<const ChartHypothesis *,bool> &reachable ) const; /* auxilliary function for GetSearchGraph */ + void FindReachableHypotheses( const ChartHypothesis *hypo, std::map<unsigned,bool> &reachable ) const; /* auxilliary function for GetSearchGraph */ const InputType& GetSource() const { return m_source; @@ -77,6 +78,7 @@ public: m_sentenceStats = std::auto_ptr<SentenceStats>(new SentenceStats(source)); } + unsigned GetNextHypoId() { return m_hypothesisId++; } }; } |