2015-10-23 20:33:12 +03:00
|
|
|
/*
|
2015-10-26 00:20:55 +03:00
|
|
|
* System.cpp
|
2015-10-23 20:33:12 +03:00
|
|
|
*
|
|
|
|
* Created on: 23 Oct 2015
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
2015-10-27 18:46:37 +03:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <boost/foreach.hpp>
|
2015-10-26 00:20:55 +03:00
|
|
|
#include "System.h"
|
2015-11-03 16:24:39 +03:00
|
|
|
#include "FF/FeatureFunction.h"
|
2015-11-04 16:09:53 +03:00
|
|
|
#include "TranslationModel/UnknownWordPenalty.h"
|
2015-10-24 04:02:50 +03:00
|
|
|
#include "moses/Util.h"
|
2015-10-27 18:46:37 +03:00
|
|
|
#include "util/exception.hh"
|
|
|
|
|
|
|
|
using namespace std;
|
2015-10-23 20:33:12 +03:00
|
|
|
|
2015-10-27 18:46:37 +03:00
|
|
|
System::System(const Moses::Parameter ¶ms)
|
2015-10-27 19:54:15 +03:00
|
|
|
:m_featureFunctions(*this)
|
2015-10-27 18:46:37 +03:00
|
|
|
,m_params(params)
|
|
|
|
{
|
2015-11-04 20:23:04 +03:00
|
|
|
params.SetParameter(stackSize, "stack", Moses::DEFAULT_MAX_HYPOSTACK_SIZE);
|
|
|
|
|
2015-10-29 21:15:12 +03:00
|
|
|
m_featureFunctions.Create();
|
2015-10-27 19:54:15 +03:00
|
|
|
LoadWeights();
|
2015-10-29 21:15:12 +03:00
|
|
|
m_featureFunctions.Load();
|
2015-10-31 05:45:01 +03:00
|
|
|
LoadMappings();
|
2015-10-27 18:46:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
System::~System() {
|
|
|
|
}
|
|
|
|
|
2015-10-27 19:54:15 +03:00
|
|
|
void System::LoadWeights()
|
2015-10-24 14:39:15 +03:00
|
|
|
{
|
2015-10-31 05:45:01 +03:00
|
|
|
const Moses::PARAM_VEC *params = m_params.GetParam("weight");
|
|
|
|
UTIL_THROW_IF2(params == NULL, "Must have [weight] section");
|
2015-10-27 18:46:37 +03:00
|
|
|
|
2015-10-29 21:15:12 +03:00
|
|
|
m_weights.Init(m_featureFunctions);
|
2015-10-31 05:45:01 +03:00
|
|
|
BOOST_FOREACH(const std::string &line, *params) {
|
2015-10-27 20:35:42 +03:00
|
|
|
m_weights.CreateFromString(m_featureFunctions, line);
|
2015-10-27 18:46:37 +03:00
|
|
|
}
|
2015-10-27 19:54:15 +03:00
|
|
|
}
|
2015-10-27 18:46:37 +03:00
|
|
|
|
2015-10-31 05:45:01 +03:00
|
|
|
void System::LoadMappings()
|
|
|
|
{
|
|
|
|
const Moses::PARAM_VEC *params = m_params.GetParam("mapping");
|
|
|
|
UTIL_THROW_IF2(params == NULL, "Must have [mapping] section");
|
|
|
|
|
|
|
|
BOOST_FOREACH(const std::string &line, *params) {
|
|
|
|
vector<string> toks = Moses::Tokenize(line);
|
|
|
|
assert(toks.size() == 2);
|
|
|
|
assert(toks[0] == "T");
|
|
|
|
size_t ptInd = Moses::Scan<size_t>(toks[1]);
|
|
|
|
const PhraseTable *pt = m_featureFunctions.GetPhraseTablesExcludeUnknownWordPenalty(ptInd);
|
|
|
|
m_mappings.push_back(pt);
|
|
|
|
}
|
2015-10-27 18:46:37 +03:00
|
|
|
|
2015-10-31 05:45:01 +03:00
|
|
|
// unk pt
|
|
|
|
const UnknownWordPenalty &unkWP = dynamic_cast<const UnknownWordPenalty&>(m_featureFunctions.FindFeatureFunction("UnknownWordPenalty0"));
|
|
|
|
m_mappings.push_back(&unkWP);
|
|
|
|
|
|
|
|
}
|
2015-10-24 15:19:42 +03:00
|
|
|
|