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-11-03 16:24:39 +03:00
|
|
|
#include "FF/FeatureFunction.h"
|
|
|
|
#include "FF/FeatureFunctions.h"
|
2015-10-24 16:36:30 +03:00
|
|
|
#include "Weights.h"
|
2015-11-11 19:23:49 +03:00
|
|
|
#include "legacy/Util2.h"
|
2015-10-27 20:35:42 +03:00
|
|
|
|
|
|
|
using namespace std;
|
2015-10-24 16:36:30 +03:00
|
|
|
|
2015-12-10 23:49:30 +03:00
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
{
|
2015-11-12 02:28:18 +03:00
|
|
|
std::vector<std::string> toks = Tokenize(line);
|
2015-10-27 20:35:42 +03:00
|
|
|
assert(toks.size());
|
|
|
|
|
|
|
|
string ffName = toks[0];
|
2015-11-27 22:53:08 +03:00
|
|
|
assert(ffName[ffName.size() - 1] == '=');
|
2015-10-27 20:35:42 +03:00
|
|
|
|
|
|
|
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-12-07 21:16:51 +03:00
|
|
|
const FeatureFunction *ff = ffs.FindFeatureFunction(ffName);
|
|
|
|
assert(ff);
|
|
|
|
size_t startInd = ff->GetStartInd();
|
|
|
|
size_t numScores = ff->GetNumScores();
|
2015-10-29 21:15:12 +03:00
|
|
|
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) {
|
2015-11-12 02:29:58 +03:00
|
|
|
SCORE score = Scan<SCORE>(toks[i+1]);
|
2015-10-29 21:15:12 +03:00
|
|
|
m_weights[i + startInd] = score;
|
|
|
|
}
|
2015-10-27 20:35:42 +03:00
|
|
|
}
|
2015-12-10 23:49:30 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|