mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
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:
parent
6f22c2ae29
commit
9ba5460e53
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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())
|
||||||
|
@ -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++; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user