diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2016-10-03 15:41:12 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2016-10-03 15:43:41 +0300 |
commit | 8421a2618804b2257b3c8ac366400295e6c18c9d (patch) | |
tree | c5560ebc4774fe99604caa26989054426d3e6e05 | |
parent | b86cecf9d64c01a96f7a7b80fec7a6651d0d4725 (diff) |
return correct target phrases
5 files changed, 57 insertions, 13 deletions
diff --git a/contrib/moses2/TranslationModel/CompactPT/PhraseDecoder.cpp b/contrib/moses2/TranslationModel/CompactPT/PhraseDecoder.cpp index e08ebe372..7860fed94 100644 --- a/contrib/moses2/TranslationModel/CompactPT/PhraseDecoder.cpp +++ b/contrib/moses2/TranslationModel/CompactPT/PhraseDecoder.cpp @@ -224,10 +224,11 @@ TargetPhraseVectorPtr PhraseDecoder::CreateTargetPhraseCollection( // Retrieve source phrase identifier std::string sourcePhraseString = sourcePhrase.GetString(*m_input); size_t sourcePhraseId = m_phraseDictionary.m_hash[MakeSourceKey(sourcePhraseString)]; + /* cerr << "sourcePhraseString=" << sourcePhraseString << " " << sourcePhraseId << endl; - + */ if(sourcePhraseId != m_phraseDictionary.m_hash.GetSize()) { // Retrieve compressed and encoded target phrase collection std::string encodedPhraseCollection; diff --git a/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.cpp b/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.cpp index 88a86cd10..7e03924cd 100644 --- a/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.cpp +++ b/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.cpp @@ -91,8 +91,9 @@ void PhraseTableCompact::Lookup(const Manager &mgr, InputPathsBase &inputPaths) break; } InputPath *path = inputPathsCast.GetMatrix().GetValue(startPos, i); - cerr << "path=" << path->Debug(mgr.system) << endl; - Lookup(mgr, mgr.GetPool(), *path); + //cerr << "path=" << path->Debug(mgr.system) << endl; + TargetPhrases *tps = Lookup(mgr, mgr.GetPool(), *path); + path->AddTargetPhrases(*this, tps); } } } @@ -103,7 +104,7 @@ TargetPhrases *PhraseTableCompact::Lookup(const Manager &mgr, MemPool &pool, TargetPhrases *ret = NULL; const Phrase<Word> &sourcePhrase = inputPath.subPhrase; - cerr << "sourcePhrase=" << sourcePhrase.Debug(mgr.system) << endl; + //cerr << "sourcePhrase=" << sourcePhrase.Debug(mgr.system) << endl; // There is no souch source phrase if source phrase is longer than longest // observed source phrase during compilation @@ -113,23 +114,23 @@ TargetPhrases *PhraseTableCompact::Lookup(const Manager &mgr, MemPool &pool, // Retrieve target phrase collection from phrase table TargetPhraseVectorPtr decodedPhraseColl = m_phraseDecoder->CreateTargetPhraseCollection(mgr, sourcePhrase, true, true); - cerr << "decodedPhraseColl=" << decodedPhraseColl->size() << endl; - - return NULL; if(decodedPhraseColl != NULL && decodedPhraseColl->size()) { TargetPhraseVectorPtr tpv(new TargetPhraseVector(*decodedPhraseColl)); //TargetPhraseCollection::shared_ptr phraseColl(new TargetPhraseCollection); ret = new (pool.Allocate<TargetPhrases>()) TargetPhrases(pool, decodedPhraseColl->size()); - cerr << "ret=" << ret->GetSize() << endl; for (size_t i = 0; i < decodedPhraseColl->size(); ++i) { - //const TargetPhraseImpl *tp = decodedPhraseColl->at(i); - //cerr << "tp=" << tp << endl; - //ret->AddTargetPhrase(*tp); + const TPCompact &tpCompact = decodedPhraseColl->at(i); + const TargetPhraseImpl *tp = CreateTargetPhrase(mgr, tpCompact, sourcePhrase); + + ret->AddTargetPhrase(*tp); } + ret->SortAndPrune(m_tableLimit); + mgr.system.featureFunctions.EvaluateAfterTablePruning(pool, *ret, sourcePhrase); + //cerr << "RET2=" << ret->Debug(mgr.system) << endl; /* // Cache phrase pair for clean-up or retrieval with PREnc const_cast<PhraseDictionaryCompact*>(this)->CacheForCleanup(phraseColl); @@ -142,6 +143,40 @@ TargetPhrases *PhraseTableCompact::Lookup(const Manager &mgr, MemPool &pool, } +const TargetPhraseImpl *PhraseTableCompact::CreateTargetPhrase( + const Manager &mgr, + const TPCompact &tpCompact, + const Phrase<Word> &sourcePhrase) const +{ + MemPool &pool = mgr.GetPool(); + + size_t size = tpCompact.words.size(); + TargetPhraseImpl *ret = new TargetPhraseImpl(pool, *this, mgr.system, size); + + // words + for (size_t i = 0; i < size; ++i) { + const Word &compactWord = tpCompact.words[i]; + Word &tpWord = (*ret)[i]; + tpWord = compactWord; + } + + // scores + Scores &scores = ret->GetScores(); + scores.Assign(mgr.system, *this, tpCompact.scores); + + // align + ret->SetAlignTerm(tpCompact.alignment); + + // score + mgr.system.featureFunctions.EvaluateInIsolation(pool, mgr.system, sourcePhrase, *ret); + + // Cache phrase pair for clean-up or retrieval with PREnc + //const_cast<PhraseDictionaryCompact*>(this)->CacheForCleanup(phraseColl); + + //cerr << "ret=" << ret->Debug(mgr.system) << endl; + return ret; +} + // scfg void PhraseTableCompact::InitActiveChart( diff --git a/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.h b/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.h index 4d1352bb1..081ef2bd0 100644 --- a/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.h +++ b/contrib/moses2/TranslationModel/CompactPT/PhraseTableCompact.h @@ -5,6 +5,7 @@ namespace Moses2 { class PhraseDecoder; +class TPCompact; class PhraseTableCompact: public PhraseTable { @@ -45,6 +46,12 @@ protected: friend class PhraseDecoder; PhraseDecoder* m_phraseDecoder; + const TargetPhraseImpl *CreateTargetPhrase( + const Manager &mgr, + const TPCompact &tpCompact, + const Phrase<Word> &sourcePhrase) const; + + // SCFG virtual void LookupGivenNode( MemPool &pool, const SCFG::Manager &mgr, diff --git a/moses/TranslationModel/CompactPT/PhraseDecoder.cpp b/moses/TranslationModel/CompactPT/PhraseDecoder.cpp index 10ef5f99c..1a1927e2b 100644 --- a/moses/TranslationModel/CompactPT/PhraseDecoder.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDecoder.cpp @@ -219,10 +219,11 @@ TargetPhraseVectorPtr PhraseDecoder::CreateTargetPhraseCollection(const Phrase & // Retrieve source phrase identifier std::string sourcePhraseString = sourcePhrase.GetStringRep(*m_input); size_t sourcePhraseId = m_phraseDictionary.m_hash[MakeSourceKey(sourcePhraseString)]; + /* cerr << "sourcePhraseString=" << sourcePhraseString << " " << sourcePhraseId << endl; - + */ if(sourcePhraseId != m_phraseDictionary.m_hash.GetSize()) { // Retrieve compressed and encoded target phrase collection std::string encodedPhraseCollection; diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp index a7c41cddf..d93613b8f 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp @@ -101,7 +101,7 @@ TargetPhraseCollection::shared_ptr PhraseDictionaryCompact:: GetTargetPhraseCollectionNonCacheLEGACY(const Phrase &sourcePhrase) const { - cerr << "sourcePhrase=" << sourcePhrase << endl; + //cerr << "sourcePhrase=" << sourcePhrase << endl; TargetPhraseCollection::shared_ptr ret; // There is no souch source phrase if source phrase is longer than longest |