/* * System.cpp * * Created on: 23 Oct 2015 * Author: hieu */ #include #include #include #include "System.h" #include "FF/FeatureFunction.h" #include "TranslationModel/UnknownWordPenalty.h" #include "moses/Util.h" #include "util/exception.hh" using namespace std; System::System(const Moses::Parameter ¶ms) :m_featureFunctions(*this) ,m_params(params) { params.SetParameter(stackSize, "stack", Moses::DEFAULT_MAX_HYPOSTACK_SIZE); m_featureFunctions.Create(); LoadWeights(); m_featureFunctions.Load(); LoadMappings(); } System::~System() { } void System::LoadWeights() { const Moses::PARAM_VEC *params = m_params.GetParam("weight"); UTIL_THROW_IF2(params == NULL, "Must have [weight] section"); m_weights.Init(m_featureFunctions); BOOST_FOREACH(const std::string &line, *params) { m_weights.CreateFromString(m_featureFunctions, line); } } 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 toks = Moses::Tokenize(line); assert(toks.size() == 2); assert(toks[0] == "T"); size_t ptInd = Moses::Scan(toks[1]); const PhraseTable *pt = m_featureFunctions.GetPhraseTablesExcludeUnknownWordPenalty(ptInd); m_mappings.push_back(pt); } // unk pt const UnknownWordPenalty &unkWP = dynamic_cast(m_featureFunctions.FindFeatureFunction("UnknownWordPenalty0")); m_mappings.push_back(&unkWP); }