diff --git a/moses/FF/DistortionScoreProducer.cpp b/moses/FF/DistortionScoreProducer.cpp index c44d204bf..67a1185cb 100644 --- a/moses/FF/DistortionScoreProducer.cpp +++ b/moses/FF/DistortionScoreProducer.cpp @@ -23,16 +23,7 @@ struct DistortionState_traditional : public FFState { DistortionScoreProducer::DistortionScoreProducer(const std::string &line) : StatefulFeatureFunction("Distortion", 1, line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } const FFState* DistortionScoreProducer::EmptyHypothesisState(const InputType &input) const diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp index f484fd1ed..7cfdf2ecb 100644 --- a/moses/FF/FeatureFunction.cpp +++ b/moses/FF/FeatureFunction.cpp @@ -107,5 +107,19 @@ void FeatureFunction::OverrideParameter(const std::string& key, const std::strin UTIL_THROW_IF(!ret, util::Exception, "Unknown argument" << key); } +void FeatureFunction::ReadParameters() +{ + size_t ind = 0; + while (ind < m_args.size()) { + vector &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} + } diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h index b32097eee..94b1c494d 100644 --- a/moses/FF/FeatureFunction.h +++ b/moses/FF/FeatureFunction.h @@ -108,6 +108,7 @@ public: virtual bool SetParameter(const std::string& key, const std::string& value); virtual void OverrideParameter(const std::string& key, const std::string& value); + virtual void ReadParameters(); }; } diff --git a/moses/FF/GlobalLexicalModel.cpp b/moses/FF/GlobalLexicalModel.cpp index 541070646..d4d91fa51 100644 --- a/moses/FF/GlobalLexicalModel.cpp +++ b/moses/FF/GlobalLexicalModel.cpp @@ -13,18 +13,7 @@ GlobalLexicalModel::GlobalLexicalModel(const std::string &line) : StatelessFeatureFunction("GlobalLexicalModel",1, line) { std::cerr << "Creating global lexical model...\n"; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); // define bias word FactorCollection &factorCollection = FactorCollection::Instance(); diff --git a/moses/FF/PhraseBoundaryFeature.cpp b/moses/FF/PhraseBoundaryFeature.cpp index 16dc522eb..6da4ed319 100644 --- a/moses/FF/PhraseBoundaryFeature.cpp +++ b/moses/FF/PhraseBoundaryFeature.cpp @@ -19,19 +19,7 @@ PhraseBoundaryFeature::PhraseBoundaryFeature(const std::string &line) : StatefulFeatureFunction("PhraseBoundaryFeature", 0, line) { std::cerr << "Initializing source word deletion feature.." << std::endl; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); - + ReadParameters(); } bool PhraseBoundaryFeature::SetParameter(const std::string& key, const std::string& value) diff --git a/moses/FF/PhraseLengthFeature.cpp b/moses/FF/PhraseLengthFeature.cpp index d419941e5..fb69a2de3 100644 --- a/moses/FF/PhraseLengthFeature.cpp +++ b/moses/FF/PhraseLengthFeature.cpp @@ -12,16 +12,7 @@ using namespace std; PhraseLengthFeature::PhraseLengthFeature(const std::string &line) :StatelessFeatureFunction("PhraseLengthFeature", 0, line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } void PhraseLengthFeature::Evaluate(const Phrase &source diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp index e5b75958f..12f8d264e 100644 --- a/moses/FF/PhrasePairFeature.cpp +++ b/moses/FF/PhrasePairFeature.cpp @@ -17,18 +17,7 @@ PhrasePairFeature::PhrasePairFeature(const std::string &line) :StatelessFeatureFunction("PhrasePairFeature", 0, line) { std::cerr << "Initializing PhrasePairFeature.." << std::endl; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); if (m_simple == 1) std::cerr << "using simple phrase pairs.. "; if (m_sourceContext == 1) std::cerr << "using source context.. "; diff --git a/moses/FF/SourceWordDeletionFeature.cpp b/moses/FF/SourceWordDeletionFeature.cpp index a4d1c3627..28000425d 100644 --- a/moses/FF/SourceWordDeletionFeature.cpp +++ b/moses/FF/SourceWordDeletionFeature.cpp @@ -22,18 +22,7 @@ SourceWordDeletionFeature::SourceWordDeletionFeature(const std::string &line) m_unrestricted(true) { std::cerr << "Initializing source word deletion feature.." << std::endl; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); } bool SourceWordDeletionFeature::SetParameter(const std::string& key, const std::string& value) diff --git a/moses/FF/TargetBigramFeature.cpp b/moses/FF/TargetBigramFeature.cpp index b170d9159..682a3d9f1 100644 --- a/moses/FF/TargetBigramFeature.cpp +++ b/moses/FF/TargetBigramFeature.cpp @@ -21,18 +21,7 @@ TargetBigramFeature::TargetBigramFeature(const std::string &line) :StatefulFeatureFunction("TargetBigramFeature", 0, line) { std::cerr << "Initializing target bigram feature.." << std::endl; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); FactorCollection& factorCollection = FactorCollection::Instance(); const Factor* bosFactor = diff --git a/moses/FF/TargetNgramFeature.cpp b/moses/FF/TargetNgramFeature.cpp index a42f4661a..fb36e2be8 100644 --- a/moses/FF/TargetNgramFeature.cpp +++ b/moses/FF/TargetNgramFeature.cpp @@ -41,19 +41,7 @@ TargetNgramFeature::TargetNgramFeature(const std::string &line) :StatefulFeatureFunction("TargetNgramFeature", 0, line) { std::cerr << "Initializing target ngram feature.." << std::endl; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); - + ReadParameters(); } bool TargetNgramFeature::SetParameter(const std::string& key, const std::string& value) diff --git a/moses/FF/TargetWordInsertionFeature.cpp b/moses/FF/TargetWordInsertionFeature.cpp index 78f02d2a8..67b11b61b 100644 --- a/moses/FF/TargetWordInsertionFeature.cpp +++ b/moses/FF/TargetWordInsertionFeature.cpp @@ -20,18 +20,7 @@ TargetWordInsertionFeature::TargetWordInsertionFeature(const std::string &line) m_unrestricted(true) { std::cerr << "Initializing target word insertion feature.." << std::endl; - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); - + ReadParameters(); } bool TargetWordInsertionFeature::SetParameter(const std::string& key, const std::string& value) diff --git a/moses/FF/UnknownWordPenaltyProducer.cpp b/moses/FF/UnknownWordPenaltyProducer.cpp index 86a561ebe..adc4c4d6b 100644 --- a/moses/FF/UnknownWordPenaltyProducer.cpp +++ b/moses/FF/UnknownWordPenaltyProducer.cpp @@ -9,17 +9,7 @@ namespace Moses UnknownWordPenaltyProducer::UnknownWordPenaltyProducer(const std::string &line) : StatelessFeatureFunction("UnknownWordPenalty",1, line) { m_tuneable = false; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } } diff --git a/moses/FF/WordPenaltyProducer.cpp b/moses/FF/WordPenaltyProducer.cpp index a93a62dde..054852349 100644 --- a/moses/FF/WordPenaltyProducer.cpp +++ b/moses/FF/WordPenaltyProducer.cpp @@ -8,16 +8,7 @@ namespace Moses { WordPenaltyProducer::WordPenaltyProducer(const std::string &line) : StatelessFeatureFunction("WordPenalty",1, line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } void WordPenaltyProducer::Evaluate(const Phrase &source diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp index b2649bb67..6caa963cb 100644 --- a/moses/FF/WordTranslationFeature.cpp +++ b/moses/FF/WordTranslationFeature.cpp @@ -26,18 +26,7 @@ WordTranslationFeature::WordTranslationFeature(const std::string &line) ,m_domainTrigger(false) { std::cerr << "Initializing word translation feature.. " << endl; - - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); if (m_simple == 1) std::cerr << "using simple word translations.. "; if (m_sourceContext == 1) std::cerr << "using source context.. "; diff --git a/moses/GenerationDictionary.cpp b/moses/GenerationDictionary.cpp index c97ae9966..2a6854bf2 100644 --- a/moses/GenerationDictionary.cpp +++ b/moses/GenerationDictionary.cpp @@ -38,16 +38,7 @@ namespace Moses GenerationDictionary::GenerationDictionary(const std::string &line) : DecodeFeature("Generation", line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } void GenerationDictionary::Load() diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp index c932ec3c8..dce6a6228 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp @@ -49,16 +49,7 @@ PhraseDictionaryCompact::PhraseDictionaryCompact(const std::string &line) ,m_phraseDecoder(0) ,m_weight(0) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } void PhraseDictionaryCompact::Load() diff --git a/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp b/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp index 2659c9c96..2a0479689 100644 --- a/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp +++ b/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp @@ -12,18 +12,7 @@ PhraseDictionaryDynSuffixArray::PhraseDictionaryDynSuffixArray(const std::string :PhraseDictionary("PhraseDictionaryDynSuffixArray", line) ,m_biSA(new BilingualDynSuffixArray()) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); - + ReadParameters(); } PhraseDictionaryDynSuffixArray::~PhraseDictionaryDynSuffixArray() diff --git a/moses/TranslationModel/PhraseDictionaryMemory.cpp b/moses/TranslationModel/PhraseDictionaryMemory.cpp index f6b186de2..4a1a86813 100644 --- a/moses/TranslationModel/PhraseDictionaryMemory.cpp +++ b/moses/TranslationModel/PhraseDictionaryMemory.cpp @@ -42,16 +42,7 @@ namespace Moses PhraseDictionaryMemory::PhraseDictionaryMemory(const std::string &line) : RuleTableTrie("PhraseDictionaryMemory", line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } TargetPhraseCollection &PhraseDictionaryMemory::GetOrCreateTargetPhraseCollection( diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index ebf703ad2..330de0ec0 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -28,17 +28,7 @@ namespace Moses PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line) :PhraseDictionary("PhraseDictionaryMultiModel", line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); if (m_mode != "interpolate") { ostringstream msg; diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index 3cc5c788a..2d1509365 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -68,17 +68,7 @@ PhraseDictionaryMultiModelCounts::PhraseDictionaryMultiModelCounts(const std::st //m_mode = "interpolate"; //m_combineFunction = LinearInterpolationFromCounts; cerr << "m_args=" << m_args.size() << endl; - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - CHECK(m_args.size() == 0); + ReadParameters(); CHECK(m_targetTable.size() == m_pdStr.size()); diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp index dbe5b0ea1..630d8e2e2 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp @@ -29,16 +29,7 @@ PhraseDictionaryTreeAdaptor:: PhraseDictionaryTreeAdaptor(const std::string &line) : PhraseDictionary("PhraseDictionaryBinary", line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor() diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp index 1d36ff675..2f05e92b6 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp @@ -32,16 +32,7 @@ namespace Moses { PhraseDictionaryOnDisk::PhraseDictionaryOnDisk(const std::string &line) : MyBase("PhraseDictionaryOnDisk", line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } + ReadParameters(); } PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk()