diff --git a/contrib/other-builds/moses2/Scores.cpp b/contrib/other-builds/moses2/Scores.cpp index df866accb..39287cc0d 100644 --- a/contrib/other-builds/moses2/Scores.cpp +++ b/contrib/other-builds/moses2/Scores.cpp @@ -95,6 +95,26 @@ void Scores::PlusEquals(const System &system, } } +void Scores::PlusEquals(const System &system, + const FeatureFunction &featureFunction, + const Vector &scores) +{ + assert(scores.size() == featureFunction.GetNumScores()); + + const Weights &weights = system.weights; + + size_t ffStartInd = featureFunction.GetStartInd(); + for (size_t i = 0; i < scores.size(); ++i) { + SCORE incrScore = scores[i]; + if (m_scores) { + m_scores[ffStartInd + i] += incrScore; + } + //cerr << "ffStartInd=" << ffStartInd << " " << i << endl; + SCORE weight = weights[ffStartInd + i]; + m_total += incrScore * weight; + } +} + void Scores::PlusEquals(const System &system, const Scores &other) { size_t numScores = system.featureFunctions.GetNumScores(); diff --git a/contrib/other-builds/moses2/Scores.h b/contrib/other-builds/moses2/Scores.h index 8f25237c2..e9c8cef97 100644 --- a/contrib/other-builds/moses2/Scores.h +++ b/contrib/other-builds/moses2/Scores.h @@ -10,6 +10,7 @@ #include #include "TypeDef.h" #include "MemPool.h" +#include "Vector.h" namespace Moses2 { @@ -43,6 +44,10 @@ public: const FeatureFunction &featureFunction, const std::vector &scores); + void PlusEquals(const System &system, + const FeatureFunction &featureFunction, + const Vector &scores); + void PlusEquals(const System &system, const Scores &scores); diff --git a/contrib/other-builds/moses2/TranslationModel/ProbingPT.cpp b/contrib/other-builds/moses2/TranslationModel/ProbingPT.cpp index 9fa2fcfce..33311fdd7 100644 --- a/contrib/other-builds/moses2/TranslationModel/ProbingPT.cpp +++ b/contrib/other-builds/moses2/TranslationModel/ProbingPT.cpp @@ -156,7 +156,7 @@ TargetPhrase *ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system, } // score for this phrase table - vector scores = probingTargetPhrase.prob; + Vector scores(pool, probingTargetPhrase.prob); std::transform(scores.begin(), scores.end(), scores.begin(), TransformScore); tp->GetScores().PlusEquals(system, *this, scores); diff --git a/contrib/other-builds/moses2/Vector.h b/contrib/other-builds/moses2/Vector.h index 5dcc24ab0..867f26064 100644 --- a/contrib/other-builds/moses2/Vector.h +++ b/contrib/other-builds/moses2/Vector.h @@ -35,6 +35,16 @@ public: m_arr = pool.Allocate(size); } + Vector(MemPool &pool, const std::vector &vec) + :m_size(vec.size()) + ,m_maxSize(vec.size()) + { + m_arr = pool.Allocate(m_size); + for (size_t i = 0; i < m_size; ++i) { + m_arr[i] = vec[i]; + } + } + virtual ~Vector() {