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
This commit is contained in:
heafield 2011-10-06 10:31:09 +00:00
parent 6f22c2ae29
commit 9ba5460e53
8 changed files with 22 additions and 16 deletions

View File

@ -183,7 +183,7 @@ size_t ChartCell::GetSize() const
return ret; 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; std::map<Word, ChartHypothesisCollection>::const_iterator iterOutside;
for (iterOutside = m_hypoColl.begin(); iterOutside != m_hypoColl.end(); ++iterOutside) { for (iterOutside = m_hypoColl.begin(); iterOutside != m_hypoColl.end(); ++iterOutside) {

View File

@ -90,7 +90,7 @@ public:
return m_coverage < compare.m_coverage; 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;
}; };

View File

@ -53,6 +53,7 @@ ChartHypothesis::ChartHypothesis(const ChartTranslationOption &transOpt,
,m_arcList(NULL) ,m_arcList(NULL)
,m_winningHypo(NULL) ,m_winningHypo(NULL)
,m_manager(manager) ,m_manager(manager)
,m_id(manager.GetNextHypoId())
{ {
// underlying hypotheses for sub-spans // underlying hypotheses for sub-spans
m_numTargetTerminals = GetCurrTargetPhrase().GetNumTerminals(); m_numTargetTerminals = GetCurrTargetPhrase().GetNumTerminals();

View File

@ -70,6 +70,8 @@ protected:
ChartManager& m_manager; 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 CalcPrefix(Phrase &ret, size_t size) const;
size_t CalcSuffix(Phrase &ret, size_t size) const; size_t CalcSuffix(Phrase &ret, size_t size) const;
@ -97,7 +99,7 @@ public:
~ChartHypothesis(); ~ChartHypothesis();
const ChartHypothesis *GetId() const { return this; } unsigned GetId() const { return m_id; }
const ChartTranslationOption &GetTranslationOption()const { const ChartTranslationOption &GetTranslationOption()const {
return m_transOpt; return m_transOpt;

View File

@ -254,7 +254,7 @@ 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; HCType::const_iterator iter;
for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) { for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) {

View File

@ -115,7 +115,7 @@ public:
float GetBestScore() const { return m_bestScore; } 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;
}; };

View File

@ -42,6 +42,7 @@ ChartManager::ChartManager(InputType const& source, const TranslationSystem* sys
,m_transOptColl(source, system, m_hypoStackColl, m_ruleLookupManagers) ,m_transOptColl(source, system, m_hypoStackColl, m_ruleLookupManagers)
,m_system(system) ,m_system(system)
,m_start(clock()) ,m_start(clock())
,m_hypothesisId(0)
{ {
m_system->InitializeBeforeSentenceProcessing(source); m_system->InitializeBeforeSentenceProcessing(source);
const std::vector<PhraseDictionaryFeature*> &dictionaries = m_system->GetPhraseDictionaries(); 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(); size_t size = m_source.GetSize();
// which hypotheses are reachable? // which hypotheses are reachable?
std::map<const ChartHypothesis *,bool> reachable; std::map<unsigned,bool> reachable;
WordsRange fullRange(0, size-1); WordsRange fullRange(0, size-1);
const ChartCell &lastCell = m_hypoStackColl.Get(fullRange); const ChartCell &lastCell = m_hypoStackColl.Get(fullRange);
const ChartHypothesis *hypo = lastCell.GetBestHypothesis(); 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 // do not recurse, if already visited
if (reachable.find(hypo->GetId()) != reachable.end()) if (reachable.find(hypo->GetId()) != reachable.end())

View File

@ -40,7 +40,7 @@ class ChartTrellisPathList;
class ChartManager class ChartManager
{ {
protected: private:
InputType const& m_source; /**< source sentence to be translated */ InputType const& m_source; /**< source sentence to be translated */
ChartCellCollection m_hypoStackColl; ChartCellCollection m_hypoStackColl;
ChartTranslationOptionCollection m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */ ChartTranslationOptionCollection m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */
@ -48,6 +48,7 @@ protected:
const TranslationSystem* m_system; const TranslationSystem* m_system;
clock_t m_start; /**< starting time, used for logging */ clock_t m_start; /**< starting time, used for logging */
std::vector<ChartRuleLookupManager*> m_ruleLookupManagers; std::vector<ChartRuleLookupManager*> m_ruleLookupManagers;
unsigned m_hypothesisId; /* For handing out hypothesis ids to ChartHypothesis */
public: public:
ChartManager(InputType const& source, const TranslationSystem* system); ChartManager(InputType const& source, const TranslationSystem* system);
@ -57,7 +58,7 @@ public:
void CalcNBest(size_t count, ChartTrellisPathList &ret,bool onlyDistinct=0) const; void CalcNBest(size_t count, ChartTrellisPathList &ret,bool onlyDistinct=0) const;
void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) 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 { const InputType& GetSource() const {
return m_source; return m_source;
@ -77,6 +78,7 @@ public:
m_sentenceStats = std::auto_ptr<SentenceStats>(new SentenceStats(source)); m_sentenceStats = std::auto_ptr<SentenceStats>(new SentenceStats(source));
} }
unsigned GetNextHypoId() { return m_hypothesisId++; }
}; };
} }