2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#include "ScoreComponentCollection.h"
|
|
|
|
#include "StaticData.h"
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2008-06-11 14:52:57 +04:00
|
|
|
ScoreComponentCollection::ScoreComponentCollection()
|
2010-09-15 21:27:37 +04:00
|
|
|
: m_scores(StaticData::Instance().GetTotalScoreComponents(), 0.0f)
|
2008-06-11 14:52:57 +04:00
|
|
|
, m_sim(&StaticData::Instance().GetScoreIndexManager())
|
|
|
|
{}
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
float ScoreComponentCollection::GetWeightedScore() const
|
|
|
|
{
|
|
|
|
float ret = InnerProduct(StaticData::Instance().GetAllWeights());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
void ScoreComponentCollection::ZeroAllLM(const LMList& lmList)
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t ind = lmList.GetMinIndex(); ind <= lmList.GetMaxIndex(); ++ind)
|
|
|
|
{
|
2010-09-15 20:30:52 +04:00
|
|
|
m_scores[m_sim->GetFeatureName(ind)] = 0;
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
void ScoreComponentCollection::PlusEqualsAllLM(const LMList& lmList, const ScoreComponentCollection& rhs)
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t ind = lmList.GetMinIndex(); ind <= lmList.GetMaxIndex(); ++ind)
|
|
|
|
{
|
2010-09-15 20:30:52 +04:00
|
|
|
m_scores[m_sim->GetFeatureName(ind)] += rhs.m_scores[m_sim->GetFeatureName(ind)];
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-09-16 13:54:13 +04:00
|
|
|
|
|
|
|
void ScoreComponentCollection::PlusEquals(const ScoreProducer* sp, const std::vector<float>& scores)
|
|
|
|
{
|
|
|
|
assert(scores.size() == sp->GetNumScoreComponents());
|
|
|
|
size_t i = m_sim->GetBeginIndex(sp->GetScoreBookkeepingID());
|
|
|
|
for (std::vector<float>::const_iterator vi = scores.begin();
|
|
|
|
vi != scores.end(); ++vi)
|
|
|
|
{
|
|
|
|
const std::string &name = m_sim->GetFeatureName(i++);
|
|
|
|
m_scores[name] += *vi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-16 11:06:42 +04:00
|
|
|
std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection& rhs)
|
|
|
|
{
|
|
|
|
os << "<<" << rhs.m_scores[rhs.m_sim->GetFeatureName(0)];
|
|
|
|
for (size_t i=1; i<rhs.m_scores.size(); i++)
|
|
|
|
os << ", " << rhs.m_scores[rhs.m_sim->GetFeatureName(i)];
|
|
|
|
return os << ">>";
|
|
|
|
}
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|