mosesdecoder/contrib/other-builds/moses2/Weights.cpp

70 lines
1.4 KiB
C++
Raw Normal View History

2015-10-24 16:36:30 +03:00
/*
* Weights.cpp
*
* Created on: 24 Oct 2015
* Author: hieu
*/
2015-10-27 20:35:42 +03:00
#include <cassert>
#include <string>
#include <vector>
2015-10-29 21:15:12 +03:00
#include "FeatureFunction.h"
2015-10-27 20:35:42 +03:00
#include "FeatureFunctions.h"
2015-10-24 16:36:30 +03:00
#include "Weights.h"
2015-10-27 20:35:42 +03:00
#include "moses/Util.h"
using namespace std;
2015-10-24 16:36:30 +03:00
2015-10-29 21:15:12 +03:00
Weights::Weights()
{
2015-10-24 16:36:30 +03:00
// TODO Auto-generated constructor stub
}
Weights::~Weights() {
// TODO Auto-generated destructor stub
}
2015-10-29 21:15:12 +03:00
void Weights::Init(const FeatureFunctions &ffs)
{
size_t totalNumScores = ffs.GetNumScores();
2015-10-30 18:58:02 +03:00
//cerr << "totalNumScores=" << totalNumScores << endl;
2015-10-29 21:15:12 +03:00
m_weights.resize(totalNumScores, 1);
}
void Weights::Debug(std::ostream &out, const FeatureFunctions &ffs) const
{
size_t numScores = ffs.GetNumScores();
for (size_t i = 0; i < numScores; ++i) {
out << m_weights[i] << " ";
}
}
2015-10-26 19:32:47 +03:00
std::ostream& operator<<(std::ostream &out, const Weights &obj)
{
return out;
}
2015-10-27 20:35:42 +03:00
void Weights::CreateFromString(const FeatureFunctions &ffs, const std::string &line)
{
std::vector<std::string> toks = Moses::Tokenize(line);
assert(toks.size());
string ffName = toks[0];
assert(ffName.back() == '=');
ffName = ffName.substr(0, ffName.size() - 1);
2015-10-30 18:58:02 +03:00
//cerr << "ffName=" << ffName << endl;
2015-10-27 20:35:42 +03:00
2015-10-29 21:15:12 +03:00
const FeatureFunction &ff = ffs.FindFeatureFunction(ffName);
size_t startInd = ff.GetStartInd();
size_t numScores = ff.GetNumScores();
assert(numScores == toks.size() -1);
2015-10-27 20:35:42 +03:00
2015-10-29 21:15:12 +03:00
for (size_t i = 0; i < numScores; ++i) {
SCORE score = Moses::Scan<SCORE>(toks[i+1]);
m_weights[i + startInd] = score;
}
2015-10-27 20:35:42 +03:00
}