diff --git a/moses/FF/Factory.cpp b/moses/FF/Factory.cpp index d2c3cf639..f7e92dc83 100644 --- a/moses/FF/Factory.cpp +++ b/moses/FF/Factory.cpp @@ -153,6 +153,8 @@ void FeatureFactory ::DefaultSetup(F *feature) { + FeatureFunction::Register(feature); + StaticData &static_data = StaticData::InstanceNonConst(); const std::string &featureName = feature->GetScoreProducerDescription(); std::vector weights = static_data.GetParameter()->GetWeights(featureName); diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp index 50e69742e..d9cb3f1ae 100644 --- a/moses/FF/FeatureFunction.cpp +++ b/moses/FF/FeatureFunction.cpp @@ -54,7 +54,8 @@ FeatureFunction(const std::string& line, bool registerNow) { m_numTuneableComponents = m_numScoreComponents; ParseLine(line); - if (registerNow) Register(); + // if (registerNow) Register(); // now done in FeatureFactory::DefaultSetup() + // TO DO: eliminate the registerNow parameter } FeatureFunction::FeatureFunction(size_t numScoreComponents, const std::string& line, bool registerNow) @@ -66,15 +67,16 @@ FeatureFunction::FeatureFunction(size_t numScoreComponents, const std::string& l { m_numTuneableComponents = m_numScoreComponents; ParseLine(line); - if (registerNow) Register(); + // if (registerNow) Register(); // now done in FeatureFactory::DefaultSetup() + // TO DO: eliminate the registerNow parameter } void FeatureFunction:: -Register() +Register(FeatureFunction* ff) { - ScoreComponentCollection::RegisterScoreProducer(this); - s_staticColl.push_back(this); + ScoreComponentCollection::RegisterScoreProducer(ff); + s_staticColl.push_back(ff); } FeatureFunction::~FeatureFunction() {} diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h index 2740a193e..c9ad7d2c8 100644 --- a/moses/FF/FeatureFunction.h +++ b/moses/FF/FeatureFunction.h @@ -49,7 +49,8 @@ protected: //In case there's multiple producers with the same description static std::multiset description_counts; - void Register(); +public: + static void Register(FeatureFunction* ff); private: // void Initialize(const std::string &line); void ParseLine(const std::string &line); diff --git a/moses/FF/LexicalReordering/LexicalReordering.cpp b/moses/FF/LexicalReordering/LexicalReordering.cpp index c256570fd..168d7a8ec 100644 --- a/moses/FF/LexicalReordering/LexicalReordering.cpp +++ b/moses/FF/LexicalReordering/LexicalReordering.cpp @@ -75,7 +75,7 @@ LexicalReordering(const std::string &line) << m_configuration->GetNumScoreComponents() << ")"); m_configuration->ConfigureSparse(sparseArgs, this); - this->Register(); + // this->Register(); } LexicalReordering:: diff --git a/moses/LM/Base.cpp b/moses/LM/Base.cpp index 88441ace5..06911c325 100644 --- a/moses/LM/Base.cpp +++ b/moses/LM/Base.cpp @@ -38,10 +38,10 @@ LanguageModel::LanguageModel(const std::string &line) : m_enableOOVFeature(false) { // load m_enableOOVFeature via SetParameter() first - ReadParameters(); + // ReadParameters(); this->m_numScoreComponents = this->m_numTuneableComponents = m_enableOOVFeature ? 2 : 1; // register with the correct m_numScoreComponents - Register(); + // Register(); } @@ -112,6 +112,7 @@ void LanguageModel::SetParameter(const std::string& key, const std::string& valu { if(key == "oov-feature") { m_enableOOVFeature = Scan(value); + this->m_numScoreComponents = this->m_numTuneableComponents = m_enableOOVFeature ? 2 : 1; } else { StatefulFeatureFunction::SetParameter(key, value); } diff --git a/moses/LM/SingleFactor.h b/moses/LM/SingleFactor.h index 6c4945b0f..c0def95d6 100644 --- a/moses/LM/SingleFactor.h +++ b/moses/LM/SingleFactor.h @@ -47,7 +47,7 @@ protected: public: virtual ~LanguageModelSingleFactor(); bool IsUseable(const FactorMask &mask) const; - void SetParameter(const std::string& key, const std::string& value); + virtual void SetParameter(const std::string& key, const std::string& value); const Factor *GetSentenceStart() const { return m_sentenceStart; diff --git a/moses/ScoreComponentCollectionTest.cpp b/moses/ScoreComponentCollectionTest.cpp index e0d9982e4..b4e4ce32a 100644 --- a/moses/ScoreComponentCollectionTest.cpp +++ b/moses/ScoreComponentCollectionTest.cpp @@ -89,7 +89,12 @@ public: struct MockProducers { - MockProducers() {} + MockProducers() + { + FeatureFunction::Register(&single); + FeatureFunction::Register(&multi); + FeatureFunction::Register(&sparse); + } MockSingleFeature single; MockMultiFeature multi; diff --git a/moses/TranslationModel/UG/mmsapt.cpp b/moses/TranslationModel/UG/mmsapt.cpp index 0dcb7b5e1..3e8d326d1 100644 --- a/moses/TranslationModel/UG/mmsapt.cpp +++ b/moses/TranslationModel/UG/mmsapt.cpp @@ -82,7 +82,7 @@ namespace Moses // * Don't use features that depend on generation steps that won't be run // yet at extract time SetFeaturesToApply(); - Register(); + // Register(); } void