From b71d6c9b24dad7b8897813f0d51d9b095a0793b2 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 2 Jan 2013 16:54:38 +0000 Subject: [PATCH] move code from LoadPhraseLengthFeature() to constructor in class PhraseLengthFeature --- moses/PhraseLengthFeature.cpp | 6 ++++++ moses/PhraseLengthFeature.h | 4 +--- moses/StaticData.cpp | 18 +++++------------- moses/StaticData.h | 1 - 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/moses/PhraseLengthFeature.cpp b/moses/PhraseLengthFeature.cpp index 92281bf93..2d931e7a1 100644 --- a/moses/PhraseLengthFeature.cpp +++ b/moses/PhraseLengthFeature.cpp @@ -8,6 +8,12 @@ namespace Moses { using namespace std; +PhraseLengthFeature::PhraseLengthFeature(const std::string &line) +:StatelessFeatureFunction("pl", ScoreProducer::unlimited) +{ + +} + void PhraseLengthFeature::Evaluate( const PhraseBasedFeatureContext& context, ScoreComponentCollection* accumulator) const diff --git a/moses/PhraseLengthFeature.h b/moses/PhraseLengthFeature.h index eba8915d2..59f264307 100644 --- a/moses/PhraseLengthFeature.h +++ b/moses/PhraseLengthFeature.h @@ -17,9 +17,7 @@ namespace Moses */ class PhraseLengthFeature : public StatelessFeatureFunction { public: - PhraseLengthFeature(): - StatelessFeatureFunction("pl", ScoreProducer::unlimited) - {} + PhraseLengthFeature(const std::string &line); void Evaluate(const PhraseBasedFeatureContext& context, ScoreComponentCollection* accumulator) const; diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index 89a024cb0..1a70c3979 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -580,6 +580,11 @@ SetWeight(m_unknownWordPenaltyProducer, weightUnknownWord); const vector &weights = m_parameter->GetWeights(feature, featureIndex); //SetWeights(model, weights); } + else if (feature == "pl") { + PhraseLengthFeature *model = new PhraseLengthFeature(line); + const vector &weights = m_parameter->GetWeights(feature, featureIndex); + //SetWeights(model, weights); + } } @@ -597,7 +602,6 @@ SetWeight(m_unknownWordPenaltyProducer, weightUnknownWord); if (!LoadReferences()) return false; if (!LoadDiscrimLMFeature()) return false; if (!LoadPhrasePairFeature()) return false; - if (!LoadPhraseLengthFeature()) return false; if (!LoadWordTranslationFeature()) return false; // report individual sparse features in n-best list @@ -1420,18 +1424,6 @@ bool StaticData::LoadPhrasePairFeature() return true; } -bool StaticData::LoadPhraseLengthFeature() -{ - if (m_parameter->isParamSpecified("phrase-length-feature")) { - PhraseLengthFeature *phraseLengthFeature = new PhraseLengthFeature(); - if (m_parameter->GetParam("report-sparse-features").size() > 0) { - phraseLengthFeature->SetSparseFeatureReporting(); - } - } - - return true; -} - bool StaticData::LoadWordTranslationFeature() { const vector ¶meters = m_parameter->GetParam("word-translation-feature"); diff --git a/moses/StaticData.h b/moses/StaticData.h index 6c15e3517..200746ab2 100644 --- a/moses/StaticData.h +++ b/moses/StaticData.h @@ -252,7 +252,6 @@ protected: bool LoadReferences(); bool LoadDiscrimLMFeature(); bool LoadPhrasePairFeature(); - bool LoadPhraseLengthFeature(); bool LoadWordTranslationFeature(); void ReduceTransOptCache() const;