diff options
author | Ulrich Germann <ugermann@inf.ed.ac.uk> | 2013-09-10 15:07:12 +0400 |
---|---|---|
committer | Ulrich Germann <ugermann@inf.ed.ac.uk> | 2013-09-10 15:07:12 +0400 |
commit | 52bb3bdf5aeaadba612a350d525201e55b6bf368 (patch) | |
tree | 4340e3bbeee949668407c913f9aa82e897d7bdc0 /moses/ScoreComponentCollection.cpp | |
parent | 6592265548749bd083518182f2d3bbb40404e0b9 (diff) | |
parent | 5cca6fafcbf903dc4abcfc86ae83299171633c9d (diff) |
Merge branch 'master' of github.com:moses-smt/mosesdecoder
Diffstat (limited to 'moses/ScoreComponentCollection.cpp')
-rw-r--r-- | moses/ScoreComponentCollection.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index 97ae2684d..7cd9be701 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -8,6 +8,27 @@ using namespace std; namespace Moses { +void ScorePair::PlusEquals(const ScorePair &other) +{ + PlusEquals(other.denseScores); + std::map<StringPiece, float>::const_iterator iter; + for (iter = other.sparseScores.begin(); iter != other.sparseScores.end(); ++iter) { + PlusEquals(iter->first, iter->second); + } +} + +void ScorePair::PlusEquals(const StringPiece &key, float value) +{ + std::map<StringPiece, float>::iterator iter; + iter = sparseScores.find(key); + if (iter == sparseScores.end()) { + sparseScores[key] = value; + } + else { + float &existingval = iter->second; + existingval += value; + } +} ScoreComponentCollection::ScoreIndexMap ScoreComponentCollection::s_scoreIndexes; size_t ScoreComponentCollection::s_denseVectorSize = 0; @@ -220,6 +241,18 @@ FVector ScoreComponentCollection::GetVectorForProducer(const FeatureFunction* sp return fv; } +void ScoreComponentCollection::PlusEquals(const FeatureFunction* sp, const ScorePair &scorePair) +{ + PlusEquals(sp, scorePair.denseScores); + + std::map<StringPiece, float>::const_iterator iter; + for (iter = scorePair.sparseScores.begin(); iter != scorePair.sparseScores.end(); ++iter) { + const StringPiece &key = iter->first; + float value = iter->second; + PlusEquals(sp, key, value); + } +} + } |