From f4befcf1258ecd418834ceab644b8154aca04cab Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 19 Mar 2014 12:59:55 +0000 Subject: [PATCH] probing pt source vocab --- contrib/other-builds/moses/.cproject | 13 ++++++----- .../TranslationModel/ProbingPT/ProbingPT.cpp | 22 +++++++++++++++---- moses/TranslationModel/ProbingPT/ProbingPT.h | 7 ++++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/contrib/other-builds/moses/.cproject b/contrib/other-builds/moses/.cproject index 8840f82bb..8a4410c16 100644 --- a/contrib/other-builds/moses/.cproject +++ b/contrib/other-builds/moses/.cproject @@ -11,12 +11,12 @@ - - + + @@ -79,8 +79,11 @@ + + + - + @@ -90,13 +93,13 @@ - - + + diff --git a/moses/TranslationModel/ProbingPT/ProbingPT.cpp b/moses/TranslationModel/ProbingPT/ProbingPT.cpp index e6ba3498a..5174e99ff 100644 --- a/moses/TranslationModel/ProbingPT/ProbingPT.cpp +++ b/moses/TranslationModel/ProbingPT/ProbingPT.cpp @@ -32,7 +32,21 @@ void ProbingPT::Load() m_unkId = 456456546456; - // vocab + // source vocab + const std::map &sourceVocab = m_engine->getSourceVocab(); + std::map::const_iterator iter; + for (iter = sourceVocab.begin(); iter != sourceVocab.end(); ++iter) { + const string &wordStr = iter->second; + const Factor *factor = FactorCollection::Instance().AddFactor(wordStr); + + uint64_t probingId = iter->first; + + SourceVocabMap::value_type entry(factor, probingId); + m_sourceVocabMap.insert(entry); + + } + + // target vocab const std::map &probingVocab = m_engine->getVocab(); std::map::const_iterator iter; for (iter = probingVocab.begin(); iter != probingVocab.end(); ++iter) { @@ -41,7 +55,7 @@ void ProbingPT::Load() unsigned int probingId = iter->first; - VocabMap::value_type entry(factor, probingId); + TargetVocabMap::value_type entry(factor, probingId); m_vocabMap.insert(entry); } @@ -173,7 +187,7 @@ TargetPhrase *ProbingPT::CreateTargetPhrase(const Phrase &sourcePhrase, const ta const Factor *ProbingPT::GetFactor(uint64_t probingId) const { - VocabMap::right_map::const_iterator iter; + TargetVocabMap::right_map::const_iterator iter; iter = m_vocabMap.right.find(probingId); if (iter != m_vocabMap.right.end()) { return iter->second; @@ -186,7 +200,7 @@ const Factor *ProbingPT::GetFactor(uint64_t probingId) const uint64_t ProbingPT::GetProbingId(const Factor *factor) const { - VocabMap::left_map::const_iterator iter; + TargetVocabMap::left_map::const_iterator iter; iter = m_vocabMap.left.find(factor); if (iter != m_vocabMap.left.end()) { return iter->second; diff --git a/moses/TranslationModel/ProbingPT/ProbingPT.h b/moses/TranslationModel/ProbingPT/ProbingPT.h index b1f7ff7de..1746f236c 100644 --- a/moses/TranslationModel/ProbingPT/ProbingPT.h +++ b/moses/TranslationModel/ProbingPT/ProbingPT.h @@ -37,8 +37,11 @@ public: protected: QueryEngine *m_engine; - typedef boost::bimap VocabMap; - mutable VocabMap m_vocabMap; + typedef boost::bimap SourceVocabMap; + mutable SourceVocabMap m_sourceVocabMap; + + typedef boost::bimap TargetVocabMap; + mutable TargetVocabMap m_vocabMap; TargetPhraseCollection *CreateTargetPhrase(const Phrase &sourcePhrase) const; TargetPhrase *CreateTargetPhrase(const Phrase &sourcePhrase, const target_text &probingTargetPhrase) const;