diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2013-09-08 18:43:18 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2013-09-08 18:43:18 +0400 |
commit | 7214be82d45dbb2f113e3f0aec25b25d9cd76632 (patch) | |
tree | b35fc778412e62af40421156faf2f2ff27f79983 /moses | |
parent | 1adf7d05214526e98e8c6c31b090fbd3b485e4d4 (diff) |
lattice decoding with sparse features
Diffstat (limited to 'moses')
-rw-r--r-- | moses/ScoreComponentCollection.cpp | 21 | ||||
-rw-r--r-- | moses/ScoreComponentCollection.h | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index c9b4d1ea0..d3c31d625 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<std::string, float>::const_iterator iter; + for (iter = other.sparseScores.begin(); iter != other.sparseScores.end(); ++iter) { + PlusEquals(iter->first, iter->second); + } +} + +void ScorePair::PlusEquals(const std::string &key, float value) +{ + std::map<std::string, 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; diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index c683dd822..b3620fd94 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -49,6 +49,9 @@ struct ScorePair std::vector<float> denseScores; std::map<std::string, float> sparseScores; + void PlusEquals(const ScorePair &other); + void PlusEquals(const std::string &key, float value); + void PlusEquals(const std::vector<float> &other) { CHECK(denseScores.size() == other.size()); |