From 0613d98beb414753ce9701ab33e6e46a35e118e5 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 23 Aug 2013 13:38:31 +0100 Subject: [PATCH 1/9] delete PhraseBasedFeatureContext --- moses/FF/GlobalLexicalModel.cpp | 2 +- moses/FF/PhraseBasedFeatureContext.cpp | 19 ------------------- moses/FF/PhraseBasedFeatureContext.h | 11 ++--------- moses/FF/PhrasePairFeature.cpp | 8 ++++---- moses/FF/WordTranslationFeature.cpp | 8 ++++---- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/moses/FF/GlobalLexicalModel.cpp b/moses/FF/GlobalLexicalModel.cpp index 609a02980..0f952b810 100644 --- a/moses/FF/GlobalLexicalModel.cpp +++ b/moses/FF/GlobalLexicalModel.cpp @@ -171,7 +171,7 @@ void GlobalLexicalModel::Evaluate ScoreComponentCollection* accumulator) const { accumulator->PlusEquals( this, - GetFromCacheOrScorePhrase(context.GetTargetPhrase()) ); + GetFromCacheOrScorePhrase(context.GetHypothesis().GetCurrTargetPhrase()) ); } bool GlobalLexicalModel::IsUseable(const FactorMask &mask) const diff --git a/moses/FF/PhraseBasedFeatureContext.cpp b/moses/FF/PhraseBasedFeatureContext.cpp index 4127a587c..9c8cc8ec8 100644 --- a/moses/FF/PhraseBasedFeatureContext.cpp +++ b/moses/FF/PhraseBasedFeatureContext.cpp @@ -10,24 +10,5 @@ PhraseBasedFeatureContext::PhraseBasedFeatureContext(const Hypothesis* hypothesi m_translationOption(m_hypothesis->GetTranslationOption()), m_source(m_hypothesis->GetManager().GetSource()) {} -PhraseBasedFeatureContext::PhraseBasedFeatureContext -(const TranslationOption& translationOption, const InputType& source) : - m_hypothesis(NULL), - m_translationOption(translationOption), - m_source(source) -{} - -const TargetPhrase& PhraseBasedFeatureContext::GetTargetPhrase() const -{ - return m_translationOption.GetTargetPhrase(); -} - -const WordsBitmap& PhraseBasedFeatureContext::GetWordsBitmap() const -{ - if (!m_hypothesis) { - throw std::logic_error("Coverage vector not available during pre-calculation"); - } - return m_hypothesis->GetWordsBitmap(); -} } diff --git a/moses/FF/PhraseBasedFeatureContext.h b/moses/FF/PhraseBasedFeatureContext.h index 0c41712ca..62eb629a7 100644 --- a/moses/FF/PhraseBasedFeatureContext.h +++ b/moses/FF/PhraseBasedFeatureContext.h @@ -25,17 +25,10 @@ class PhraseBasedFeatureContext public: PhraseBasedFeatureContext(const Hypothesis* hypothesis); - PhraseBasedFeatureContext(const TranslationOption& translationOption, - const InputType& source); - const TranslationOption& GetTranslationOption() const { - return m_translationOption; + const Hypothesis& GetHypothesis() const { + return *m_hypothesis; } - const InputType& GetSource() const { - return m_source; - } - const TargetPhrase& GetTargetPhrase() const; //convenience method - const WordsBitmap& GetWordsBitmap() const; }; diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp index 883a147ca..de566a3ce 100644 --- a/moses/FF/PhrasePairFeature.cpp +++ b/moses/FF/PhrasePairFeature.cpp @@ -109,8 +109,8 @@ void PhrasePairFeature::Evaluate( const PhraseBasedFeatureContext& context, ScoreComponentCollection* accumulator) const { - const TargetPhrase& target = context.GetTargetPhrase(); - const Phrase& source = context.GetTranslationOption().GetInputPath().GetPhrase(); + const TargetPhrase& target = context.GetHypothesis().GetCurrTargetPhrase(); + const Phrase& source = context.GetHypothesis().GetTranslationOption().GetInputPath().GetPhrase(); if (m_simple) { ostringstream namestr; namestr << "pp_"; @@ -131,7 +131,7 @@ void PhrasePairFeature::Evaluate( accumulator->SparsePlusEquals(namestr.str(),1); } if (m_domainTrigger) { - const Sentence& input = static_cast(context.GetSource()); + const Sentence& input = static_cast(context.GetHypothesis().GetInput()); const bool use_topicid = input.GetUseTopicId(); const bool use_topicid_prob = input.GetUseTopicIdAndProb(); @@ -199,7 +199,7 @@ void PhrasePairFeature::Evaluate( } } if (m_sourceContext) { - const Sentence& input = static_cast(context.GetSource()); + const Sentence& input = static_cast(context.GetHypothesis().GetInput()); // range over source words to get context for(size_t contextIndex = 0; contextIndex < input.GetSize(); contextIndex++ ) { diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp index bd8a711c1..82815fd07 100644 --- a/moses/FF/WordTranslationFeature.cpp +++ b/moses/FF/WordTranslationFeature.cpp @@ -140,9 +140,9 @@ void WordTranslationFeature::Evaluate (const PhraseBasedFeatureContext& context, ScoreComponentCollection* accumulator) const { - const Sentence& input = static_cast(context.GetSource()); - const TranslationOption& transOpt = context.GetTranslationOption(); - const TargetPhrase& targetPhrase = context.GetTargetPhrase(); + const Sentence& input = static_cast(context.GetHypothesis().GetInput()); + const TranslationOption& transOpt = context.GetHypothesis().GetTranslationOption(); + const TargetPhrase& targetPhrase = context.GetHypothesis().GetCurrTargetPhrase(); const AlignmentInfo &alignment = targetPhrase.GetAlignTerm(); // process aligned words @@ -243,7 +243,7 @@ void WordTranslationFeature::Evaluate } } if (m_sourceContext) { - size_t globalSourceIndex = context.GetTranslationOption().GetStartPos() + sourceIndex; + size_t globalSourceIndex = context.GetHypothesis().GetTranslationOption().GetStartPos() + sourceIndex; if (!m_domainTrigger && globalSourceIndex == 0) { // add trigger feature for source stringstream feature; From 4dfb625536e3b7deed1896d26c84c8f041288ba9 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 23 Aug 2013 13:53:30 +0100 Subject: [PATCH 2/9] beautify --- moses-cmd/IOWrapper.cpp | 9 +- moses/FeatureVector.h | 3 +- moses/ScoreComponentCollection.h | 3 +- moses/TargetPhrase.cpp | 3 +- moses/TranslationModel/PhraseDictionary.cpp | 16 +-- .../RuleTable/PhraseDictionaryOnDisk.cpp | 121 +++++++++--------- 6 files changed, 78 insertions(+), 77 deletions(-) diff --git a/moses-cmd/IOWrapper.cpp b/moses-cmd/IOWrapper.cpp index b1c50cff8..b04257e8b 100644 --- a/moses-cmd/IOWrapper.cpp +++ b/moses-cmd/IOWrapper.cpp @@ -217,12 +217,11 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector< //preface surface form with UNK if marking unknowns const Word &word = phrase.GetWord(pos); if(markUnknown && word.IsOOV()) { - out << "UNK" << *factor; + out << "UNK" << *factor; + } else { + out << *factor; } - else { - out << *factor; - } - + for (size_t i = 1 ; i < outputFactorOrder.size() ; i++) { const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[i]); CHECK(factor); diff --git a/moses/FeatureVector.h b/moses/FeatureVector.h index e95246a47..b677494e6 100644 --- a/moses/FeatureVector.h +++ b/moses/FeatureVector.h @@ -311,7 +311,8 @@ private: }; -inline void swap(FVector &first, FVector &second) { +inline void swap(FVector &first, FVector &second) +{ swap(first.m_features, second.m_features); swap(first.m_coreFeatures, second.m_coreFeatures); } diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index 4d12e4286..9f3ea49f4 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -417,7 +417,8 @@ struct SCCPlus { } }; -inline void swap(ScoreComponentCollection &first, ScoreComponentCollection &second) { +inline void swap(ScoreComponentCollection &first, ScoreComponentCollection &second) +{ swap(first.m_scores, second.m_scores); } diff --git a/moses/TargetPhrase.cpp b/moses/TargetPhrase.cpp index 507c88c3e..813471531 100644 --- a/moses/TargetPhrase.cpp +++ b/moses/TargetPhrase.cpp @@ -201,7 +201,8 @@ void TargetPhrase::Merge(const TargetPhrase ©, const std::vector m_fullScore += copy.m_fullScore; } -void swap(TargetPhrase &first, TargetPhrase &second) { +void swap(TargetPhrase &first, TargetPhrase &second) +{ first.SwapWords(second); std::swap(first.m_fullScore, second.m_fullScore); std::swap(first.m_futureScore, second.m_futureScore); diff --git a/moses/TranslationModel/PhraseDictionary.cpp b/moses/TranslationModel/PhraseDictionary.cpp index e0589e22a..c2d0c616b 100644 --- a/moses/TranslationModel/PhraseDictionary.cpp +++ b/moses/TranslationModel/PhraseDictionary.cpp @@ -62,13 +62,13 @@ const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollection(const cache[hash] = value; } else { // in cache. just use it - std::pair &value = iter->second; - value.second = clock(); + std::pair &value = iter->second; + value.second = clock(); - ret = value.first; + ret = value.first; } } else { - // don't use cache. look up from phrase table + // don't use cache. look up from phrase table ret = GetTargetPhraseCollectionNonCache(src); } @@ -92,7 +92,7 @@ GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const& range) co void PhraseDictionary::SetParameter(const std::string& key, const std::string& value) { if (key == "cache-size") { - m_maxCacheSize = Scan(value); + m_maxCacheSize = Scan(value); } else if (key == "path") { m_filePath = value; } else if (key == "table-limit") { @@ -128,7 +128,7 @@ void PhraseDictionary::GetTargetPhraseCollectionBatch(const InputPathList &phras void PhraseDictionary::ReduceCache() const { - CacheColl &cache = GetCache(); + CacheColl &cache = GetCache(); if (cache.size() <= m_maxCacheSize) return; // not full // find cutoff for last used time @@ -161,8 +161,8 @@ PhraseDictionary::CacheColl &PhraseDictionary::GetCache() const CacheColl *cache; cache = m_cache.get(); if (cache == NULL) { - cache = new CacheColl; - m_cache.reset(cache); + cache = new CacheColl; + m_cache.reset(cache); } CHECK(cache); return *cache; diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp index d7fc793a0..7e9f694bb 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp @@ -104,92 +104,91 @@ void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(const InputPathList void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(InputPath &inputPath) const { - OnDiskPt::OnDiskWrapper &wrapper = const_cast(GetImplementation()); - const Phrase &phrase = inputPath.GetPhrase(); - const InputPath *prevInputPath = inputPath.GetPrevNode(); + OnDiskPt::OnDiskWrapper &wrapper = const_cast(GetImplementation()); + const Phrase &phrase = inputPath.GetPhrase(); + const InputPath *prevInputPath = inputPath.GetPrevNode(); - const OnDiskPt::PhraseNode *prevPtNode = NULL; + const OnDiskPt::PhraseNode *prevPtNode = NULL; - if (prevInputPath) { - prevPtNode = static_cast(prevInputPath->GetPtNode(*this)); + if (prevInputPath) { + prevPtNode = static_cast(prevInputPath->GetPtNode(*this)); + } else { + // Starting subphrase. + assert(phrase.GetSize() == 1); + prevPtNode = &wrapper.GetRootSourceNode(); + } + + if (prevPtNode) { + Word lastWord = phrase.GetWord(phrase.GetSize() - 1); + lastWord.OnlyTheseFactors(m_inputFactors); + OnDiskPt::Word *lastWordOnDisk = wrapper.ConvertFromMoses(m_input, lastWord); + + if (lastWordOnDisk == NULL) { + // OOV according to this phrase table. Not possible to extend + inputPath.SetTargetPhrases(*this, NULL, NULL); } else { - // Starting subphrase. - assert(phrase.GetSize() == 1); - prevPtNode = &wrapper.GetRootSourceNode(); - } - - if (prevPtNode) { - Word lastWord = phrase.GetWord(phrase.GetSize() - 1); - lastWord.OnlyTheseFactors(m_inputFactors); - OnDiskPt::Word *lastWordOnDisk = wrapper.ConvertFromMoses(m_input, lastWord); - - if (lastWordOnDisk == NULL) { - // OOV according to this phrase table. Not possible to extend - inputPath.SetTargetPhrases(*this, NULL, NULL); + const OnDiskPt::PhraseNode *ptNode = prevPtNode->GetChild(*lastWordOnDisk, wrapper); + if (ptNode) { + const TargetPhraseCollection *targetPhrases = GetTargetPhraseCollection(ptNode); + inputPath.SetTargetPhrases(*this, targetPhrases, ptNode); } else { - const OnDiskPt::PhraseNode *ptNode = prevPtNode->GetChild(*lastWordOnDisk, wrapper); - if (ptNode) { - const TargetPhraseCollection *targetPhrases = GetTargetPhraseCollection(ptNode); - inputPath.SetTargetPhrases(*this, targetPhrases, ptNode); - } else { - inputPath.SetTargetPhrases(*this, NULL, NULL); - } - - delete lastWordOnDisk; + inputPath.SetTargetPhrases(*this, NULL, NULL); } + + delete lastWordOnDisk; } + } } const TargetPhraseCollection *PhraseDictionaryOnDisk::GetTargetPhraseCollection(const OnDiskPt::PhraseNode *ptNode) const { - const TargetPhraseCollection *ret; + const TargetPhraseCollection *ret; - if (m_maxCacheSize) { - CacheColl &cache = GetCache(); - size_t hash = (size_t) ptNode->GetFilePos(); + if (m_maxCacheSize) { + CacheColl &cache = GetCache(); + size_t hash = (size_t) ptNode->GetFilePos(); - std::map >::iterator iter; + std::map >::iterator iter; - iter = cache.find(hash); + iter = cache.find(hash); - if (iter == cache.end()) { - // not in cache, need to look up from phrase table - ret = GetTargetPhraseCollectionNonCache(ptNode); - if (ret) { - ret = new TargetPhraseCollection(*ret); - } + if (iter == cache.end()) { + // not in cache, need to look up from phrase table + ret = GetTargetPhraseCollectionNonCache(ptNode); + if (ret) { + ret = new TargetPhraseCollection(*ret); + } - std::pair value(ret, clock()); - cache[hash] = value; - } - else { - // in cache. just use it - std::pair &value = iter->second; - value.second = clock(); + std::pair value(ret, clock()); + cache[hash] = value; + } else { + // in cache. just use it + std::pair &value = iter->second; + value.second = clock(); - ret = value.first; - } - } else { - ret = GetTargetPhraseCollectionNonCache(ptNode); - } + ret = value.first; + } + } else { + ret = GetTargetPhraseCollectionNonCache(ptNode); + } - return ret; + return ret; } const TargetPhraseCollection *PhraseDictionaryOnDisk::GetTargetPhraseCollectionNonCache(const OnDiskPt::PhraseNode *ptNode) const { - OnDiskPt::OnDiskWrapper &wrapper = const_cast(GetImplementation()); + OnDiskPt::OnDiskWrapper &wrapper = const_cast(GetImplementation()); - vector weightT = StaticData::Instance().GetWeights(this); - OnDiskPt::Vocab &vocab = wrapper.GetVocab(); + vector weightT = StaticData::Instance().GetWeights(this); + OnDiskPt::Vocab &vocab = wrapper.GetVocab(); - const OnDiskPt::TargetPhraseCollection *targetPhrasesOnDisk = ptNode->GetTargetPhraseCollection(m_tableLimit, wrapper); - TargetPhraseCollection *targetPhrases - = targetPhrasesOnDisk->ConvertToMoses(m_input, m_output, *this, weightT, vocab, false); + const OnDiskPt::TargetPhraseCollection *targetPhrasesOnDisk = ptNode->GetTargetPhraseCollection(m_tableLimit, wrapper); + TargetPhraseCollection *targetPhrases + = targetPhrasesOnDisk->ConvertToMoses(m_input, m_output, *this, weightT, vocab, false); - delete targetPhrasesOnDisk; + delete targetPhrasesOnDisk; - return targetPhrases; + return targetPhrases; } } // namespace From 1d653c87aaa6f7c13d184bad7f1648c4b534ac3c Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 23 Aug 2013 14:25:25 +0100 Subject: [PATCH 3/9] delete PhraseBasedFeatureContext --- contrib/other-builds/moses/.project | 10 ------- moses/FF/ChartBasedFeatureContext.h | 3 --- moses/FF/FeatureFunction.h | 1 - moses/FF/GlobalLexicalModel.cpp | 4 +-- moses/FF/GlobalLexicalModel.h | 2 +- moses/FF/PhraseBasedFeatureContext.cpp | 14 ---------- moses/FF/PhraseBasedFeatureContext.h | 37 -------------------------- moses/FF/PhrasePairFeature.cpp | 10 +++---- moses/FF/PhrasePairFeature.h | 2 +- moses/FF/StatelessFeatureFunction.h | 2 +- moses/FF/WordTranslationFeature.cpp | 10 +++---- moses/FF/WordTranslationFeature.h | 2 +- moses/Hypothesis.cpp | 2 +- moses/ScoreComponentCollectionTest.cpp | 2 +- 14 files changed, 18 insertions(+), 83 deletions(-) delete mode 100644 moses/FF/PhraseBasedFeatureContext.cpp delete mode 100644 moses/FF/PhraseBasedFeatureContext.h diff --git a/contrib/other-builds/moses/.project b/contrib/other-builds/moses/.project index 0ae0ca19f..99d40167b 100644 --- a/contrib/other-builds/moses/.project +++ b/contrib/other-builds/moses/.project @@ -1171,16 +1171,6 @@ 2 virtual:/virtual - - FF/PhraseBasedFeatureContext.cpp - 1 - PARENT-3-PROJECT_LOC/moses/FF/PhraseBasedFeatureContext.cpp - - - FF/PhraseBasedFeatureContext.h - 1 - PARENT-3-PROJECT_LOC/moses/FF/PhraseBasedFeatureContext.h - FF/PhraseBoundaryFeature.cpp 1 diff --git a/moses/FF/ChartBasedFeatureContext.h b/moses/FF/ChartBasedFeatureContext.h index a204f7c77..c8c7e2122 100644 --- a/moses/FF/ChartBasedFeatureContext.h +++ b/moses/FF/ChartBasedFeatureContext.h @@ -6,9 +6,6 @@ class ChartHypothesis; class InputType; class TargetPhrase; -/** - * Same as PhraseBasedFeatureContext, but for chart-based Moses. - **/ class ChartBasedFeatureContext { //The context either has a hypothesis (during search) or a diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h index 0ce62973a..49adb52b5 100644 --- a/moses/FF/FeatureFunction.h +++ b/moses/FF/FeatureFunction.h @@ -4,7 +4,6 @@ #include #include #include -#include "PhraseBasedFeatureContext.h" #include "ChartBasedFeatureContext.h" #include "moses/TypeDef.h" diff --git a/moses/FF/GlobalLexicalModel.cpp b/moses/FF/GlobalLexicalModel.cpp index 0f952b810..15b5f7531 100644 --- a/moses/FF/GlobalLexicalModel.cpp +++ b/moses/FF/GlobalLexicalModel.cpp @@ -167,11 +167,11 @@ float GlobalLexicalModel::GetFromCacheOrScorePhrase( const TargetPhrase& targetP } void GlobalLexicalModel::Evaluate -(const PhraseBasedFeatureContext& context, +(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const { accumulator->PlusEquals( this, - GetFromCacheOrScorePhrase(context.GetHypothesis().GetCurrTargetPhrase()) ); + GetFromCacheOrScorePhrase(hypo.GetCurrTargetPhrase()) ); } bool GlobalLexicalModel::IsUseable(const FactorMask &mask) const diff --git a/moses/FF/GlobalLexicalModel.h b/moses/FF/GlobalLexicalModel.h index 26e13c857..d31cc9f5a 100644 --- a/moses/FF/GlobalLexicalModel.h +++ b/moses/FF/GlobalLexicalModel.h @@ -68,7 +68,7 @@ public: bool IsUseable(const FactorMask &mask) const; - void Evaluate(const PhraseBasedFeatureContext& context, + void Evaluate(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const; diff --git a/moses/FF/PhraseBasedFeatureContext.cpp b/moses/FF/PhraseBasedFeatureContext.cpp deleted file mode 100644 index 9c8cc8ec8..000000000 --- a/moses/FF/PhraseBasedFeatureContext.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "PhraseBasedFeatureContext.h" -#include "moses/Hypothesis.h" -#include "moses/Manager.h" -#include "moses/TranslationOption.h" - -namespace Moses -{ -PhraseBasedFeatureContext::PhraseBasedFeatureContext(const Hypothesis* hypothesis) : - m_hypothesis(hypothesis), - m_translationOption(m_hypothesis->GetTranslationOption()), - m_source(m_hypothesis->GetManager().GetSource()) {} - - -} diff --git a/moses/FF/PhraseBasedFeatureContext.h b/moses/FF/PhraseBasedFeatureContext.h deleted file mode 100644 index 62eb629a7..000000000 --- a/moses/FF/PhraseBasedFeatureContext.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -namespace Moses -{ -class Hypothesis; -class TranslationOption; -class InputType; -class TargetPhrase; -class WordsBitmap; - -/** - * Contains all that a feature function can access without affecting recombination. - * For stateless features, this is all that it can access. Currently this is not - * used for stateful features, as it would need to be retro-fitted to the LM feature. - * TODO: Expose source segmentation,lattice path. - * XXX Don't add anything to the context that would break recombination XXX - **/ -class PhraseBasedFeatureContext -{ - // The context either has a hypothesis (during search), or a TranslationOption and - // source sentence (during pre-calculation). - const Hypothesis* m_hypothesis; - const TranslationOption& m_translationOption; - const InputType& m_source; - -public: - PhraseBasedFeatureContext(const Hypothesis* hypothesis); - - const Hypothesis& GetHypothesis() const { - return *m_hypothesis; - } - -}; - -} // namespace - - diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp index de566a3ce..017099371 100644 --- a/moses/FF/PhrasePairFeature.cpp +++ b/moses/FF/PhrasePairFeature.cpp @@ -106,11 +106,11 @@ void PhrasePairFeature::Load() } void PhrasePairFeature::Evaluate( - const PhraseBasedFeatureContext& context, + const Hypothesis& hypo, ScoreComponentCollection* accumulator) const { - const TargetPhrase& target = context.GetHypothesis().GetCurrTargetPhrase(); - const Phrase& source = context.GetHypothesis().GetTranslationOption().GetInputPath().GetPhrase(); + const TargetPhrase& target = hypo.GetCurrTargetPhrase(); + const Phrase& source = hypo.GetTranslationOption().GetInputPath().GetPhrase(); if (m_simple) { ostringstream namestr; namestr << "pp_"; @@ -131,7 +131,7 @@ void PhrasePairFeature::Evaluate( accumulator->SparsePlusEquals(namestr.str(),1); } if (m_domainTrigger) { - const Sentence& input = static_cast(context.GetHypothesis().GetInput()); + const Sentence& input = static_cast(hypo.GetInput()); const bool use_topicid = input.GetUseTopicId(); const bool use_topicid_prob = input.GetUseTopicIdAndProb(); @@ -199,7 +199,7 @@ void PhrasePairFeature::Evaluate( } } if (m_sourceContext) { - const Sentence& input = static_cast(context.GetHypothesis().GetInput()); + const Sentence& input = static_cast(hypo.GetInput()); // range over source words to get context for(size_t contextIndex = 0; contextIndex < input.GetSize(); contextIndex++ ) { diff --git a/moses/FF/PhrasePairFeature.h b/moses/FF/PhrasePairFeature.h index 6738992ee..6eb91ac12 100644 --- a/moses/FF/PhrasePairFeature.h +++ b/moses/FF/PhrasePairFeature.h @@ -37,7 +37,7 @@ public: bool IsUseable(const FactorMask &mask) const; - void Evaluate(const PhraseBasedFeatureContext& context, + void Evaluate(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const; void EvaluateChart(const ChartBasedFeatureContext& context, diff --git a/moses/FF/StatelessFeatureFunction.h b/moses/FF/StatelessFeatureFunction.h index 1e2c6d450..fcad2137f 100644 --- a/moses/FF/StatelessFeatureFunction.h +++ b/moses/FF/StatelessFeatureFunction.h @@ -23,7 +23,7 @@ public: /** * This should be implemented for features that apply to phrase-based models. **/ - virtual void Evaluate(const PhraseBasedFeatureContext& context, + virtual void Evaluate(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const { } diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp index 82815fd07..87af44254 100644 --- a/moses/FF/WordTranslationFeature.cpp +++ b/moses/FF/WordTranslationFeature.cpp @@ -137,12 +137,12 @@ void WordTranslationFeature::Load() } void WordTranslationFeature::Evaluate -(const PhraseBasedFeatureContext& context, +(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const { - const Sentence& input = static_cast(context.GetHypothesis().GetInput()); - const TranslationOption& transOpt = context.GetHypothesis().GetTranslationOption(); - const TargetPhrase& targetPhrase = context.GetHypothesis().GetCurrTargetPhrase(); + const Sentence& input = static_cast(hypo.GetInput()); + const TranslationOption& transOpt = hypo.GetTranslationOption(); + const TargetPhrase& targetPhrase = hypo.GetCurrTargetPhrase(); const AlignmentInfo &alignment = targetPhrase.GetAlignTerm(); // process aligned words @@ -243,7 +243,7 @@ void WordTranslationFeature::Evaluate } } if (m_sourceContext) { - size_t globalSourceIndex = context.GetHypothesis().GetTranslationOption().GetStartPos() + sourceIndex; + size_t globalSourceIndex = hypo.GetTranslationOption().GetStartPos() + sourceIndex; if (!m_domainTrigger && globalSourceIndex == 0) { // add trigger feature for source stringstream feature; diff --git a/moses/FF/WordTranslationFeature.h b/moses/FF/WordTranslationFeature.h index d6bc7c06f..da3b06352 100644 --- a/moses/FF/WordTranslationFeature.h +++ b/moses/FF/WordTranslationFeature.h @@ -47,7 +47,7 @@ public: return new DummyState(); } - void Evaluate(const PhraseBasedFeatureContext& context, + void Evaluate(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const; void EvaluateChart(const ChartBasedFeatureContext& context, diff --git a/moses/Hypothesis.cpp b/moses/Hypothesis.cpp index c472b8709..efbe03e03 100644 --- a/moses/Hypothesis.cpp +++ b/moses/Hypothesis.cpp @@ -263,7 +263,7 @@ void Hypothesis::EvaluateWith(const StatelessFeatureFunction& slff) { const StaticData &staticData = StaticData::Instance(); if (! staticData.IsFeatureFunctionIgnored( slff )) { - slff.Evaluate(PhraseBasedFeatureContext(this), &m_scoreBreakdown); + slff.Evaluate(*this, &m_scoreBreakdown); } } diff --git a/moses/ScoreComponentCollectionTest.cpp b/moses/ScoreComponentCollectionTest.cpp index 4b5f20ae2..9182c9b0b 100644 --- a/moses/ScoreComponentCollectionTest.cpp +++ b/moses/ScoreComponentCollectionTest.cpp @@ -34,7 +34,7 @@ class MockStatelessFeatureFunction : public StatelessFeatureFunction public: MockStatelessFeatureFunction(const string& desc, size_t n, const string &line) : StatelessFeatureFunction(desc,n, line) {} - virtual void Evaluate(const PhraseBasedFeatureContext&, ScoreComponentCollection*) const {} + virtual void Evaluate(const Hypothesis&, ScoreComponentCollection*) const {} virtual void EvaluateChart(const ChartBasedFeatureContext&, ScoreComponentCollection*) const {} virtual void Evaluate(const TargetPhrase &targetPhrase , ScoreComponentCollection &scoreBreakdown From 3ad3cd900426b10e0bd7bb01612b6f7d55592fa2 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 23 Aug 2013 14:39:42 +0100 Subject: [PATCH 4/9] delete ChartBasedFeatureContext --- moses/FF/ChartBasedFeatureContext.cpp | 8 -------- moses/FF/ChartBasedFeatureContext.h | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/moses/FF/ChartBasedFeatureContext.cpp b/moses/FF/ChartBasedFeatureContext.cpp index a74cce50c..2d4ca0761 100644 --- a/moses/FF/ChartBasedFeatureContext.cpp +++ b/moses/FF/ChartBasedFeatureContext.cpp @@ -11,14 +11,6 @@ ChartBasedFeatureContext::ChartBasedFeatureContext m_source(hypothesis->GetManager().GetSource()) {} -ChartBasedFeatureContext::ChartBasedFeatureContext( - const TargetPhrase& targetPhrase, - const InputType& source): - m_hypothesis(NULL), - m_targetPhrase(targetPhrase), - m_source(source) -{} - } diff --git a/moses/FF/ChartBasedFeatureContext.h b/moses/FF/ChartBasedFeatureContext.h index c8c7e2122..d181245c8 100644 --- a/moses/FF/ChartBasedFeatureContext.h +++ b/moses/FF/ChartBasedFeatureContext.h @@ -18,16 +18,6 @@ class ChartBasedFeatureContext public: ChartBasedFeatureContext(const ChartHypothesis* hypothesis); - ChartBasedFeatureContext(const TargetPhrase& targetPhrase, - const InputType& source); - - const InputType& GetSource() const { - return m_source; - } - - const TargetPhrase& GetTargetPhrase() const { - return m_targetPhrase; - } }; From 5625f37eb170546ab84a24480ef674d469475047 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 23 Aug 2013 15:00:47 +0100 Subject: [PATCH 5/9] delete ChartBasedFeatureContext --- contrib/other-builds/moses/.project | 10 ---------- moses/ChartHypothesis.cpp | 2 +- moses/FF/ChartBasedFeatureContext.cpp | 16 ---------------- moses/FF/ChartBasedFeatureContext.h | 26 -------------------------- moses/FF/FeatureFunction.h | 1 - moses/FF/GlobalLexicalModel.h | 2 +- moses/FF/PhraseLengthFeature.h | 2 +- moses/FF/PhrasePairFeature.h | 2 +- moses/FF/StatelessFeatureFunction.h | 2 +- moses/FF/WordTranslationFeature.cpp | 2 +- moses/FF/WordTranslationFeature.h | 2 +- moses/ScoreComponentCollectionTest.cpp | 2 +- 12 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 moses/FF/ChartBasedFeatureContext.cpp delete mode 100644 moses/FF/ChartBasedFeatureContext.h diff --git a/contrib/other-builds/moses/.project b/contrib/other-builds/moses/.project index 99d40167b..d15ff4692 100644 --- a/contrib/other-builds/moses/.project +++ b/contrib/other-builds/moses/.project @@ -1076,16 +1076,6 @@ 1 PARENT-3-PROJECT_LOC/moses/FF/BleuScoreFeature.h - - FF/ChartBasedFeatureContext.cpp - 1 - PARENT-3-PROJECT_LOC/moses/FF/ChartBasedFeatureContext.cpp - - - FF/ChartBasedFeatureContext.h - 1 - PARENT-3-PROJECT_LOC/moses/FF/ChartBasedFeatureContext.h - FF/ControlRecombination.cpp 1 diff --git a/moses/ChartHypothesis.cpp b/moses/ChartHypothesis.cpp index c3f090b64..23896b782 100644 --- a/moses/ChartHypothesis.cpp +++ b/moses/ChartHypothesis.cpp @@ -162,7 +162,7 @@ void ChartHypothesis::Evaluate() StatelessFeatureFunction::GetStatelessFeatureFunctions(); for (unsigned i = 0; i < sfs.size(); ++i) { if (! staticData.IsFeatureFunctionIgnored( *sfs[i] )) { - sfs[i]->EvaluateChart(ChartBasedFeatureContext(this),&m_scoreBreakdown); + sfs[i]->EvaluateChart(*this,&m_scoreBreakdown); } } diff --git a/moses/FF/ChartBasedFeatureContext.cpp b/moses/FF/ChartBasedFeatureContext.cpp deleted file mode 100644 index 2d4ca0761..000000000 --- a/moses/FF/ChartBasedFeatureContext.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "ChartBasedFeatureContext.h" -#include "moses/ChartHypothesis.h" -#include "moses/ChartManager.h" - -namespace Moses -{ -ChartBasedFeatureContext::ChartBasedFeatureContext -(const ChartHypothesis* hypothesis): - m_hypothesis(hypothesis), - m_targetPhrase(hypothesis->GetCurrTargetPhrase()), - m_source(hypothesis->GetManager().GetSource()) -{} - - -} - diff --git a/moses/FF/ChartBasedFeatureContext.h b/moses/FF/ChartBasedFeatureContext.h deleted file mode 100644 index d181245c8..000000000 --- a/moses/FF/ChartBasedFeatureContext.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -namespace Moses -{ -class ChartHypothesis; -class InputType; -class TargetPhrase; - -class ChartBasedFeatureContext -{ - //The context either has a hypothesis (during search) or a - //TargetPhrase and source sentence (during pre-calculation) - //TODO: should the context also include some info on where the TargetPhrase - //is anchored (assuming it's lexicalised), which is available at pre-calc? - const ChartHypothesis* m_hypothesis; - const TargetPhrase& m_targetPhrase; - const InputType& m_source; - -public: - ChartBasedFeatureContext(const ChartHypothesis* hypothesis); - -}; - -} // namespace - - diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h index 49adb52b5..71179ee81 100644 --- a/moses/FF/FeatureFunction.h +++ b/moses/FF/FeatureFunction.h @@ -4,7 +4,6 @@ #include #include #include -#include "ChartBasedFeatureContext.h" #include "moses/TypeDef.h" namespace Moses diff --git a/moses/FF/GlobalLexicalModel.h b/moses/FF/GlobalLexicalModel.h index d31cc9f5a..9c5f40c46 100644 --- a/moses/FF/GlobalLexicalModel.h +++ b/moses/FF/GlobalLexicalModel.h @@ -73,7 +73,7 @@ public: void EvaluateChart( - const ChartBasedFeatureContext& context, + const ChartHypothesis& hypo, ScoreComponentCollection* accumulator) const { throw std::logic_error("GlobalLexicalModel not supported in chart decoder, yet"); } diff --git a/moses/FF/PhraseLengthFeature.h b/moses/FF/PhraseLengthFeature.h index 9bcc2cb93..5d0284c14 100644 --- a/moses/FF/PhraseLengthFeature.h +++ b/moses/FF/PhraseLengthFeature.h @@ -24,7 +24,7 @@ public: return true; } - void EvaluateChart(const ChartBasedFeatureContext& context, + void EvaluateChart(const ChartHypothesis& hypo, ScoreComponentCollection*) const { throw std::logic_error("PhraseLengthFeature not valid in chart decoder"); } diff --git a/moses/FF/PhrasePairFeature.h b/moses/FF/PhrasePairFeature.h index 6eb91ac12..eb94fb48b 100644 --- a/moses/FF/PhrasePairFeature.h +++ b/moses/FF/PhrasePairFeature.h @@ -40,7 +40,7 @@ public: void Evaluate(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const; - void EvaluateChart(const ChartBasedFeatureContext& context, + void EvaluateChart(const ChartHypothesis& hypo, ScoreComponentCollection*) const { throw std::logic_error("PhrasePairFeature not valid in chart decoder"); } diff --git a/moses/FF/StatelessFeatureFunction.h b/moses/FF/StatelessFeatureFunction.h index fcad2137f..51101add3 100644 --- a/moses/FF/StatelessFeatureFunction.h +++ b/moses/FF/StatelessFeatureFunction.h @@ -30,7 +30,7 @@ public: /** * Same for chart-based features. **/ - virtual void EvaluateChart(const ChartBasedFeatureContext& context, + virtual void EvaluateChart(const ChartHypothesis &hypo, ScoreComponentCollection* accumulator) const { } diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp index 87af44254..ebedf2388 100644 --- a/moses/FF/WordTranslationFeature.cpp +++ b/moses/FF/WordTranslationFeature.cpp @@ -349,7 +349,7 @@ void WordTranslationFeature::Evaluate } void WordTranslationFeature::EvaluateChart( - const ChartBasedFeatureContext& context, + const ChartHypothesis &hypo, ScoreComponentCollection* accumulator) const { UTIL_THROW(util::Exception, "Need source phrase. Can't be arsed at the moment"); diff --git a/moses/FF/WordTranslationFeature.h b/moses/FF/WordTranslationFeature.h index da3b06352..eb88c5812 100644 --- a/moses/FF/WordTranslationFeature.h +++ b/moses/FF/WordTranslationFeature.h @@ -50,7 +50,7 @@ public: void Evaluate(const Hypothesis& hypo, ScoreComponentCollection* accumulator) const; - void EvaluateChart(const ChartBasedFeatureContext& context, + void EvaluateChart(const ChartHypothesis &hypo, ScoreComponentCollection* accumulator) const; void SetParameter(const std::string& key, const std::string& value); }; diff --git a/moses/ScoreComponentCollectionTest.cpp b/moses/ScoreComponentCollectionTest.cpp index 9182c9b0b..be25b5b98 100644 --- a/moses/ScoreComponentCollectionTest.cpp +++ b/moses/ScoreComponentCollectionTest.cpp @@ -35,7 +35,7 @@ public: MockStatelessFeatureFunction(const string& desc, size_t n, const string &line) : StatelessFeatureFunction(desc,n, line) {} virtual void Evaluate(const Hypothesis&, ScoreComponentCollection*) const {} - virtual void EvaluateChart(const ChartBasedFeatureContext&, ScoreComponentCollection*) const {} + virtual void EvaluateChart(const ChartHypothesis&, ScoreComponentCollection*) const {} virtual void Evaluate(const TargetPhrase &targetPhrase , ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &estimatedFutureScore) const { From de9decc30d9e2f1139f03f68c5d16cd32d86f944 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 23 Aug 2013 21:02:03 +0100 Subject: [PATCH 6/9] mark GetTargetPhraseCollection with LEGACY --- contrib/other-builds/moses-chart-cmd/.cproject | 5 +++-- contrib/other-builds/moses-cmd/.cproject | 5 +++-- moses/TranslationModel/PhraseDictionary.cpp | 6 ++---- moses/TranslationModel/PhraseDictionary.h | 2 +- moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp | 2 +- moses/TranslationModel/PhraseDictionaryDynSuffixArray.h | 2 +- moses/TranslationModel/PhraseDictionaryMemory.cpp | 2 +- moses/TranslationModel/PhraseDictionaryMemory.h | 2 +- moses/TranslationModel/PhraseDictionaryMultiModel.cpp | 4 ++-- moses/TranslationModel/PhraseDictionaryMultiModel.h | 2 +- moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp | 6 +++--- moses/TranslationModel/PhraseDictionaryMultiModelCounts.h | 2 +- moses/TranslationModel/RuleTable/UTrie.h | 2 -- 13 files changed, 20 insertions(+), 22 deletions(-) diff --git a/contrib/other-builds/moses-chart-cmd/.cproject b/contrib/other-builds/moses-chart-cmd/.cproject index b6112ebc8..1e38e75c5 100644 --- a/contrib/other-builds/moses-chart-cmd/.cproject +++ b/contrib/other-builds/moses-chart-cmd/.cproject @@ -1,5 +1,7 @@ - + + + @@ -85,7 +87,6 @@ - diff --git a/contrib/other-builds/moses-cmd/.cproject b/contrib/other-builds/moses-cmd/.cproject index 7848c58c2..d992d838f 100644 --- a/contrib/other-builds/moses-cmd/.cproject +++ b/contrib/other-builds/moses-cmd/.cproject @@ -1,5 +1,7 @@ - + + + @@ -81,7 +83,6 @@ -