From f379e5cb8a1d7e04072b4931b4f852b9a8ceb979 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 10 Sep 2013 15:36:21 +0200 Subject: lattice decoding with sparse features --- moses/ScoreComponentCollection.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'moses/ScoreComponentCollection.cpp') diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index 7cd9be701..0ce50d992 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -1,6 +1,6 @@ // $Id$ #include - +#include "util/exception.hh" #include "ScoreComponentCollection.h" #include "StaticData.h" @@ -30,6 +30,20 @@ void ScorePair::PlusEquals(const StringPiece &key, float value) } } +std::ostream& operator<<(std::ostream& os, const ScorePair& rhs) +{ + for (size_t i = 0; i < rhs.denseScores.size(); ++i) { + os << rhs.denseScores[i] << ","; + } + + std::map::const_iterator iter; + for (iter = rhs.sparseScores.begin(); iter != rhs.sparseScores.end(); ++iter) { + os << iter->first << "=" << iter->second << ","; + } + + return os; +} + ScoreComponentCollection::ScoreIndexMap ScoreComponentCollection::s_scoreIndexes; size_t ScoreComponentCollection::s_denseVectorSize = 0; @@ -206,6 +220,21 @@ void ScoreComponentCollection::Assign(const FeatureFunction* sp, const string li } } +void ScoreComponentCollection::Assign(const FeatureFunction* sp, const std::vector& scores) { + IndexPair indexes = GetIndexes(sp); + size_t numScores = indexes.second - indexes.first; + + if (scores.size() != numScores) { + UTIL_THROW(util::Exception, "Feature function " << sp->GetScoreProducerDescription() << " specified " + << numScores << " dense scores or weights. Actually has " << scores.size()); + } + + for (size_t i = 0; i < scores.size(); ++i) { + m_scores[i + indexes.first] = scores[i]; + } +} + + void ScoreComponentCollection::InvertDenseFeatures(const FeatureFunction* sp) { -- cgit v1.2.3