diff options
-rw-r--r-- | moses-chart-cmd/IOWrapper.cpp | 2 | ||||
-rw-r--r-- | moses-chart-cmd/Main.cpp | 2 | ||||
-rw-r--r-- | moses-cmd/IOWrapper.cpp | 2 | ||||
-rw-r--r-- | moses-cmd/Main.cpp | 4 | ||||
-rw-r--r-- | moses/FeatureFunction.cpp | 9 | ||||
-rw-r--r-- | moses/FeatureFunction.h | 3 | ||||
-rw-r--r-- | moses/GlobalLexicalModelUnlimited.cpp | 2 | ||||
-rw-r--r-- | moses/Manager.cpp | 2 | ||||
-rw-r--r-- | moses/PhraseBoundaryFeature.cpp | 2 | ||||
-rw-r--r-- | moses/PhraseLengthFeature.cpp | 2 | ||||
-rw-r--r-- | moses/PhrasePairFeature.cpp | 2 | ||||
-rw-r--r-- | moses/ScoreComponentCollection.cpp | 11 | ||||
-rw-r--r-- | moses/ScoreComponentCollection.h | 9 | ||||
-rw-r--r-- | moses/ScoreComponentCollectionTest.cpp | 2 | ||||
-rw-r--r-- | moses/SourceWordDeletionFeature.cpp | 2 | ||||
-rw-r--r-- | moses/TargetBigramFeature.cpp | 2 | ||||
-rw-r--r-- | moses/TargetNgramFeature.cpp | 2 | ||||
-rw-r--r-- | moses/TargetWordInsertionFeature.cpp | 2 | ||||
-rw-r--r-- | moses/WordTranslationFeature.cpp | 2 |
19 files changed, 19 insertions, 45 deletions
diff --git a/moses-chart-cmd/IOWrapper.cpp b/moses-chart-cmd/IOWrapper.cpp index 3ada07e59..84a2ce69b 100644 --- a/moses-chart-cmd/IOWrapper.cpp +++ b/moses-chart-cmd/IOWrapper.cpp @@ -425,7 +425,7 @@ void IOWrapper::OutputFeatureScores( std::ostream& out, const ScoreComponentColl bool labeledOutput = staticData.IsLabeledNBestList(); // regular features (not sparse) - if (ff->GetNumScoreComponents() != FeatureFunction::unlimited) { + if (ff->GetNumScoreComponents() != 0) { if( labeledOutput && lastName != ff->GetScoreProducerDescription() ) { lastName = ff->GetScoreProducerDescription(); out << " " << lastName << "="; diff --git a/moses-chart-cmd/Main.cpp b/moses-chart-cmd/Main.cpp index 44b657c19..2db3f9259 100644 --- a/moses-chart-cmd/Main.cpp +++ b/moses-chart-cmd/Main.cpp @@ -189,7 +189,7 @@ bool ReadInput(IOWrapper &ioWrapper, InputTypeEnum inputType, InputType*& source static void PrintFeatureWeight(const FeatureFunction* ff) { size_t numScoreComps = ff->GetNumScoreComponents(); - if (numScoreComps != FeatureFunction::unlimited) { + if (numScoreComps != 0) { vector<float> values = StaticData::Instance().GetAllWeights().GetScoresForProducer(ff); cout << ff->GetScoreProducerDescription() << "="; for (size_t i = 0; i < numScoreComps; ++i) { diff --git a/moses-cmd/IOWrapper.cpp b/moses-cmd/IOWrapper.cpp index a7c4633e0..e3e93aa7c 100644 --- a/moses-cmd/IOWrapper.cpp +++ b/moses-cmd/IOWrapper.cpp @@ -484,7 +484,7 @@ void OutputFeatureScores( std::ostream& out bool labeledOutput = staticData.IsLabeledNBestList(); // regular features (not sparse) - if (ff->GetNumScoreComponents() != FeatureFunction::unlimited) { + if (ff->GetNumScoreComponents() != 0) { if( labeledOutput && lastName != ff->GetScoreProducerDescription() ) { lastName = ff->GetScoreProducerDescription(); out << " " << lastName << "="; diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index bf1e08605..8f177389c 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -449,7 +449,7 @@ private: static void PrintFeatureWeight(const FeatureFunction* ff) { size_t numScoreComps = ff->GetNumScoreComponents(); - if (numScoreComps != FeatureFunction::unlimited) { + if (numScoreComps != 0) { vector<float> values = StaticData::Instance().GetAllWeights().GetScoresForProducer(ff); cout << ff->GetScoreProducerDescription() << "="; for (size_t i = 0; i < numScoreComps; ++i) { @@ -491,7 +491,7 @@ static void ShowWeights() size_t OutputFeatureWeightsForHypergraph(size_t index, const FeatureFunction* ff, std::ostream &outputSearchGraphStream) { size_t numScoreComps = ff->GetNumScoreComponents(); - if (numScoreComps != FeatureFunction::unlimited) { + if (numScoreComps != 0) { vector<float> values = StaticData::Instance().GetAllWeights().GetScoresForProducer(ff); if (numScoreComps > 1) { for (size_t i = 0; i < numScoreComps; ++i) { diff --git a/moses/FeatureFunction.cpp b/moses/FeatureFunction.cpp index 9e719a42b..3b921ac8e 100644 --- a/moses/FeatureFunction.cpp +++ b/moses/FeatureFunction.cpp @@ -73,7 +73,6 @@ const TargetPhrase& ChartBasedFeatureContext::GetTargetPhrase() const } multiset<string> FeatureFunction::description_counts; -const size_t FeatureFunction::unlimited = -1; std::vector<FeatureFunction*> FeatureFunction::m_producers; std::vector<const StatelessFeatureFunction*> StatelessFeatureFunction::m_statelessFFs; @@ -97,10 +96,7 @@ FeatureFunction::FeatureFunction(const std::string& description, const std::stri m_description = dstream.str(); } - if (m_numScoreComponents != unlimited) { ScoreComponentCollection::RegisterScoreProducer(this); - } - m_producers.push_back(this); } @@ -120,10 +116,7 @@ FeatureFunction::FeatureFunction(const std::string& description, size_t numScore m_description = dstream.str(); } - if (numScoreComponents != unlimited) { - ScoreComponentCollection::RegisterScoreProducer(this); - } - + ScoreComponentCollection::RegisterScoreProducer(this); m_producers.push_back(this); } diff --git a/moses/FeatureFunction.h b/moses/FeatureFunction.h index 864a37666..724eb27f4 100644 --- a/moses/FeatureFunction.h +++ b/moses/FeatureFunction.h @@ -99,15 +99,12 @@ public: virtual bool IsStateless() const = 0; virtual ~FeatureFunction(); - static const size_t unlimited; - static void ResetDescriptionCounts() { description_counts.clear(); } //! returns the number of scores that a subclass produces. //! For example, a language model conventionally produces 1, a translation table some arbitrary number, etc - //! sparse features returned unlimited size_t GetNumScoreComponents() const {return m_numScoreComponents;} //! returns a string description of this producer diff --git a/moses/GlobalLexicalModelUnlimited.cpp b/moses/GlobalLexicalModelUnlimited.cpp index 93639a292..474634fb4 100644 --- a/moses/GlobalLexicalModelUnlimited.cpp +++ b/moses/GlobalLexicalModelUnlimited.cpp @@ -10,7 +10,7 @@ using namespace std; namespace Moses { GlobalLexicalModelUnlimited::GlobalLexicalModelUnlimited(const std::string &line) -:StatelessFeatureFunction("glm",FeatureFunction::unlimited, line) +:StatelessFeatureFunction("glm", 0, line) { const vector<string> modelSpec = Tokenize(line); diff --git a/moses/Manager.cpp b/moses/Manager.cpp index ae916b7c2..88273c16a 100644 --- a/moses/Manager.cpp +++ b/moses/Manager.cpp @@ -754,7 +754,7 @@ void Manager::OutputFeatureValuesForHypergraph(const Hypothesis* hypo, std::ostr size_t Manager::OutputFeatureWeightsForSLF(size_t index, const FeatureFunction* ff, std::ostream &outputSearchGraphStream) const { size_t numScoreComps = ff->GetNumScoreComponents(); - if (numScoreComps != FeatureFunction::unlimited) { + if (numScoreComps != 0) { vector<float> values = StaticData::Instance().GetAllWeights().GetScoresForProducer(ff); for (size_t i = 0; i < numScoreComps; ++i) { outputSearchGraphStream << "# " << ff->GetScoreProducerDescription() diff --git a/moses/PhraseBoundaryFeature.cpp b/moses/PhraseBoundaryFeature.cpp index 24cf65fb4..96046642f 100644 --- a/moses/PhraseBoundaryFeature.cpp +++ b/moses/PhraseBoundaryFeature.cpp @@ -15,7 +15,7 @@ int PhraseBoundaryState::Compare(const FFState& other) const } PhraseBoundaryFeature::PhraseBoundaryFeature(const std::string &line) -: StatefulFeatureFunction("PhraseBoundaryFeature", FeatureFunction::unlimited, line) +: StatefulFeatureFunction("PhraseBoundaryFeature", 0, line) { std::cerr << "Initializing source word deletion feature.." << std::endl; diff --git a/moses/PhraseLengthFeature.cpp b/moses/PhraseLengthFeature.cpp index 62dc65924..bd70e1eae 100644 --- a/moses/PhraseLengthFeature.cpp +++ b/moses/PhraseLengthFeature.cpp @@ -9,7 +9,7 @@ namespace Moses { using namespace std; PhraseLengthFeature::PhraseLengthFeature(const std::string &line) -:StatelessFeatureFunction("pl", FeatureFunction::unlimited, line) +:StatelessFeatureFunction("pl", 0, line) { } diff --git a/moses/PhrasePairFeature.cpp b/moses/PhrasePairFeature.cpp index 92f3feccd..26743a7b6 100644 --- a/moses/PhrasePairFeature.cpp +++ b/moses/PhrasePairFeature.cpp @@ -12,7 +12,7 @@ using namespace std; namespace Moses { PhrasePairFeature::PhrasePairFeature(const std::string &line) -:StatelessFeatureFunction("PhrasePairFeature", FeatureFunction::unlimited, line) +:StatelessFeatureFunction("PhrasePairFeature", 0, line) { std::cerr << "Initializing PhrasePairFeature.." << std::endl; diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index d82377c45..bd926012d 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -19,7 +19,6 @@ ScoreComponentCollection::ScoreComponentCollection() : m_scores(s_denseVectorSiz void ScoreComponentCollection::RegisterScoreProducer (const FeatureFunction* scoreProducer) { - CHECK(scoreProducer->GetNumScoreComponents() != FeatureFunction::unlimited); size_t start = s_denseVectorSize; size_t end = start + scoreProducer->GetNumScoreComponents(); VERBOSE(1, "FeatureFunction: " << scoreProducer->GetScoreProducerDescription() << " start: " << start << " end: " << end << endl); @@ -27,14 +26,6 @@ void ScoreComponentCollection::RegisterScoreProducer s_denseVectorSize = end; } -void ScoreComponentCollection::UnregisterScoreProducer - (const FeatureFunction* scoreProducer) -{ - CHECK(scoreProducer->GetNumScoreComponents() != FeatureFunction::unlimited); - ScoreIndexMap::iterator iter = s_scoreIndexes.find(scoreProducer); - CHECK(iter != s_scoreIndexes.end()); - s_scoreIndexes.erase(iter); -} float ScoreComponentCollection::GetWeightedScore() const { @@ -62,7 +53,6 @@ void ScoreComponentCollection::MultiplyEquals(float scalar) // Multiply all weights of this sparse producer by a given scalar void ScoreComponentCollection::MultiplyEquals(const FeatureFunction* sp, float scalar) { - assert(sp->GetNumScoreComponents() == FeatureFunction::unlimited); std::string prefix = sp->GetScoreProducerDescription() + FName::SEP; for(FVector::FNVmap::const_iterator i = m_scores.cbegin(); i != m_scores.cend(); i++) { std::stringstream name; @@ -74,7 +64,6 @@ void ScoreComponentCollection::MultiplyEquals(const FeatureFunction* sp, float s // Count weights belonging to this sparse producer size_t ScoreComponentCollection::GetNumberWeights(const FeatureFunction* sp) { - assert(sp->GetNumScoreComponents() == FeatureFunction::unlimited); std::string prefix = sp->GetScoreProducerDescription() + FName::SEP; size_t weights = 0; for(FVector::FNVmap::const_iterator i = m_scores.cbegin(); i != m_scores.cend(); i++) { diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index 82d4d702a..9d781af54 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -106,7 +106,6 @@ public: * be allocated space in the dense part of the feature vector. **/ static void RegisterScoreProducer(const FeatureFunction* scoreProducer); - static void UnregisterScoreProducer(const FeatureFunction* scoreProducer); /** Load from file */ bool Load(const std::string& filename) @@ -194,7 +193,6 @@ public: //For features which have an unbounded number of components void MinusEquals(const FeatureFunction*sp, const std::string& name, float score) { - assert(sp->GetNumScoreComponents() == FeatureFunction::unlimited); FName fname(sp->GetScoreProducerDescription(),name); m_scores[fname] -= score; } @@ -242,7 +240,6 @@ public: //For features which have an unbounded number of components void PlusEquals(const FeatureFunction*sp, const std::string& name, float score) { - CHECK(sp->GetNumScoreComponents() == FeatureFunction::unlimited); FName fname(sp->GetScoreProducerDescription(),name); m_scores[fname] += score; } @@ -250,7 +247,6 @@ public: //For features which have an unbounded number of components void PlusEquals(const FeatureFunction*sp, const StringPiece& name, float score) { - CHECK(sp->GetNumScoreComponents() == FeatureFunction::unlimited); FName fname(sp->GetScoreProducerDescription(),name); m_scores[fname] += score; } @@ -289,7 +285,6 @@ public: //For features which have an unbounded number of components void Assign(const FeatureFunction*sp, const std::string name, float score) { - CHECK(sp->GetNumScoreComponents() == FeatureFunction::unlimited); FName fname(sp->GetScoreProducerDescription(),name); m_scores[fname] = score; } @@ -321,7 +316,8 @@ public: std::vector<float> GetScoresForProducer(const FeatureFunction* sp) const { size_t components = sp->GetNumScoreComponents(); - if (components == FeatureFunction::unlimited) return std::vector<float>(); + assert(components > 0); + std::vector<float> res(components); IndexPair indexes = GetIndexes(sp); for (size_t i = 0; i < res.size(); ++i) { @@ -386,7 +382,6 @@ public: float GetScoreForProducer (const FeatureFunction* sp, const std::string& name) const { - CHECK(sp->GetNumScoreComponents() == FeatureFunction::unlimited); FName fname(sp->GetScoreProducerDescription(),name); return m_scores[fname]; } diff --git a/moses/ScoreComponentCollectionTest.cpp b/moses/ScoreComponentCollectionTest.cpp index d951df695..71b85af9e 100644 --- a/moses/ScoreComponentCollectionTest.cpp +++ b/moses/ScoreComponentCollectionTest.cpp @@ -54,7 +54,7 @@ class MockMultiFeature : public MockStatelessFeatureFunction { class MockSparseFeature : public MockStatelessFeatureFunction { public: - MockSparseFeature(): MockStatelessFeatureFunction("MockSparse", FeatureFunction::unlimited, "MockSparse") {} + MockSparseFeature(): MockStatelessFeatureFunction("MockSparse", 0, "MockSparse") {} }; diff --git a/moses/SourceWordDeletionFeature.cpp b/moses/SourceWordDeletionFeature.cpp index 0bc3e4950..6d2a0ab6b 100644 --- a/moses/SourceWordDeletionFeature.cpp +++ b/moses/SourceWordDeletionFeature.cpp @@ -15,7 +15,7 @@ namespace Moses { using namespace std; SourceWordDeletionFeature::SourceWordDeletionFeature(const std::string &line) -:StatelessFeatureFunction("SourceWordDeletionFeature", FeatureFunction::unlimited, line), +:StatelessFeatureFunction("SourceWordDeletionFeature", 0, line), m_unrestricted(true) { std::cerr << "Initializing source word deletion feature.." << std::endl; diff --git a/moses/TargetBigramFeature.cpp b/moses/TargetBigramFeature.cpp index 9f5cab34c..af77c2e17 100644 --- a/moses/TargetBigramFeature.cpp +++ b/moses/TargetBigramFeature.cpp @@ -15,7 +15,7 @@ int TargetBigramState::Compare(const FFState& other) const { } TargetBigramFeature::TargetBigramFeature(const std::string &line) -:StatefulFeatureFunction("TargetBigramFeature", FeatureFunction::unlimited, line) +:StatefulFeatureFunction("TargetBigramFeature", 0, line) { std::cerr << "Initializing target bigram feature.." << std::endl; diff --git a/moses/TargetNgramFeature.cpp b/moses/TargetNgramFeature.cpp index 913a8d132..c448456be 100644 --- a/moses/TargetNgramFeature.cpp +++ b/moses/TargetNgramFeature.cpp @@ -38,7 +38,7 @@ int TargetNgramState::Compare(const FFState& other) const { } TargetNgramFeature::TargetNgramFeature(const std::string &line) -:StatefulFeatureFunction("TargetNgramFeature", FeatureFunction::unlimited, line) +:StatefulFeatureFunction("TargetNgramFeature", 0, line) ,m_sparseProducerWeight(1) { std::cerr << "Initializing target ngram feature.." << std::endl; diff --git a/moses/TargetWordInsertionFeature.cpp b/moses/TargetWordInsertionFeature.cpp index 012727d67..edf120f81 100644 --- a/moses/TargetWordInsertionFeature.cpp +++ b/moses/TargetWordInsertionFeature.cpp @@ -14,7 +14,7 @@ namespace Moses { using namespace std; TargetWordInsertionFeature::TargetWordInsertionFeature(const std::string &line) -:StatelessFeatureFunction("TargetWordInsertionFeature", FeatureFunction::unlimited, line), +:StatelessFeatureFunction("TargetWordInsertionFeature", 0, line), m_unrestricted(true) { std::cerr << "Initializing target word insertion feature.." << std::endl; diff --git a/moses/WordTranslationFeature.cpp b/moses/WordTranslationFeature.cpp index 871890701..2af3475ea 100644 --- a/moses/WordTranslationFeature.cpp +++ b/moses/WordTranslationFeature.cpp @@ -15,7 +15,7 @@ namespace Moses { using namespace std; WordTranslationFeature::WordTranslationFeature(const std::string &line) -:StatelessFeatureFunction("WordTranslationFeature", FeatureFunction::unlimited, line) +:StatelessFeatureFunction("WordTranslationFeature", 0, line) ,m_unrestricted(true) ,m_sparseProducerWeight(1) ,m_simple(true) |