Merge ../mosesdecoder into perf_moses2

This commit is contained in:
Hieu Hoang 2015-12-11 17:29:10 +00:00
commit e5d3306519
261 changed files with 1985 additions and 2460 deletions

View File

@ -12,9 +12,9 @@ else
with-xmlrpc-c = [ option.get "with-xmlrpc-c" ] ;
if $(with-xmlrpc-c) {
echo While building mosesserver ... ;
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ;
echo "!!! You are linking the XMLRPC-C library; Must be v.1.32 (September 2012) or higher !!!" ;
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ;
# echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ;
# echo "!!! You are linking the XMLRPC-C library; Must be v.1.32 (September 2012) or higher !!!" ;
# echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ;
build-moses-server = true ;
xmlrpc-command = $(with-xmlrpc-c)/bin/xmlrpc-c-config ;

View File

@ -1,13 +1,5 @@
#if 1
#include "moses/ExportInterface.h"
// The separate moses server executable is being phased out.
// Since there were problems with the migration into the main
// executable, this separate program is still included in the
// distribution for legacy reasons. Contributors are encouraged
// to add their contributions to moses/server rather than
// contrib/server. This recommendation does not apply to wrapper
// scripts.
// The future is this:
// The separate moses server executable has been phased out.
/** main function of the command line version of the decoder **/
int main(int argc, char const** argv)
@ -25,747 +17,3 @@ int main(int argc, char const** argv)
argv2[argc] = "--server";
return decoder_main(argc+1, argv2);
}
#else
// #include <stdexcept>
// #include <iostream>
// #include <vector>
// #include <algorithm>
// #include "moses/Util.h"
// #include "moses/ChartManager.h"
// #include "moses/Hypothesis.h"
// #include "moses/Manager.h"
// #include "moses/StaticData.h"
// #include "moses/ThreadPool.h"
// #include "moses/TranslationTask.h"
// #include "moses/TranslationModel/PhraseDictionaryMultiModelCounts.h"
// #include "moses/FF/StatefulFeatureFunction.h"
// #if PT_UG
// #include "moses/TranslationModel/UG/mmsapt.h"
// #endif
// #include "moses/TreeInput.h"
// #include "moses/IOWrapper.h"
// #include <boost/foreach.hpp>
// #ifdef WITH_THREADS
// #include <boost/thread.hpp>
// #endif
// #include <xmlrpc-c/base.hpp>
// #include <xmlrpc-c/registry.hpp>
// #include <xmlrpc-c/server_abyss.hpp>
// // using namespace Moses;
// using namespace std;
// using namespace Moses;
// typedef std::map<std::string, xmlrpc_c::value> params_t;
// class Updater: public xmlrpc_c::method
// {
// public:
// Updater() {
// // signature and help strings are documentation -- the client
// // can query this information with a system.methodSignature and
// // system.methodHelp RPC.
// this->_signature = "S:S";
// this->_help = "Updates stuff";
// }
// void
// execute(xmlrpc_c::paramList const& paramList,
// xmlrpc_c::value * const retvalP) {
// const params_t params = paramList.getStruct(0);
// breakOutParams(params);
// #if PT_UG
// Mmsapt* pdsa = reinterpret_cast<Mmsapt*>(PhraseDictionary::GetColl()[0]);
// pdsa->add(source_,target_,alignment_);
// #else
// std::string msg;
// msg = "Server was compiled without a phrase table implementation that ";
// msg += "supports updates.";
// throw xmlrpc_c::fault(msg.c_str(), xmlrpc_c::fault::CODE_PARSE);
// #endif
// XVERBOSE(1,"Done inserting\n");
// *retvalP = xmlrpc_c::value_string("Phrase table updated");
// }
// string source_, target_, alignment_;
// bool bounded_;
// void breakOutParams(const params_t& params) {
// params_t::const_iterator si = params.find("source");
// if(si == params.end())
// throw xmlrpc_c::fault("Missing source sentence", xmlrpc_c::fault::CODE_PARSE);
// source_ = xmlrpc_c::value_string(si->second);
// XVERBOSE(1,"source = " << source_ << endl);
// si = params.find("target");
// if(si == params.end())
// throw xmlrpc_c::fault("Missing target sentence", xmlrpc_c::fault::CODE_PARSE);
// target_ = xmlrpc_c::value_string(si->second);
// XVERBOSE(1,"target = " << target_ << endl);
// si = params.find("alignment");
// if(si == params.end())
// throw xmlrpc_c::fault("Missing alignment", xmlrpc_c::fault::CODE_PARSE);
// alignment_ = xmlrpc_c::value_string(si->second);
// XVERBOSE(1,"alignment = " << alignment_ << endl);
// si = params.find("bounded");
// bounded_ = (si != params.end());
// }
// };
// class Optimizer : public xmlrpc_c::method
// {
// public:
// Optimizer() {
// // signature and help strings are documentation -- the client
// // can query this information with a system.methodSignature and
// // system.methodHelp RPC.
// this->_signature = "S:S";
// this->_help = "Optimizes multi-model translation model";
// }
// void
// execute(xmlrpc_c::paramList const& paramList,
// xmlrpc_c::value * const retvalP) {
// #ifdef WITH_DLIB
// const params_t params = paramList.getStruct(0);
// params_t::const_iterator si = params.find("model_name");
// if (si == params.end()) {
// throw xmlrpc_c::fault(
// "Missing name of model to be optimized (e.g. PhraseDictionaryMultiModelCounts0)",
// xmlrpc_c::fault::CODE_PARSE);
// }
// const string model_name = xmlrpc_c::value_string(si->second);
// PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name);
// si = params.find("phrase_pairs");
// if (si == params.end()) {
// throw xmlrpc_c::fault(
// "Missing list of phrase pairs",
// xmlrpc_c::fault::CODE_PARSE);
// }
// vector<pair<string, string> > phrase_pairs;
// xmlrpc_c::value_array phrase_pairs_array = xmlrpc_c::value_array(si->second);
// vector<xmlrpc_c::value> phrasePairValueVector(phrase_pairs_array.vectorValueValue());
// for (size_t i=0;i < phrasePairValueVector.size();i++) {
// xmlrpc_c::value_array phrasePairArray = xmlrpc_c::value_array(phrasePairValueVector[i]);
// vector<xmlrpc_c::value> phrasePair(phrasePairArray.vectorValueValue());
// string L1 = xmlrpc_c::value_string(phrasePair[0]);
// string L2 = xmlrpc_c::value_string(phrasePair[1]);
// phrase_pairs.push_back(make_pair(L1,L2));
// }
// vector<float> weight_vector;
// weight_vector = pdmm->MinimizePerplexity(phrase_pairs);
// vector<xmlrpc_c::value> weight_vector_ret;
// for (size_t i=0;i < weight_vector.size();i++) {
// weight_vector_ret.push_back(xmlrpc_c::value_double(weight_vector[i]));
// }
// *retvalP = xmlrpc_c::value_array(weight_vector_ret);
// #else
// string errmsg = "Error: Perplexity minimization requires dlib (compilation option --with-dlib)";
// cerr << errmsg << endl;
// *retvalP = xmlrpc_c::value_string(errmsg);
// #endif
// }
// };
// /**
// * Required so that translations can be sent to a thread pool.
// **/
// class TranslationTask : public virtual Moses::TranslationTask {
// protected:
// TranslationTask(xmlrpc_c::paramList const& paramList,
// boost::condition_variable& cond, boost::mutex& mut)
// : m_paramList(paramList),
// m_cond(cond),
// m_mut(mut),
// m_done(false)
// {}
// public:
// static boost::shared_ptr<TranslationTask>
// create(xmlrpc_c::paramList const& paramList,
// boost::condition_variable& cond, boost::mutex& mut)
// {
// boost::shared_ptr<TranslationTask> ret(new TranslationTask(paramList, cond, mut));
// ret->m_self = ret;
// return ret;
// }
// virtual bool DeleteAfterExecution() {return false;}
// bool IsDone() const {return m_done;}
// const map<string, xmlrpc_c::value>& GetRetData() { return m_retData;}
// virtual void
// Run()
// {
// using namespace xmlrpc_c;
// const params_t params = m_paramList.getStruct(0);
// m_paramList.verifyEnd(1);
// params_t::const_iterator si = params.find("text");
// if (si == params.end()) {
// throw fault("Missing source text", fault::CODE_PARSE);
// }
// const string source = value_string(si->second);
// XVERBOSE(1,"Input: " << source << endl);
// si = params.find("align");
// bool addAlignInfo = (si != params.end());
// si = params.find("word-align");
// bool addWordAlignInfo = (si != params.end());
// si = params.find("sg");
// bool addGraphInfo = (si != params.end());
// si = params.find("topt");
// bool addTopts = (si != params.end());
// si = params.find("report-all-factors");
// bool reportAllFactors = (si != params.end());
// si = params.find("nbest");
// int nbest_size = (si == params.end()) ? 0 : int(value_int(si->second));
// si = params.find("nbest-distinct");
// bool nbest_distinct = (si != params.end());
// si = params.find("add-score-breakdown");
// bool addScoreBreakdown = (si != params.end());
// vector<float> multiModelWeights;
// si = params.find("lambda");
// if (si != params.end())
// {
// value_array multiModelArray = value_array(si->second);
// vector<value> multiModelValueVector(multiModelArray.vectorValueValue());
// for (size_t i=0;i < multiModelValueVector.size();i++)
// {
// multiModelWeights.push_back(value_double(multiModelValueVector[i]));
// }
// }
// si = params.find("model_name");
// if (si != params.end() && multiModelWeights.size() > 0)
// {
// const string model_name = value_string(si->second);
// PhraseDictionaryMultiModel* pdmm
// = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name);
// pdmm->SetTemporaryMultiModelWeightsVector(multiModelWeights);
// }
// const StaticData &staticData = StaticData::Instance();
// //Make sure alternative paths are retained, if necessary
// // if (addGraphInfo || nbest_size>0) {
// // (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(true);
// // }
// stringstream out, graphInfo, transCollOpts;
// if (staticData.IsSyntax())
// {
// boost::shared_ptr<TreeInput> tinput(new TreeInput);
// const vector<FactorType>& IFO = staticData.GetInputFactorOrder();
// istringstream in(source + "\n");
// tinput->Read(in,IFO,staticData.options());
// ttasksptr task = Moses::TranslationTask::create(tinput);
// ChartManager manager(task);
// manager.Decode();
// const ChartHypothesis *hypo = manager.GetBestHypothesis();
// outputChartHypo(out,hypo);
// if (addGraphInfo) {
// // const size_t translationId = tinput.GetTranslationId();
// std::ostringstream sgstream;
// manager.OutputSearchGraphMoses(sgstream);
// m_retData["sg"] = value_string(sgstream.str());
// }
// }
// else
// {
// // size_t lineNumber = 0; // TODO: Include sentence request number here?
// boost::shared_ptr<Sentence> sentence;
// sentence.reset(new Sentence(0,source,staticData.options()));
// ttasksptr task = Moses::TranslationTask::create(sentence);
// Manager manager(task);
// manager.Decode();
// const Hypothesis* hypo = manager.GetBestHypothesis();
// vector<xmlrpc_c::value> alignInfo;
// outputHypo(out,hypo,addAlignInfo,alignInfo,reportAllFactors);
// if (addAlignInfo) m_retData["align"] = value_array(alignInfo);
// if (addWordAlignInfo)
// {
// stringstream wordAlignment;
// hypo->OutputAlignment(wordAlignment);
// vector<xmlrpc_c::value> alignments;
// string alignmentPair;
// while (wordAlignment >> alignmentPair)
// {
// int pos = alignmentPair.find('-');
// map<string, xmlrpc_c::value> wordAlignInfo;
// wordAlignInfo["source-word"]
// = value_int(atoi(alignmentPair.substr(0, pos).c_str()));
// wordAlignInfo["target-word"]
// = value_int(atoi(alignmentPair.substr(pos + 1).c_str()));
// alignments.push_back(value_struct(wordAlignInfo));
// }
// m_retData["word-align"] = value_array(alignments);
// }
// if (addGraphInfo) insertGraphInfo(manager,m_retData);
// if (addTopts) insertTranslationOptions(manager,m_retData);
// if (nbest_size > 0)
// {
// outputNBest(manager, m_retData, nbest_size, nbest_distinct,
// reportAllFactors, addAlignInfo, addScoreBreakdown);
// }
// // (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(false);
// }
// m_retData["text"] = value_string(out.str());
// XVERBOSE(1,"Output: " << out.str() << endl);
// {
// boost::lock_guard<boost::mutex> lock(m_mut);
// m_done = true;
// }
// m_cond.notify_one();
// }
// void outputHypo(ostream& out, const Hypothesis* hypo,
// bool addAlignmentInfo, vector<xmlrpc_c::value>& alignInfo,
// bool reportAllFactors = false) {
// if (hypo->GetPrevHypo() != NULL) {
// outputHypo(out,hypo->GetPrevHypo(),addAlignmentInfo,
// alignInfo, reportAllFactors);
// Phrase p = hypo->GetCurrTargetPhrase();
// if(reportAllFactors) {
// out << p << " ";
// } else {
// for (size_t pos = 0 ; pos < p.GetSize() ; pos++) {
// const Factor *factor = p.GetFactor(pos, 0);
// out << *factor << " ";
// }
// }
// if (addAlignmentInfo) {
// /**
// * Add the alignment info to the array. This is in target
// * order and consists of (tgt-start, src-start, src-end)
// * triples.
// **/
// map<string, xmlrpc_c::value> phraseAlignInfo;
// phraseAlignInfo["tgt-start"] = xmlrpc_c::value_int(hypo->GetCurrTargetWordsRange().GetStartPos());
// phraseAlignInfo["src-start"] = xmlrpc_c::value_int(hypo->GetCurrSourceWordsRange().GetStartPos());
// phraseAlignInfo["src-end"] = xmlrpc_c::value_int(hypo->GetCurrSourceWordsRange().GetEndPos());
// alignInfo.push_back(xmlrpc_c::value_struct(phraseAlignInfo));
// }
// }
// }
// void outputChartHypo(ostream& out, const ChartHypothesis* hypo) {
// Phrase outPhrase(20);
// hypo->GetOutputPhrase(outPhrase);
// // delete 1st & last
// assert(outPhrase.GetSize() >= 2);
// outPhrase.RemoveWord(0);
// outPhrase.RemoveWord(outPhrase.GetSize() - 1);
// for (size_t pos = 0 ; pos < outPhrase.GetSize() ; pos++) {
// const Factor *factor = outPhrase.GetFactor(pos, 0);
// out << *factor << " ";
// }
// }
// bool compareSearchGraphNode(const SearchGraphNode& a, const SearchGraphNode b) {
// return a.hypo->GetId() < b.hypo->GetId();
// }
// void insertGraphInfo(Manager& manager, map<string, xmlrpc_c::value>& retData) {
// vector<xmlrpc_c::value> searchGraphXml;
// vector<SearchGraphNode> searchGraph;
// manager.GetSearchGraph(searchGraph);
// std::sort(searchGraph.begin(), searchGraph.end());
// for (vector<SearchGraphNode>::const_iterator i = searchGraph.begin(); i != searchGraph.end(); ++i) {
// map<string, xmlrpc_c::value> searchGraphXmlNode;
// searchGraphXmlNode["forward"] = xmlrpc_c::value_double(i->forward);
// searchGraphXmlNode["fscore"] = xmlrpc_c::value_double(i->fscore);
// const Hypothesis* hypo = i->hypo;
// searchGraphXmlNode["hyp"] = xmlrpc_c::value_int(hypo->GetId());
// searchGraphXmlNode["stack"] = xmlrpc_c::value_int(hypo->GetWordsBitmap().GetNumWordsCovered());
// if (hypo->GetId() != 0) {
// const Hypothesis *prevHypo = hypo->GetPrevHypo();
// searchGraphXmlNode["back"] = xmlrpc_c::value_int(prevHypo->GetId());
// searchGraphXmlNode["score"] = xmlrpc_c::value_double(hypo->GetScore());
// searchGraphXmlNode["transition"] = xmlrpc_c::value_double(hypo->GetScore() - prevHypo->GetScore());
// if (i->recombinationHypo) {
// searchGraphXmlNode["recombined"] = xmlrpc_c::value_int(i->recombinationHypo->GetId());
// }
// searchGraphXmlNode["cover-start"] = xmlrpc_c::value_int(hypo->GetCurrSourceWordsRange().GetStartPos());
// searchGraphXmlNode["cover-end"] = xmlrpc_c::value_int(hypo->GetCurrSourceWordsRange().GetEndPos());
// searchGraphXmlNode["out"] =
// xmlrpc_c::value_string(hypo->GetCurrTargetPhrase().GetStringRep(StaticData::Instance().GetOutputFactorOrder()));
// }
// searchGraphXml.push_back(xmlrpc_c::value_struct(searchGraphXmlNode));
// }
// retData.insert(pair<string, xmlrpc_c::value>("sg", xmlrpc_c::value_array(searchGraphXml)));
// }
// void outputNBest(const Manager& manager,
// map<string, xmlrpc_c::value>& retData,
// const int n=100,
// const bool distinct=false,
// const bool reportAllFactors=false,
// const bool addAlignmentInfo=false,
// const bool addScoreBreakdown=false)
// {
// TrellisPathList nBestList;
// manager.CalcNBest(n, nBestList, distinct);
// vector<xmlrpc_c::value> nBestXml;
// TrellisPathList::const_iterator iter;
// for (iter = nBestList.begin() ; iter != nBestList.end() ; ++iter) {
// const TrellisPath &path = **iter;
// const std::vector<const Hypothesis *> &edges = path.GetEdges();
// map<string, xmlrpc_c::value> nBestXMLItem;
// // output surface
// ostringstream out;
// vector<xmlrpc_c::value> alignInfo;
// for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--) {
// const Hypothesis &edge = *edges[currEdge];
// const Phrase& phrase = edge.GetCurrTargetPhrase();
// if(reportAllFactors) {
// out << phrase << " ";
// } else {
// for (size_t pos = 0 ; pos < phrase.GetSize() ; pos++) {
// const Factor *factor = phrase.GetFactor(pos, 0);
// out << *factor << " ";
// }
// }
// if (addAlignmentInfo && currEdge != (int)edges.size() - 1) {
// map<string, xmlrpc_c::value> phraseAlignInfo;
// phraseAlignInfo["tgt-start"] = xmlrpc_c::value_int(edge.GetCurrTargetWordsRange().GetStartPos());
// phraseAlignInfo["src-start"] = xmlrpc_c::value_int(edge.GetCurrSourceWordsRange().GetStartPos());
// phraseAlignInfo["src-end"] = xmlrpc_c::value_int(edge.GetCurrSourceWordsRange().GetEndPos());
// alignInfo.push_back(xmlrpc_c::value_struct(phraseAlignInfo));
// }
// }
// nBestXMLItem["hyp"] = xmlrpc_c::value_string(out.str());
// if (addAlignmentInfo) {
// nBestXMLItem["align"] = xmlrpc_c::value_array(alignInfo);
// if ((int)edges.size() > 0) {
// stringstream wordAlignment;
// const Hypothesis *edge = edges[0];
// edge->OutputAlignment(wordAlignment);
// vector<xmlrpc_c::value> alignments;
// string alignmentPair;
// while (wordAlignment >> alignmentPair) {
// int pos = alignmentPair.find('-');
// map<string, xmlrpc_c::value> wordAlignInfo;
// wordAlignInfo["source-word"] = xmlrpc_c::value_int(atoi(alignmentPair.substr(0, pos).c_str()));
// wordAlignInfo["target-word"] = xmlrpc_c::value_int(atoi(alignmentPair.substr(pos + 1).c_str()));
// alignments.push_back(xmlrpc_c::value_struct(wordAlignInfo));
// }
// nBestXMLItem["word-align"] = xmlrpc_c::value_array(alignments);
// }
// }
// if (addScoreBreakdown)
// {
// // should the score breakdown be reported in a more structured manner?
// ostringstream buf;
// bool with_labels
// = StaticData::Instance().options().nbest.include_feature_labels;
// path.GetScoreBreakdown()->OutputAllFeatureScores(buf, with_labels);
// nBestXMLItem["fvals"] = xmlrpc_c::value_string(buf.str());
// }
// // weighted score
// nBestXMLItem["totalScore"] = xmlrpc_c::value_double(path.GetFutureScore());
// nBestXml.push_back(xmlrpc_c::value_struct(nBestXMLItem));
// }
// retData.insert(pair<string, xmlrpc_c::value>("nbest", xmlrpc_c::value_array(nBestXml)));
// }
// void
// insertTranslationOptions(Manager& manager, map<string, xmlrpc_c::value>& retData)
// {
// const TranslationOptionCollection* toptsColl = manager.getSntTranslationOptions();
// vector<xmlrpc_c::value> toptsXml;
// size_t const stop = toptsColl->GetSource().GetSize();
// TranslationOptionList const* tol;
// for (size_t s = 0 ; s < stop ; ++s)
// {
// for (size_t e = s; (tol = toptsColl->GetTranslationOptionList(s,e)) != NULL; ++e)
// {
// BOOST_FOREACH(TranslationOption const* topt, *tol)
// {
// map<string, xmlrpc_c::value> toptXml;
// TargetPhrase const& tp = topt->GetTargetPhrase();
// StaticData const& GLOBAL = StaticData::Instance();
// string tphrase = tp.GetStringRep(GLOBAL.GetOutputFactorOrder());
// toptXml["phrase"] = xmlrpc_c::value_string(tphrase);
// toptXml["fscore"] = xmlrpc_c::value_double(topt->GetFutureScore());
// toptXml["start"] = xmlrpc_c::value_int(s);
// toptXml["end"] = xmlrpc_c::value_int(e);
// vector<xmlrpc_c::value> scoresXml;
// const std::valarray<FValue> &scores
// = topt->GetScoreBreakdown().getCoreFeatures();
// for (size_t j = 0; j < scores.size(); ++j)
// scoresXml.push_back(xmlrpc_c::value_double(scores[j]));
// toptXml["scores"] = xmlrpc_c::value_array(scoresXml);
// toptsXml.push_back(xmlrpc_c::value_struct(toptXml));
// }
// }
// }
// retData.insert(pair<string, xmlrpc_c::value>("topt", xmlrpc_c::value_array(toptsXml)));
// }
// private:
// xmlrpc_c::paramList const& m_paramList;
// map<string, xmlrpc_c::value> m_retData;
// boost::condition_variable& m_cond;
// boost::mutex& m_mut;
// bool m_done;
// };
// class Translator : public xmlrpc_c::method
// {
// public:
// Translator(size_t numThreads = 10) : m_threadPool(numThreads) {
// // signature and help strings are documentation -- the client
// // can query this information with a system.methodSignature and
// // system.methodHelp RPC.
// this->_signature = "S:S";
// this->_help = "Does translation";
// }
// void
// execute(xmlrpc_c::paramList const& paramList,
// xmlrpc_c::value * const retvalP) {
// boost::condition_variable cond;
// boost::mutex mut;
// typedef ::TranslationTask TTask;
// boost::shared_ptr<TTask> task = TTask::create(paramList,cond,mut);
// m_threadPool.Submit(task);
// boost::unique_lock<boost::mutex> lock(mut);
// while (!task->IsDone()) {
// cond.wait(lock);
// }
// *retvalP = xmlrpc_c::value_struct(task->GetRetData());
// }
// private:
// Moses::ThreadPool m_threadPool;
// };
// static
// void
// PrintFeatureWeight(ostream& out, const FeatureFunction* ff)
// {
// out << ff->GetScoreProducerDescription() << "=";
// size_t numScoreComps = ff->GetNumScoreComponents();
// vector<float> values = StaticData::Instance().GetAllWeights().GetScoresForProducer(ff);
// for (size_t i = 0; i < numScoreComps; ++i) {
// out << " " << values[i];
// }
// out << endl;
// }
// static
// void
// ShowWeights(ostream& out)
// {
// // adapted from moses-cmd/Main.cpp
// std::ios::fmtflags old_flags = out.setf(std::ios::fixed);
// size_t old_precision = out.precision(6);
// const vector<const StatelessFeatureFunction*>&
// slf = StatelessFeatureFunction::GetStatelessFeatureFunctions();
// const vector<const StatefulFeatureFunction*>&
// sff = StatefulFeatureFunction::GetStatefulFeatureFunctions();
// for (size_t i = 0; i < sff.size(); ++i) {
// const StatefulFeatureFunction *ff = sff[i];
// if (ff->IsTuneable()) {
// PrintFeatureWeight(out,ff);
// }
// else {
// out << ff->GetScoreProducerDescription() << " UNTUNEABLE" << endl;
// }
// }
// for (size_t i = 0; i < slf.size(); ++i) {
// const StatelessFeatureFunction *ff = slf[i];
// if (ff->IsTuneable()) {
// PrintFeatureWeight(out,ff);
// }
// else {
// out << ff->GetScoreProducerDescription() << " UNTUNEABLE" << endl;
// }
// }
// if (! (old_flags & std::ios::fixed))
// out.unsetf(std::ios::fixed);
// out.precision(old_precision);
// }
// int main(int argc, char** argv)
// {
// //Extract port and log, send other args to moses
// char** mosesargv = new char*[argc+2]; // why "+2" [UG]
// int mosesargc = 0;
// int port = 8080;
// const char* logfile = "/dev/null";
// bool isSerial = false;
// size_t numThreads = 10; //for translation tasks
// //Abyss server configuration: initial values reflect hard-coded default
// //-> http://xmlrpc-c.sourceforge.net/doc/libxmlrpc_server_abyss.html#max_conn
// size_t maxConn = 15;
// size_t maxConnBacklog = 15;
// size_t keepaliveTimeout = 15;
// size_t keepaliveMaxConn = 30;
// size_t timeout = 15;
// for (int i = 0; i < argc; ++i) {
// if (!strcmp(argv[i],"--server-port")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-port" << endl;
// exit(1);
// } else {
// port = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i],"--server-log")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-log" << endl;
// exit(1);
// } else {
// logfile = argv[i];
// }
// } else if (!strcmp(argv[i],"--server-maxconn")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-maxconn" << endl;
// exit(1);
// } else {
// maxConn = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i],"--server-maxconn-backlog")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-maxconn-backlog" << endl;
// exit(1);
// } else {
// maxConnBacklog = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i],"--server-keepalive-timeout")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-keepalive-timeout" << endl;
// exit(1);
// } else {
// keepaliveTimeout = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i],"--server-keepalive-maxconn")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-keepalive-maxconn" << endl;
// exit(1);
// } else {
// keepaliveMaxConn = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i],"--server-timeout")) {
// ++i;
// if (i >= argc) {
// cerr << "Error: Missing argument to --server-timeout" << endl;
// exit(1);
// } else {
// timeout = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i], "--threads")) {
// ++i;
// if (i>=argc) {
// cerr << "Error: Missing argument to --threads" << endl;
// exit(1);
// } else {
// numThreads = atoi(argv[i]);
// }
// } else if (!strcmp(argv[i], "--serial")) {
// cerr << "Running single-threaded server" << endl;
// isSerial = true;
// } else {
// mosesargv[mosesargc] = new char[strlen(argv[i])+1];
// strcpy(mosesargv[mosesargc],argv[i]);
// ++mosesargc;
// }
// }
// Parameter* params = new Parameter();
// if (!params->LoadParam(mosesargc,mosesargv)) {
// params->Explain();
// exit(1);
// }
// if (!StaticData::LoadDataStatic(params, argv[0])) {
// exit(1);
// }
// if (params->isParamSpecified("show-weights")) {
// ShowWeights(cout);
// exit(0);
// }
// //512 MB data limit (512KB is not enough for optimization)
// xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 512*1024*1024);
// xmlrpc_c::registry myRegistry;
// xmlrpc_c::methodPtr const translator(new Translator(numThreads));
// xmlrpc_c::methodPtr const updater(new Updater);
// xmlrpc_c::methodPtr const optimizer(new Optimizer);
// myRegistry.addMethod("translate", translator);
// myRegistry.addMethod("updater", updater);
// myRegistry.addMethod("optimize", optimizer);
// /* CODE FOR old xmlrpc-c v. 1.32 or lower
// xmlrpc_c::serverAbyss myAbyssServer(
// myRegistry,
// port, // TCP port on which to listen
// logfile
// );
// */
// /* doesn't work with xmlrpc-c v. 1.16.33 - ie very old lib on Ubuntu 12.04 */
// xmlrpc_c::serverAbyss myAbyssServer(
// xmlrpc_c::serverAbyss::constrOpt()
// .registryP(&myRegistry)
// .portNumber(port) // TCP port on which to listen
// .logFileName(logfile)
// .allowOrigin("*")
// .maxConn((unsigned int)maxConn)
// .maxConnBacklog((unsigned int)maxConnBacklog)
// .keepaliveTimeout((unsigned int)keepaliveTimeout)
// .keepaliveMaxConn((unsigned int)keepaliveMaxConn)
// .timeout((unsigned int)timeout)
// );
// XVERBOSE(1,"Listening on port " << port << endl);
// if (isSerial) {
// while(1) myAbyssServer.runOnce();
// } else {
// myAbyssServer.run();
// }
// std::cerr << "xmlrpc_c::serverAbyss.run() returned but should not." << std::endl;
// return 1;
// }
#endif

View File

@ -15,7 +15,7 @@ ExternalFeatureState::ExternalFeatureState(int stateSize, void *data)
memcpy(m_data, data, stateSize);
}
void ExternalFeature::Load()
void ExternalFeature::Load(AllOptions const& opts)
{
string nparam = "testing";

View File

@ -43,7 +43,7 @@ public:
}
~ExternalFeature();
void Load();
void Load(AllOptions const& opts);
bool IsUseable(const FactorMask &mask) const {
return true;

View File

@ -58,7 +58,7 @@ public:
delete m_lmImpl;
}
bool Load(const std::string &filePath
bool Load(AllOptions const& opts, const std::string &filePath
, const std::vector<FactorType> &factorTypes
, size_t nGramOrder) {
m_factorTypes = FactorMask(factorTypes);
@ -77,7 +77,7 @@ public:
m_sentenceEndWord[factorType] = factorCollection.AddFactor(Output, factorType, EOS_);
}
m_lmImpl->Load();
m_lmImpl->Load(AllOptions const& opts);
}
LMResult GetValueForgotState(const std::vector<const Word*> &contextFactor, FFState &outState) const {

View File

@ -55,8 +55,28 @@ else
}
local prefix = [ shell_or_die "$(config) --prefix" ] ;
local version = [ shell_or_die "$(config) --version" ] ;
echo "XMLRPC-C: USING VERSION $(version) FROM $(prefix)" ;
# Check the version is recent enough:
# If anyone knows a better way to do this, go ahead and fix this.
minversion = 1.32.0 ;
local cmd = "perl -e '@a = split(/\\./,@ARGV[0]); @b = split(/\\./,$ARGV[1]); ++$i while $i < $#a && $a[$i] == $b[$i]; die if $a[$i] < $b[$i];'" ;
local check = [ SHELL "$(cmd) $(version) $(minversion) 2>/dev/null" : exit-status ] ;
if $(check[2]) = 0
{
echo "XMLRPC-C: USING VERSION $(version) FROM $(prefix)" ;
}
else
{
echo "\nCOMPILATION FAILED! YOUR VERSION OF THE XMLRPC-C LIBRARY IS TOO OLD.\n" ;
echo "Moses server functionality requires XMLRPC-C version $(minversion) or newer." ;
echo "The version provided in $(prefix) is $(version). " ;
echo "Install a suitable version if necessary and provide its location with\n " ;
echo " --with-xmlrpc-c=/path/to/correct/version\n" ;
echo "You can also use --no-xmlrpc-c to compile without the xmlrpc-c library, " ;
echo "in which case Moses will work in batch mode, but can't be run as a server. " ;
exit : 1 ;
}
# now add stuff to the requirements
local xmlrpc-cxxflags = [ shell_or_die "$(config) c++2 abyss-server --cflags" ] ;
requirements += <define>HAVE_XMLRPC_C ;

View File

@ -9,6 +9,7 @@
#include "moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h"
#include "moses/Util.h"
#include "moses/Phrase.h"
#include "moses/parameters/AllOptions.h"
void usage();
@ -50,7 +51,8 @@ int main(int argc, char **argv)
std::stringstream ss;
ss << nscores;
PhraseDictionaryCompact pdc("PhraseDictionaryCompact input-factor=0 output-factor=0 num-features=" + ss.str() + " path=" + ttable);
pdc.Load();
AllOptions::ptr opts(new AllOptions);
pdc.Load(opts);
std::string line;
while(getline(std::cin, line)) {

View File

@ -163,11 +163,12 @@ int main(int argc, char const* argv[])
}
StaticData& SD = const_cast<StaticData&>(StaticData::Instance());
LMBR_Options& lmbr = SD.options().lmbr;
MBR_Options& mbr = SD.options().mbr;
boost::shared_ptr<AllOptions> opts(new AllOptions(*SD.options()));
LMBR_Options& lmbr = opts->lmbr;
MBR_Options& mbr = opts->mbr;
lmbr.enabled = true;
boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper);
boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper(*opts));
if (!ioWrapper) {
throw runtime_error("Failed to initialise IOWrapper");
}
@ -205,10 +206,7 @@ int main(int argc, char const* argv[])
<< r << " " << size_t(prune_i) << " " << scale_i
<< " ||| ";
vector<Word> mbrBestHypo = doLatticeMBR(manager,nBestList);
manager.OutputBestHypo(mbrBestHypo, lineCount,
manager.options().output.ReportSegmentation,
manager.options().output.ReportAllFactors,
cout);
manager.OutputBestHypo(mbrBestHypo, cout);
}
}
}

View File

@ -125,8 +125,8 @@ int main(int argc, char const** argv)
IFVERBOSE(1) {
PrintUserTime("Created input-output object");
}
boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper());
AllOptions::ptr opts(new AllOptions(*StaticData::Instance().options()));
boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper(*opts));
if (ioWrapper == NULL) {
cerr << "Error; Failed to create IO object" << endl;
exit(1);

View File

@ -98,10 +98,10 @@ void
BaseManager::
OutputSurface(std::ostream &out, Phrase const& phrase) const
{
std::vector<FactorType> const& factor_order = options().output.factor_order;
std::vector<FactorType> const& factor_order = options()->output.factor_order;
bool markUnknown = options().unk.mark;
std::string const& fd = options().output.FactorDelimiter;
bool markUnknown = options()->unk.mark;
std::string const& fd = options()->output.FactorDelimiter;
size_t size = phrase.GetSize();
for (size_t pos = 0 ; pos < size ; pos++) {
@ -110,7 +110,7 @@ OutputSurface(std::ostream &out, Phrase const& phrase) const
const Word &word = phrase.GetWord(pos);
if(markUnknown && word.IsOOV()) {
out << options().unk.prefix;
out << options()->unk.prefix;
}
out << *factor;
@ -122,7 +122,7 @@ OutputSurface(std::ostream &out, Phrase const& phrase) const
}
if(markUnknown && word.IsOOV()) {
out << options().unk.suffix;
out << options()->unk.suffix;
}
out << " ";
@ -147,7 +147,7 @@ void BaseManager::WriteApplicationContext(std::ostream &out,
}
}
AllOptions const&
AllOptions::ptr const&
BaseManager::
options() const
{

View File

@ -49,7 +49,7 @@ public:
//! the input sentence being decoded
const InputType& GetSource() const;
const ttasksptr GetTtask() const;
AllOptions const& options() const;
AllOptions::ptr const& options() const;
virtual void Decode() = 0;
// outputs

View File

@ -61,7 +61,7 @@ public:
, m_transOptRange(transOptRange) {
m_totalWeightDistortion = 0;
const StaticData &staticData = StaticData::Instance();
const std::vector<const DistortionScoreProducer*> &ffs = DistortionScoreProducer::GetDistortionFeatureFunctions();
std::vector<const DistortionScoreProducer*>::const_iterator iter;
for (iter = ffs.begin(); iter != ffs.end(); ++iter) {
@ -139,7 +139,8 @@ BackwardsEdge::BackwardsEdge(const BitmapContainer &prevBitmapContainer
}
// Fetch the things we need for distortion cost computation.
int maxDistortion = StaticData::Instance().GetMaxDistortion();
// int maxDistortion = StaticData::Instance().GetMaxDistortion();
int maxDistortion = itype.options()->reordering.max_distortion;
if (maxDistortion == -1) {
for (HypothesisSet::const_iterator iter = m_prevBitmapContainer.GetHypotheses().begin(); iter != m_prevBitmapContainer.GetHypotheses().end(); ++iter) {

View File

@ -50,7 +50,7 @@ ChartCellBase::~ChartCellBase() {}
ChartCell::ChartCell(size_t startPos, size_t endPos, ChartManager &manager) :
ChartCellBase(startPos, endPos), m_manager(manager)
{
m_nBestIsEnabled = manager.options().nbest.enabled;
m_nBestIsEnabled = manager.options()->nbest.enabled;
}
ChartCell::~ChartCell() {}
@ -66,7 +66,7 @@ bool ChartCell::AddHypothesis(ChartHypothesis *hypo)
MapType::iterator m = m_hypoColl.find(targetLHS);
if (m == m_hypoColl.end()) {
std::pair<Word, ChartHypothesisCollection>
e(targetLHS, ChartHypothesisCollection(m_manager.options()));
e(targetLHS, ChartHypothesisCollection(*m_manager.options()));
m = m_hypoColl.insert(e).first;
}
return m->second.AddHypothesis(hypo, m_manager);
@ -101,7 +101,7 @@ void ChartCell::Decode(const ChartTranslationOptionList &transOptList
}
// pluck things out of queue and add to hypo collection
const size_t popLimit = m_manager.options().cube.pop_limit;
const size_t popLimit = m_manager.options()->cube.pop_limit;
for (size_t numPops = 0; numPops < popLimit && !queue.IsEmpty(); ++numPops) {
ChartHypothesis *hypo = queue.Pop();
AddHypothesis(hypo);

View File

@ -102,7 +102,7 @@ ChartHypothesis::~ChartHypothesis()
*/
void ChartHypothesis::GetOutputPhrase(Phrase &outPhrase) const
{
FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor;
FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor;
for (size_t pos = 0; pos < GetCurrTargetPhrase().GetSize(); ++pos) {
const Word &word = GetCurrTargetPhrase().GetWord(pos);
@ -256,7 +256,7 @@ void ChartHypothesis::CleanupArcList()
* However, may not be enough if only unique candidates are needed,
* so we'll keep all of arc list if nedd distinct n-best list
*/
AllOptions const& opts = StaticData::Instance().options();
AllOptions const& opts = *StaticData::Instance().options();
size_t nBestSize = opts.nbest.nbest_size;
bool distinctNBest = (opts.nbest.only_distinct
|| opts.mbr.enabled
@ -336,7 +336,7 @@ std::ostream& operator<<(std::ostream& out, const ChartHypothesis& hypo)
out << "->" << hypo.GetWinningHypothesis()->GetId();
}
if (StaticData::Instance().GetIncludeLHSInSearchGraph()) {
if (hypo.GetManager().options()->output.include_lhs_in_search_graph) {
out << " " << hypo.GetTargetLHS() << "=>";
}
out << " " << hypo.GetCurrTargetPhrase()

View File

@ -52,7 +52,7 @@ protected:
boost::shared_ptr<ChartTranslationOption> m_transOpt;
Range m_currSourceWordsRange;
Range m_currSourceWordsRange;
std::vector<const FFState*> m_ffStates; /*! stateful feature function states */
/*! sum of scores of this hypothesis, and previous hypotheses. Lazily initialised. */
mutable boost::scoped_ptr<ScoreComponentCollection> m_scoreBreakdown;
@ -62,8 +62,8 @@ protected:
,m_lmPrefix;
float m_totalScore;
ChartArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */
const ChartHypothesis *m_winningHypo;
ChartArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */
const ChartHypothesis *m_winningHypo;
std::vector<const ChartHypothesis*> m_prevHypos; // always sorted by source position?

View File

@ -82,7 +82,7 @@ void ChartKBestExtractor::Extract(
// Generate the target-side yield of the derivation d.
Phrase ChartKBestExtractor::GetOutputPhrase(const Derivation &d)
{
FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor;
FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor;
Phrase ret(ARRAY_SIZE_INCR);

View File

@ -128,16 +128,15 @@ void ChartManager::Decode()
*/
void ChartManager::AddXmlChartOptions()
{
// const StaticData &staticData = StaticData::Instance();
const std::vector <ChartTranslationOptions*> xmlChartOptionsList = m_source.GetXmlChartTranslationOptions();
const std::vector <ChartTranslationOptions*> xmlChartOptionsList
= m_source.GetXmlChartTranslationOptions();
IFVERBOSE(2) {
cerr << "AddXmlChartOptions " << xmlChartOptionsList.size() << endl;
}
if (xmlChartOptionsList.size() == 0) return;
for(std::vector<ChartTranslationOptions*>::const_iterator i = xmlChartOptionsList.begin();
i != xmlChartOptionsList.end(); ++i) {
typedef std::vector<ChartTranslationOptions*>::const_iterator citer;
for(citer i = xmlChartOptionsList.begin(); i != xmlChartOptionsList.end(); ++i) {
ChartTranslationOptions* opt = *i;
const Range &range = opt->GetSourceWordsRange();
@ -204,8 +203,7 @@ void ChartManager::CalcNBest(
// than n. The n-best factor determines how much bigger the limit should be,
// with 0 being 'unlimited.' This actually sets a large-ish limit in case
// too many translations are identical.
const StaticData &staticData = StaticData::Instance();
const std::size_t nBestFactor = staticData.options().nbest.factor;
const std::size_t nBestFactor = options()->nbest.factor;
std::size_t numDerivations = (nBestFactor == 0) ? n*1000 : n*nBestFactor;
// Extract the derivations.
@ -315,15 +313,14 @@ void ChartManager::OutputBest(OutputCollector *collector) const
void ChartManager::OutputNBest(OutputCollector *collector) const
{
// const StaticData &staticData = StaticData::Instance();
size_t nBestSize = options().nbest.nbest_size;
size_t nBestSize = options()->nbest.nbest_size;
if (nBestSize > 0) {
const size_t translationId = m_source.GetTranslationId();
VERBOSE(2,"WRITING " << nBestSize << " TRANSLATION ALTERNATIVES TO "
<< options().nbest.output_file_path << endl);
<< options()->nbest.output_file_path << endl);
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
CalcNBest(nBestSize, nBestList, options().nbest.only_distinct);
CalcNBest(nBestSize, nBestList, options()->nbest.only_distinct);
OutputNBestList(collector, nBestList, translationId);
IFVERBOSE(2) {
PrintUserTime("N-Best Hypotheses Generation Time:");
@ -336,9 +333,6 @@ void ChartManager::OutputNBestList(OutputCollector *collector,
const ChartKBestExtractor::KBestVec &nBestList,
long translationId) const
{
// const StaticData &staticData = StaticData::Instance();
// const std::vector<Moses::FactorType> &outputFactorOrder = staticData.GetOutputFactorOrder();
std::ostringstream out;
if (collector->OutputIsCout()) {
@ -347,7 +341,7 @@ void ChartManager::OutputNBestList(OutputCollector *collector,
FixPrecision(out);
}
NBestOptions const& nbo = options().nbest;
NBestOptions const& nbo = options()->nbest;
bool includeWordAlignment = nbo.include_alignment_info;
bool PrintNBestTrees = nbo.print_trees;
@ -369,7 +363,7 @@ void ChartManager::OutputNBestList(OutputCollector *collector,
OutputSurface(out, outputPhrase); // , outputFactorOrder, false);
out << " ||| ";
boost::shared_ptr<ScoreComponentCollection> scoreBreakdown = ChartKBestExtractor::GetOutputScoreBreakdown(derivation);
bool with_labels = options().nbest.include_feature_labels;
bool with_labels = options()->nbest.include_feature_labels;
scoreBreakdown->OutputAllFeatureScores(out, with_labels);
out << " ||| " << derivation.score;
@ -615,13 +609,11 @@ void ChartManager::OutputDetailedTranslationReport(
collector->Write(translationId, out.str());
//DIMw
const StaticData &staticData = StaticData::Instance();
if (options().output.detailed_all_transrep_filepath.size()) {
if (options()->output.detailed_all_transrep_filepath.size()) {
const Sentence &sentence = static_cast<const Sentence &>(m_source);
size_t nBestSize = staticData.options().nbest.nbest_size;
size_t nBestSize = options()->nbest.nbest_size;
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
CalcNBest(nBestSize, nBestList, staticData.options().nbest.nbest_size);
CalcNBest(nBestSize, nBestList, options()->nbest.only_distinct);
OutputDetailedAllTranslationReport(collector, nBestList, sentence, translationId);
}
@ -725,7 +717,8 @@ void ChartManager::OutputDetailedTreeFragmentsTranslationReport(OutputCollector
OutputTreeFragmentsTranslationOptions(out, applicationContext, hypo, sentence, translationId);
//Tree of full sentence
const StatefulFeatureFunction* treeStructure = StaticData::Instance().GetTreeStructure();
const StatefulFeatureFunction* treeStructure;
treeStructure = StaticData::Instance().GetTreeStructure();
if (treeStructure != NULL) {
const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions();
for( size_t i=0; i<sff.size(); i++ ) {
@ -813,15 +806,6 @@ void ChartManager::OutputDetailedAllTranslationReport(
collector->Write(translationId, out.str());
}
// void ChartManager::OutputSearchGraphHypergraph() const
// {
// const StaticData &staticData = StaticData::Instance();
// if (staticData.GetOutputSearchGraphHypergraph()) {
// HypergraphOutput<ChartManager> hypergraphOutputChart(PRECISION);
// hypergraphOutputChart.Write(*this);
// }
// }
void ChartManager::OutputBestHypo(OutputCollector *collector, const ChartHypothesis *hypo, long translationId) const
{
if (!collector)
@ -834,11 +818,11 @@ void ChartManager::OutputBestHypo(OutputCollector *collector, const ChartHypothe
Backtrack(hypo);
VERBOSE(3,"0" << std::endl);
if (options().output.ReportHypoScore) {
if (options()->output.ReportHypoScore) {
out << hypo->GetFutureScore() << " ";
}
if (options().output.RecoverPath) {
if (options()->output.RecoverPath) {
out << "||| ";
}
Phrase outPhrase(ARRAY_SIZE_INCR);
@ -851,14 +835,12 @@ void ChartManager::OutputBestHypo(OutputCollector *collector, const ChartHypothe
outPhrase.RemoveWord(0);
outPhrase.RemoveWord(outPhrase.GetSize() - 1);
const std::vector<FactorType> outputFactorOrder
= StaticData::Instance().GetOutputFactorOrder();
string output = outPhrase.GetStringRep(outputFactorOrder);
string output = outPhrase.GetStringRep(options()->output.factor_order);
out << output << endl;
} else {
VERBOSE(1, "NO BEST TRANSLATION" << endl);
if (options().output.ReportHypoScore) {
if (options()->output.ReportHypoScore) {
out << "0 ";
}

View File

@ -44,17 +44,26 @@ ChartParserUnknown
ChartParserUnknown::~ChartParserUnknown()
{
RemoveAllInColl(m_unksrcs);
// RemoveAllInColl(m_cacheTargetPhraseCollection);
}
void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, ChartParserCallback &to)
AllOptions::ptr const&
ChartParserUnknown::
options() const
{
return m_ttask.lock()->options();
}
void
ChartParserUnknown::
Process(const Word &sourceWord, const Range &range, ChartParserCallback &to)
{
// unknown word, add as trans opt
const StaticData &staticData = StaticData::Instance();
const UnknownWordPenaltyProducer &unknownWordPenaltyProducer = UnknownWordPenaltyProducer::Instance();
const UnknownWordPenaltyProducer &unknownWordPenaltyProducer
= UnknownWordPenaltyProducer::Instance();
size_t isDigit = 0;
if (staticData.options().unk.drop) {
if (options()->unk.drop) {
const Factor *f = sourceWord[0]; // TODO hack. shouldn't know which factor is surface
const StringPiece s = f->GetString();
isDigit = s.find_first_of("0123456789");
@ -79,9 +88,9 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha
}
//TranslationOption *transOpt;
if (! staticData.options().unk.drop || isDigit) {
if (! options()->unk.drop || isDigit) {
// loop
const UnknownLHSList &lhsList = staticData.GetUnknownLHS();
const UnknownLHSList &lhsList = options()->syntax.unknown_lhs; // staticData.GetUnknownLHS();
UnknownLHSList::const_iterator iterLHS;
for (iterLHS = lhsList.begin(); iterLHS != lhsList.end(); ++iterLHS) {
const string &targetLHSStr = iterLHS->first;
@ -91,7 +100,8 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha
//const Word &sourceLHS = staticData.GetInputDefaultNonTerminal();
Word *targetLHS = new Word(true);
targetLHS->CreateFromString(Output, staticData.GetOutputFactorOrder(), targetLHSStr, true);
targetLHS->CreateFromString(Output, options()->output.factor_order,
targetLHSStr, true);
UTIL_THROW_IF2(targetLHS->GetFactor(0) == NULL, "Null factor for target LHS");
// add to dictionary
@ -107,9 +117,8 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha
targetPhrase->SetAlignmentInfo("0-0");
targetPhrase->EvaluateInIsolation(*unksrc);
AllOptions const& opts = staticData.options();
if (!opts.output.detailed_tree_transrep_filepath.empty() ||
opts.nbest.print_trees || staticData.GetTreeStructure() != NULL) {
if (!options()->output.detailed_tree_transrep_filepath.empty() ||
options()->nbest.print_trees || staticData.GetTreeStructure() != NULL) {
std::string prop = "[ ";
prop += (*targetLHS)[0]->GetString().as_string() + " ";
prop += sourceWord[0]->GetString().as_string() + " ]";
@ -125,14 +134,15 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha
TargetPhrase *targetPhrase = new TargetPhrase(firstPt);
// loop
const UnknownLHSList &lhsList = staticData.GetUnknownLHS();
const UnknownLHSList &lhsList = options()->syntax.unknown_lhs;//staticData.GetUnknownLHS();
UnknownLHSList::const_iterator iterLHS;
for (iterLHS = lhsList.begin(); iterLHS != lhsList.end(); ++iterLHS) {
const string &targetLHSStr = iterLHS->first;
//float prob = iterLHS->second;
Word *targetLHS = new Word(true);
targetLHS->CreateFromString(Output, staticData.GetOutputFactorOrder(), targetLHSStr, true);
targetLHS->CreateFromString(Output, staticData.options()->output.factor_order,
targetLHSStr, true);
UTIL_THROW_IF2(targetLHS->GetFactor(0) == NULL, "Null factor for target LHS");
targetPhrase->GetScoreBreakdown().Assign(&unknownWordPenaltyProducer, unknownScore);
@ -209,9 +219,11 @@ void ChartParser::Create(const Range &range, ChartParserCallback &to)
}
}
if (range.GetNumWordsCovered() == 1 && range.GetStartPos() != 0 && range.GetStartPos() != m_source.GetSize()-1) {
bool alwaysCreateDirectTranslationOption = StaticData::Instance().IsAlwaysCreateDirectTranslationOption();
if (to.Empty() || alwaysCreateDirectTranslationOption) {
if (range.GetNumWordsCovered() == 1
&& range.GetStartPos() != 0
&& range.GetStartPos() != m_source.GetSize()-1) {
bool always = options()->unk.always_create_direct_transopt;
if (to.Empty() || always) {
// create unknown words for 1 word coverage where we don't have any trans options
const Word &sourceWord = m_source.GetWord(range.GetStartPos());
m_unknown.Process(sourceWord, range, to);
@ -285,4 +297,14 @@ long ChartParser::GetTranslationId() const
{
return m_source.GetTranslationId();
}
AllOptions::ptr const&
ChartParser::
options() const
{
return m_ttask.lock()->options();
}
} // namespace Moses

View File

@ -57,6 +57,7 @@ public:
private:
std::vector<Phrase*> m_unksrcs;
std::list<TargetPhraseCollection::shared_ptr> m_cacheTargetPhraseCollection;
AllOptions::ptr const& options() const;
};
class ChartParser
@ -78,6 +79,8 @@ public:
return m_unknown.GetUnknownSources();
}
AllOptions::ptr const& options() const;
private:
ChartParserUnknown m_unknown;
std::vector <DecodeGraph*> m_decodeGraphList;

View File

@ -68,7 +68,7 @@ void ChartTranslationOptions::EvaluateWithSourceContext(const InputType &input,
{
SetInputPath(&inputPath);
// if (StaticData::Instance().GetPlaceholderFactor() != NOT_FOUND) {
if (inputPath.ttask.lock()->options().input.placeholder_factor != NOT_FOUND) {
if (inputPath.ttask.lock()->options()->input.placeholder_factor != NOT_FOUND) {
CreateSourceRuleFromInputPath();
}

View File

@ -11,7 +11,7 @@
#include "Sentence.h"
#include "moses/FF/InputFeature.h"
#include "util/exception.hh"
#include "moses/TranslationTask.h"
namespace Moses
{
struct CNStats {
@ -62,13 +62,12 @@ GetColumnIncrement(size_t i, size_t j) const
}
ConfusionNet::
ConfusionNet() : InputType()
ConfusionNet(AllOptions::ptr const& opts) : InputType(opts)
{
stats.createOne();
const StaticData& SD = StaticData::Instance();
if (SD.IsSyntax()) {
m_defaultLabelSet.insert(SD.GetInputDefaultNonTerminal());
if (is_syntax(opts->search.algo)) {
m_defaultLabelSet.insert(opts->syntax.input_default_non_terminal);
}
UTIL_THROW_IF2(InputFeature::InstancePtr() == NULL, "Input feature must be specified");
}
@ -80,7 +79,7 @@ ConfusionNet::
}
ConfusionNet::
ConfusionNet(Sentence const& s) : InputType()
ConfusionNet(Sentence const& s) : InputType(s.options())
{
data.resize(s.GetSize());
for(size_t i=0; i<s.GetSize(); ++i) {
@ -92,14 +91,14 @@ ConfusionNet(Sentence const& s) : InputType()
bool
ConfusionNet::
ReadF(std::istream& in, const std::vector<FactorType>& factorOrder, int format)
ReadF(std::istream& in, int format)
{
VERBOSE(2, "read confusion net with format "<<format<<"\n");
switch(format) {
case 0:
return ReadFormat0(in,factorOrder);
return ReadFormat0(in);
case 1:
return ReadFormat1(in,factorOrder);
return ReadFormat1(in);
default:
std::cerr << "ERROR: unknown format '"<<format
<<"' in ConfusionNet::Read";
@ -109,22 +108,20 @@ ReadF(std::istream& in, const std::vector<FactorType>& factorOrder, int format)
int
ConfusionNet::
Read(std::istream& in,
const std::vector<FactorType>& factorOrder,
AllOptions const& opts)
Read(std::istream& in)
{
int rv=ReadF(in,factorOrder,0);
int rv=ReadF(in,0);
if(rv) stats.collect(*this);
return rv;
}
bool
ConfusionNet::
ReadFormat0(std::istream& in, const std::vector<FactorType>& factorOrder)
ReadFormat0(std::istream& in)
{
Clear();
const std::vector<FactorType>& factorOrder = m_options->input.factor_order;
// const StaticData &staticData = StaticData::Instance();
const InputFeature *inputFeature = InputFeature::InstancePtr();
size_t numInputScores = inputFeature->GetNumInputScores();
size_t numRealWordCount = inputFeature->GetNumRealWordsInInput();
@ -140,7 +137,6 @@ ReadFormat0(std::istream& in, const std::vector<FactorType>& factorOrder)
Column col;
while(is>>word) {
Word w;
// String2Word(word,w,factorOrder);
w.CreateFromString(Input,factorOrder,StringPiece(word),false,false);
std::vector<float> probs(totalCount, 0.0);
for(size_t i=0; i < numInputScores; i++) {
@ -179,9 +175,10 @@ ReadFormat0(std::istream& in, const std::vector<FactorType>& factorOrder)
bool
ConfusionNet::
ReadFormat1(std::istream& in, const std::vector<FactorType>& factorOrder)
ReadFormat1(std::istream& in)
{
Clear();
const std::vector<FactorType>& factorOrder = m_options->input.factor_order;
std::string line;
if(!getline(in,line)) return 0;
size_t s;
@ -282,9 +279,11 @@ ConfusionNet::
CreateTranslationOptionCollection(ttasksptr const& ttask) const
{
size_t maxNoTransOptPerCoverage
= StaticData::Instance().GetMaxNoTransOptPerCoverage();
= ttask->options()->search.max_trans_opt_per_cov;
// StaticData::Instance().GetMaxNoTransOptPerCoverage();
float translationOptionThreshold
= StaticData::Instance().GetTranslationOptionThreshold();
= ttask->options()->search.trans_opt_threshold;
// StaticData::Instance().GetTranslationOptionThreshold();
TranslationOptionCollection *rv
= new TranslationOptionCollectionConfusionNet
(ttask, *this, maxNoTransOptPerCoverage, translationOptionThreshold);

View File

@ -30,12 +30,12 @@ protected:
std::vector<Column> data;
NonTerminalSet m_defaultLabelSet;
bool ReadFormat0(std::istream&,const std::vector<FactorType>& factorOrder);
bool ReadFormat1(std::istream&,const std::vector<FactorType>& factorOrder);
bool ReadFormat0(std::istream&);
bool ReadFormat1(std::istream&);
void String2Word(const std::string& s,Word& w,const std::vector<FactorType>& factorOrder);
public:
ConfusionNet();
ConfusionNet(AllOptions::ptr const& opts);
virtual ~ConfusionNet();
ConfusionNet(Sentence const& s);
@ -46,7 +46,8 @@ public:
const Column& GetColumn(size_t i) const {
UTIL_THROW_IF2(i >= data.size(),
"Out of bounds. Trying to access " << i << " when vector only contains " << data.size());
"Out of bounds. Trying to access " << i
<< " when vector only contains " << data.size());
return data[i];
}
const Column& operator[](size_t i) const {
@ -64,11 +65,10 @@ public:
data.clear();
}
bool ReadF(std::istream&,const std::vector<FactorType>& factorOrder,int format=0);
bool ReadF(std::istream&, int format=0);
virtual void Print(std::ostream&) const;
int Read(std::istream& in,const std::vector<FactorType>& factorOrder,
AllOptions const& opts);
int Read(std::istream& in);
Phrase GetSubString(const Range&) const; //TODO not defined
std::string GetStringRep(const std::vector<FactorType> factorsToPrint) const; //TODO not defined

View File

@ -64,6 +64,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef HAVE_XMLRPC_C
#include "moses/server/Server.h"
#endif
#include <signal.h>
using namespace std;
using namespace Moses;
@ -102,7 +103,7 @@ SimpleTranslationInterface::~SimpleTranslationInterface()
//the simplified version of string input/output translation
string SimpleTranslationInterface::translate(const string &inputString)
{
boost::shared_ptr<Moses::IOWrapper> ioWrapper(new IOWrapper);
boost::shared_ptr<Moses::IOWrapper> ioWrapper(new IOWrapper(*StaticData::Instance().options()));
// main loop over set of input sentences
size_t sentEnd = inputString.rfind('\n'); //find the last \n, the input stream has to be appended with \n to be translated
const string &newString = sentEnd != string::npos ? inputString : inputString + '\n';
@ -142,11 +143,25 @@ void SimpleTranslationInterface::DestroyFeatureFunctionStatic()
Parameter params;
void
signal_handler(int signum)
{
if (signum == SIGALRM) {
exit(0); // that's what we expected from the child process after forking
} else if (signum == SIGTERM || signum == SIGKILL) {
exit(0);
} else {
std::cerr << "Unexpected signal " << signum << std::endl;
exit(signum);
}
}
//! run moses in server mode
int
run_as_server()
{
#ifdef HAVE_XMLRPC_C
kill(getppid(),SIGALRM);
MosesServer::Server server(params);
return server.run(); // actually: don't return. see Server::run()
#else
@ -167,7 +182,7 @@ batch_run()
IFVERBOSE(1) PrintUserTime("Created input-output object");
// set up read/writing class:
boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper);
boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper(*staticData.options()));
UTIL_THROW_IF2(ioWrapper == NULL, "Error; Failed to create IO object"
<< " [" << HERE << "]");
@ -326,17 +341,28 @@ int decoder_main(int argc, char const** argv)
if (!StaticData::LoadDataStatic(&params, argv[0]))
exit(1);
//
#if 1
pid_t pid;
if (params.GetParam("daemon")) {
pid = fork();
if (pid) {
pause(); // parent process
exit(0);
}
}
#endif
// setting "-show-weights" -> just dump out weights and exit
if (params.isParamSpecified("show-weights")) {
ShowWeights();
exit(0);
}
if (params.GetParam("server"))
if (params.GetParam("server")) {
std::cerr << "RUN SERVER at pid " << pid << std::endl;
return run_as_server();
else
} else
return batch_run();
}
#ifdef NDEBUG
catch (const std::exception &e) {

View File

@ -46,12 +46,12 @@ ConstrainedDecoding::ConstrainedDecoding(const std::string &line)
ReadParameters();
}
void ConstrainedDecoding::Load()
void ConstrainedDecoding::Load(AllOptions::ptr const& opts)
{
m_options = opts;
const StaticData &staticData = StaticData::Instance();
bool addBeginEndWord
= ((staticData.options().search.algo == CYKPlus)
|| (staticData.options().search.algo == ChartIncremental));
= ((opts->search.algo == CYKPlus) || (opts->search.algo == ChartIncremental));
for(size_t i = 0; i < m_paths.size(); ++i) {
InputFileStream constraintFile(m_paths[i]);
@ -63,12 +63,10 @@ void ConstrainedDecoding::Load()
Phrase phrase(0);
if (vecStr.size() == 1) {
sentenceID++;
// phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], staticData.GetFactorDelimiter(), NULL);
phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], NULL);
phrase.CreateFromString(Output, opts->output.factor_order, vecStr[0], NULL);
} else if (vecStr.size() == 2) {
sentenceID = Scan<long>(vecStr[0]);
// phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], staticData.GetFactorDelimiter(), NULL);
phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], NULL);
phrase.CreateFromString(Output, opts->output.factor_order, vecStr[1], NULL);
} else {
UTIL_THROW(util::Exception, "Reference file not loaded");
}

View File

@ -36,7 +36,7 @@ class ConstrainedDecoding : public StatefulFeatureFunction
public:
ConstrainedDecoding(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
bool IsUseable(const FactorMask &mask) const {
return true;

View File

@ -1,7 +1,6 @@
#include "CountNonTerms.h"
#include "moses/Util.h"
#include "moses/TargetPhrase.h"
#include "moses/StaticData.h"
using namespace std;
@ -21,8 +20,6 @@ void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection &estimatedScores) const
{
const StaticData &staticData = StaticData::Instance();
vector<float> scores(m_numScoreComponents, 0);
size_t indScore = 0;
@ -39,7 +36,7 @@ void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase
if (m_targetSyntax) {
for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
const Word &word = targetPhrase.GetWord(i);
if (word.IsNonTerminal() && word != staticData.GetOutputDefaultNonTerminal()) {
if (word.IsNonTerminal() && word != m_options->syntax.output_default_non_terminal) {
++scores[indScore];
}
}
@ -49,7 +46,7 @@ void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase
if (m_sourceSyntax) {
for (size_t i = 0; i < sourcePhrase.GetSize(); ++i) {
const Word &word = sourcePhrase.GetWord(i);
if (word.IsNonTerminal() && word != staticData.GetInputDefaultNonTerminal()) {
if (word.IsNonTerminal() && word != m_options->syntax.input_default_non_terminal) {
++scores[indScore];
}
}
@ -72,5 +69,12 @@ void CountNonTerms::SetParameter(const std::string& key, const std::string& valu
}
}
void
CountNonTerms::
Load(AllOptions::ptr const& opts)
{
m_options = opts;
}
}

View File

@ -41,6 +41,7 @@ public:
void SetParameter(const std::string& key, const std::string& value);
void Load(AllOptions::ptr const& opts);
protected:
bool m_all, m_sourceSyntax, m_targetSyntax;
};

View File

@ -52,8 +52,9 @@ void CoveredReferenceFeature::EvaluateWithSourceContext(const InputType &input
estimatedScores->Assign(this, scores);
}
void CoveredReferenceFeature::Load()
void CoveredReferenceFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
InputFileStream refFile(m_path);
std::string line;
const StaticData &staticData = StaticData::Instance();

View File

@ -44,7 +44,7 @@ public:
ReadParameters();
}
void Load();
void Load(AllOptions::ptr const& opts);
bool IsUseable(const FactorMask &mask) const {
return true;

View File

@ -16,8 +16,9 @@ DeleteRules::DeleteRules(const std::string &line)
ReadParameters();
}
void DeleteRules::Load()
void DeleteRules::Load(AllOptions::ptr const& opts)
{
m_options = opts;
std::vector<FactorType> factorOrder;
factorOrder.push_back(0); // unfactored for now

View File

@ -15,7 +15,7 @@ protected:
public:
DeleteRules(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
bool IsUseable(const FactorMask &mask) const {
return true;

View File

@ -323,8 +323,9 @@ void DynamicCacheBasedLanguageModel::Clear()
m_cache.clear();
}
void DynamicCacheBasedLanguageModel::Load()
void DynamicCacheBasedLanguageModel::Load(AllOptions::ptr const& opts)
{
m_options = opts;
// SetPreComputedScores();
VERBOSE(2,"DynamicCacheBasedLanguageModel::Load()" << std::endl);
Load(m_initfiles);

View File

@ -119,7 +119,7 @@ public:
return true;
}
void Load();
void Load(AllOptions::ptr const& opts);
void Load(const std::string filestr);
void Execute(std::string command);
void SetParameter(const std::string& key, const std::string& value);

View File

@ -7,12 +7,13 @@
#include <string>
#include "moses/FeatureVector.h"
#include "moses/TypeDef.h"
#include "moses/parameters/AllOptions.h"
#include <boost/shared_ptr.hpp>
namespace Moses
{
class AllOptions;
class Phrase;
class TargetPhrase;
class TranslationOptionList;
@ -46,6 +47,7 @@ protected:
size_t m_index; // index into vector covering ALL feature function values
std::vector<bool> m_tuneableComponents;
size_t m_numTuneableComponents;
AllOptions::ptr m_options;
//In case there's multiple producers with the same description
static std::multiset<std::string> description_counts;
@ -69,7 +71,13 @@ public:
virtual ~FeatureFunction();
//! override to load model files
virtual void Load() {
virtual void Load(AllOptions::ptr const& opts) {
m_options = opts;
}
AllOptions::ptr const&
options() const {
return m_options;
}
static void ResetDescriptionCounts() {

View File

@ -51,8 +51,9 @@ GlobalLexicalModel::~GlobalLexicalModel()
}
}
void GlobalLexicalModel::Load()
void GlobalLexicalModel::Load(AllOptions::ptr const& opts)
{
m_options = opts;
FactorCollection &factorCollection = FactorCollection::Instance();
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();

View File

@ -57,7 +57,7 @@ private:
std::vector<FactorType> m_inputFactorsVec, m_outputFactorsVec;
std::string m_filePath;
void Load();
void Load(AllOptions::ptr const& opts);
float ScorePhrase( const TargetPhrase& targetPhrase ) const;
float GetFromCacheOrScorePhrase( const TargetPhrase& targetPhrase ) const;

View File

@ -19,8 +19,8 @@ HyperParameterAsWeight::HyperParameterAsWeight(const std::string &line)
vector<float> weights = staticData.GetWeights(this);
staticData.m_options.search.stack_size = weights[0] * 1000;
staticData.m_options.search.beam_width = weights[1] * 10;
staticData.m_options->search.stack_size = weights[0] * 1000;
staticData.m_options->search.beam_width = weights[1] * 10;
}

View File

@ -23,9 +23,9 @@ InputFeature::InputFeature(const std::string &line)
s_instance = this;
}
void InputFeature::Load()
void InputFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
const PhraseDictionary *pt = PhraseDictionary::GetColl()[0];
const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt);

View File

@ -23,7 +23,7 @@ public:
InputFeature(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
void SetParameter(const std::string& key, const std::string& value);

View File

@ -7,8 +7,11 @@ namespace Moses
InternalTree::InternalTree(const std::string & line, size_t start, size_t len, const bool nonterminal)
{
std::vector<FactorType> const& oFactors
= StaticData::Instance().options()->output.factor_order;
if (len > 0) {
m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), StringPiece(line).substr(start, len), nonterminal);
m_value.CreateFromString(Output, oFactors, StringPiece(line).substr(start, len),
nonterminal);
}
}
@ -18,7 +21,9 @@ InternalTree::InternalTree(const std::string & line, const bool nonterminal)
size_t found = line.find_first_of("[] ");
if (found == line.npos) {
m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), line, nonterminal);
m_value.CreateFromString(Output,
StaticData::Instance().options()->output.factor_order,
line, nonterminal);
} else {
AddSubTree(line, 0);
}
@ -44,14 +49,18 @@ size_t InternalTree::AddSubTree(const std::string & line, size_t pos)
pos = m_children.back()->AddSubTree(line, pos+1);
} else {
if (len > 0) {
m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), StringPiece(line).substr(oldpos, len), false);
m_value.CreateFromString(Output,
StaticData::Instance().options()->output.factor_order,
StringPiece(line).substr(oldpos, len), false);
has_value = true;
}
pos = AddSubTree(line, pos+1);
}
} else if (token == ' ' || token == ']') {
if (len > 0 && !has_value) {
m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), StringPiece(line).substr(oldpos, len), true);
m_value.CreateFromString(Output,
StaticData::Instance().options()->output.factor_order,
StringPiece(line).substr(oldpos, len), true);
has_value = true;
} else if (len > 0) {
m_children.push_back(boost::make_shared<InternalTree>(line, oldpos, len, false));
@ -81,7 +90,7 @@ std::string InternalTree::GetString(bool start) const
ret += "[";
}
ret += m_value.GetString(StaticData::Instance().GetOutputFactorOrder(), false);
ret += m_value.GetString(StaticData::Instance().options()->output.factor_order, false);
for (std::vector<TreePointer>::const_iterator it = m_children.begin(); it != m_children.end(); ++it) {
ret += (*it)->GetString(false);
}
@ -189,4 +198,4 @@ bool InternalTree::RecursiveSearch(const Word & label, std::vector<TreePointer>:
return false;
}
}
}

View File

@ -6,6 +6,7 @@
#include <vector>
#include "FFState.h"
#include "moses/Word.h"
#include "moses/StaticData.h"
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include "util/generator.hh"

View File

@ -84,8 +84,9 @@ LexicalReordering::
void
LexicalReordering::
Load()
Load(AllOptions::ptr const& opts)
{
m_options = opts;
typedef LexicalReorderingTable LRTable;
if (m_filePath.size())
m_table.reset(LRTable::LoadAvailable(m_filePath, m_factorsF,

View File

@ -33,7 +33,7 @@ class LexicalReordering : public StatefulFeatureFunction
public:
LexicalReordering(const std::string &line);
virtual ~LexicalReordering();
void Load();
void Load(AllOptions::ptr const& opts);
virtual
bool

View File

@ -159,8 +159,9 @@ void Model1Feature::SetParameter(const std::string& key, const std::string& valu
}
}
void Model1Feature::Load()
void Model1Feature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
FEATUREVERBOSE(2, GetScoreProducerDescription() << ": Loading source vocabulary from file " << m_fileNameVcbS << " ...");
Model1Vocabulary vcbS;
vcbS.Load(m_fileNameVcbS);

View File

@ -99,7 +99,7 @@ private:
Model1LexicalTable m_model1;
const Factor* m_emptyWord;
void Load();
void Load(AllOptions::ptr const& opts);
// cache
mutable boost::unordered_map<const InputType*, boost::unordered_map<const Factor*, float> > m_cache;

View File

@ -35,8 +35,9 @@ void OpSequenceModel :: readLanguageModel(const char *lmFile)
}
void OpSequenceModel::Load()
void OpSequenceModel::Load(AllOptions::ptr const& opts)
{
m_options = opts;
readLanguageModel(m_lmPath.c_str());
}

View File

@ -25,7 +25,7 @@ public:
~OpSequenceModel();
void readLanguageModel(const char *);
void Load();
void Load(AllOptions::ptr const& opts);
FFState* EvaluateWhenApplied(
const Hypothesis& cur_hypo,

View File

@ -15,7 +15,6 @@
#include "moses/Hypothesis.h"
#include "moses/ChartHypothesis.h"
#include "moses/ChartManager.h"
#include "phrase-extract/extract-ghkm/Alignment.h"
#include <boost/shared_ptr.hpp>
@ -23,15 +22,59 @@ namespace Moses
{
size_t PhraseOrientationFeatureState::hash() const
{
UTIL_THROW2("TODO:Haven't figure this out yet");
if (!m_distinguishStates) {
return 0;
}
size_t ret = 0;
if (m_leftBoundaryIsSet) {
HashCombineLeftBoundaryRecursive(ret, *this, m_useSparseNT);
}
if (m_rightBoundaryIsSet) {
boost::hash_combine(ret, 42);
HashCombineRightBoundaryRecursive(ret, *this, m_useSparseNT);
}
return 0;
}
bool PhraseOrientationFeatureState::operator==(const FFState& other) const
{
UTIL_THROW2("TODO:Haven't figure this out yet");
if (!m_distinguishStates) {
return true;
}
const PhraseOrientationFeatureState &otherState = static_cast<const PhraseOrientationFeatureState&>(other);
if (!m_leftBoundaryIsSet && !otherState.m_leftBoundaryIsSet &&
!m_rightBoundaryIsSet && !otherState.m_rightBoundaryIsSet) {
return true;
}
if (m_leftBoundaryIsSet != otherState.m_leftBoundaryIsSet) {
return false;
}
if (m_rightBoundaryIsSet != otherState.m_rightBoundaryIsSet) {
return false;
}
if (m_leftBoundaryIsSet) {
int compareLeft = CompareLeftBoundaryRecursive(*this, otherState, m_useSparseNT);
if (compareLeft != 0) {
return false;
}
}
if (m_rightBoundaryIsSet) {
int compareRight = CompareRightBoundaryRecursive(*this, otherState, m_useSparseNT);
if (compareRight != 0) {
return false;
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
const std::string PhraseOrientationFeature::MORIENT("M");
const std::string PhraseOrientationFeature::SORIENT("S");
const std::string PhraseOrientationFeature::DORIENT("D");
@ -75,8 +118,9 @@ void PhraseOrientationFeature::SetParameter(const std::string& key, const std::s
}
void PhraseOrientationFeature::Load()
void PhraseOrientationFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
if ( !m_filenameTargetWordList.empty() ) {
LoadWordList(m_filenameTargetWordList,m_targetWordList);
m_useTargetWordList = true;
@ -143,7 +187,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
if (targetPhrase.GetAlignNonTerm().GetSize() != 0) {
// Initialize phrase orientation scoring object
MosesTraining::Syntax::GHKM::PhraseOrientation phraseOrientation(source.GetSize(), targetPhrase.GetSize(),
MosesTraining::PhraseOrientation phraseOrientation(source.GetSize(), targetPhrase.GetSize(),
targetPhrase.GetAlignTerm(), targetPhrase.GetAlignNonTerm());
PhraseOrientationFeature::ReoClassData* reoClassData = new PhraseOrientationFeature::ReoClassData();
@ -159,7 +203,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
// LEFT-TO-RIGHT DIRECTION
MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS l2rOrientation = phraseOrientation.GetOrientationInfo(sourceIndex,sourceIndex,MosesTraining::Syntax::GHKM::PhraseOrientation::REO_DIR_L2R);
MosesTraining::PhraseOrientation::REO_CLASS l2rOrientation = phraseOrientation.GetOrientationInfo(sourceIndex,sourceIndex,MosesTraining::PhraseOrientation::REO_DIR_L2R);
if ( ((targetIndex == 0) || !phraseOrientation.TargetSpanIsAligned(0,targetIndex)) // boundary non-terminal in rule-initial position (left boundary)
&& (targetPhraseLHS != m_glueTargetLHS) ) { // and not glue rule
@ -179,7 +223,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
if (reoClassData->firstNonTerminalPreviousSourceSpanIsAligned &&
reoClassData->firstNonTerminalFollowingSourceSpanIsAligned) {
// discontinuous
l2rOrientation = MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT;
l2rOrientation = MosesTraining::PhraseOrientation::REO_CLASS_DLEFT;
} else {
reoClassData->firstNonTerminalIsBoundary = true;
}
@ -189,7 +233,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
// RIGHT-TO-LEFT DIRECTION
MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS r2lOrientation = phraseOrientation.GetOrientationInfo(sourceIndex,sourceIndex,MosesTraining::Syntax::GHKM::PhraseOrientation::REO_DIR_R2L);
MosesTraining::PhraseOrientation::REO_CLASS r2lOrientation = phraseOrientation.GetOrientationInfo(sourceIndex,sourceIndex,MosesTraining::PhraseOrientation::REO_DIR_R2L);
if ( ((targetIndex == targetPhrase.GetSize()-1) || !phraseOrientation.TargetSpanIsAligned(targetIndex,targetPhrase.GetSize()-1)) // boundary non-terminal in rule-final position (right boundary)
&& (targetPhraseLHS != m_glueTargetLHS) ) { // and not glue rule
@ -209,7 +253,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
if (reoClassData->lastNonTerminalPreviousSourceSpanIsAligned &&
reoClassData->lastNonTerminalFollowingSourceSpanIsAligned) {
// discontinuous
r2lOrientation = MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT;
r2lOrientation = MosesTraining::PhraseOrientation::REO_CLASS_DLEFT;
} else {
reoClassData->lastNonTerminalIsBoundary = true;
}
@ -344,25 +388,25 @@ FFState* PhraseOrientationFeature::EvaluateWhenApplied(
// LEFT-TO-RIGHT DIRECTION
MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS l2rOrientation = reoClassData->nonTerminalReoClassL2R[nNT];
MosesTraining::PhraseOrientation::REO_CLASS l2rOrientation = reoClassData->nonTerminalReoClassL2R[nNT];
IFFEATUREVERBOSE(2) {
FEATUREVERBOSE(2, "l2rOrientation ");
switch (l2rOrientation) {
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_LEFT:
case MosesTraining::PhraseOrientation::REO_CLASS_LEFT:
FEATUREVERBOSE2(2, "mono" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_RIGHT:
case MosesTraining::PhraseOrientation::REO_CLASS_RIGHT:
FEATUREVERBOSE2(2, "swap" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT:
case MosesTraining::PhraseOrientation::REO_CLASS_DLEFT:
FEATUREVERBOSE2(2, "dleft" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DRIGHT:
case MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT:
FEATUREVERBOSE2(2, "dright" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_UNKNOWN:
// modelType == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_MSLR
case MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN:
// modelType == MosesTraining::PhraseOrientation::REO_MSLR
FEATUREVERBOSE2(2, "unknown->dleft" << std::endl);
break;
default:
@ -405,23 +449,23 @@ FFState* PhraseOrientationFeature::EvaluateWhenApplied(
} else {
if ( l2rOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_LEFT ) {
if ( l2rOrientation == MosesTraining::PhraseOrientation::REO_CLASS_LEFT ) {
newScores[0] += TransformScore(orientationPhraseProperty->GetLeftToRightProbabilityMono());
// if sub-derivation has left-boundary non-terminal:
// add recursive actual score of boundary non-terminal from subderivation
LeftBoundaryL2RScoreRecursive(featureID, prevState, 0x1, newScores, accumulator);
} else if ( l2rOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_RIGHT ) {
} else if ( l2rOrientation == MosesTraining::PhraseOrientation::REO_CLASS_RIGHT ) {
newScores[1] += TransformScore(orientationPhraseProperty->GetLeftToRightProbabilitySwap());
// if sub-derivation has left-boundary non-terminal:
// add recursive actual score of boundary non-terminal from subderivation
LeftBoundaryL2RScoreRecursive(featureID, prevState, 0x2, newScores, accumulator);
} else if ( ( l2rOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT ) ||
( l2rOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DRIGHT ) ||
( l2rOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_UNKNOWN ) ) {
} else if ( ( l2rOrientation == MosesTraining::PhraseOrientation::REO_CLASS_DLEFT ) ||
( l2rOrientation == MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT ) ||
( l2rOrientation == MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN ) ) {
newScores[2] += TransformScore(orientationPhraseProperty->GetLeftToRightProbabilityDiscontinuous());
// if sub-derivation has left-boundary non-terminal:
@ -446,25 +490,25 @@ FFState* PhraseOrientationFeature::EvaluateWhenApplied(
// RIGHT-TO-LEFT DIRECTION
MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS r2lOrientation = reoClassData->nonTerminalReoClassR2L[nNT];
MosesTraining::PhraseOrientation::REO_CLASS r2lOrientation = reoClassData->nonTerminalReoClassR2L[nNT];
IFFEATUREVERBOSE(2) {
FEATUREVERBOSE(2, "r2lOrientation ");
switch (r2lOrientation) {
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_LEFT:
case MosesTraining::PhraseOrientation::REO_CLASS_LEFT:
FEATUREVERBOSE2(2, "mono" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_RIGHT:
case MosesTraining::PhraseOrientation::REO_CLASS_RIGHT:
FEATUREVERBOSE2(2, "swap" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT:
case MosesTraining::PhraseOrientation::REO_CLASS_DLEFT:
FEATUREVERBOSE2(2, "dleft" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DRIGHT:
case MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT:
FEATUREVERBOSE2(2, "dright" << std::endl);
break;
case MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_UNKNOWN:
// modelType == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_MSLR
case MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN:
// modelType == MosesTraining::PhraseOrientation::REO_MSLR
FEATUREVERBOSE2(2, "unknown->dleft" << std::endl);
break;
default:
@ -507,23 +551,23 @@ FFState* PhraseOrientationFeature::EvaluateWhenApplied(
} else {
if ( r2lOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_LEFT ) {
if ( r2lOrientation == MosesTraining::PhraseOrientation::REO_CLASS_LEFT ) {
newScores[m_offsetR2LScores+0] += TransformScore(orientationPhraseProperty->GetRightToLeftProbabilityMono());
// if sub-derivation has right-boundary non-terminal:
// add recursive actual score of boundary non-terminal from subderivation
RightBoundaryR2LScoreRecursive(featureID, prevState, 0x1, newScores, accumulator);
} else if ( r2lOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_RIGHT ) {
} else if ( r2lOrientation == MosesTraining::PhraseOrientation::REO_CLASS_RIGHT ) {
newScores[m_offsetR2LScores+1] += TransformScore(orientationPhraseProperty->GetRightToLeftProbabilitySwap());
// if sub-derivation has right-boundary non-terminal:
// add recursive actual score of boundary non-terminal from subderivation
RightBoundaryR2LScoreRecursive(featureID, prevState, 0x2, newScores, accumulator);
} else if ( ( r2lOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT ) ||
( r2lOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DRIGHT ) ||
( r2lOrientation == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_UNKNOWN ) ) {
} else if ( ( r2lOrientation == MosesTraining::PhraseOrientation::REO_CLASS_DLEFT ) ||
( r2lOrientation == MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT ) ||
( r2lOrientation == MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN ) ) {
newScores[m_offsetR2LScores+2] += TransformScore(orientationPhraseProperty->GetRightToLeftProbabilityDiscontinuous());
// if sub-derivation has right-boundary non-terminal:
@ -871,17 +915,17 @@ void PhraseOrientationFeature::SparseNonTerminalR2LScore(const Factor* nonTermin
}
const std::string* PhraseOrientationFeature::ToString(const MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS o) const
const std::string* PhraseOrientationFeature::ToString(const MosesTraining::PhraseOrientation::REO_CLASS o) const
{
if ( o == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_LEFT ) {
if ( o == MosesTraining::PhraseOrientation::REO_CLASS_LEFT ) {
return &MORIENT;
} else if ( o == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_RIGHT ) {
} else if ( o == MosesTraining::PhraseOrientation::REO_CLASS_RIGHT ) {
return &SORIENT;
} else if ( ( o == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DLEFT ) ||
( o == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_DRIGHT ) ||
( o == MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS_UNKNOWN ) ) {
} else if ( ( o == MosesTraining::PhraseOrientation::REO_CLASS_DLEFT ) ||
( o == MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT ) ||
( o == MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN ) ) {
return &DORIENT;
} else {

View File

@ -16,7 +16,7 @@
#include "StatefulFeatureFunction.h"
#include "FFState.h"
#include "moses/Factor.h"
#include "phrase-extract/extract-ghkm/PhraseOrientation.h"
#include "phrase-extract/PhraseOrientation.h"
#include "moses/PP/OrientationPhraseProperty.h"
#include <boost/unordered_set.hpp>
@ -226,6 +226,54 @@ protected:
return CompareRightBoundaryRecursive(*prevState, *otherPrevState, useSparseNT);
};
static void HashCombineLeftBoundaryRecursive(size_t &hash, const PhraseOrientationFeatureState& state, bool useSparseNT) {
if (useSparseNT) {
boost::hash_combine(hash, state.m_leftBoundaryNonTerminalSymbol);
}
// boost::hash_combine(hash, state.m_leftBoundaryNonTerminalL2RHeuristicScoreIndex);
// boost::hash_combine(hash, state.m_leftBoundaryNonTerminalL2RPossibleFutureOrientations);
for (size_t i=0; i<state.m_leftBoundaryNonTerminalL2RScores.size(); ++i) {
if (state.m_leftBoundaryNonTerminalL2RPossibleFutureOrientations[i]) {
boost::hash_combine(hash, state.m_leftBoundaryNonTerminalL2RScores[i]);
} else {
boost::hash_combine(hash, 0);
}
}
if (!state.m_leftBoundaryRecursionGuard) {
const PhraseOrientationFeatureState *prevState = state.m_leftBoundaryPrevState;
if (prevState->m_leftBoundaryIsSet) {
HashCombineLeftBoundaryRecursive(hash, *prevState, useSparseNT);
}
}
};
static void HashCombineRightBoundaryRecursive(size_t &hash, const PhraseOrientationFeatureState& state, bool useSparseNT) {
if (useSparseNT) {
boost::hash_combine(hash, state.m_rightBoundaryNonTerminalSymbol);
}
// boost::hash_combine(hash, state.m_leftBoundaryNonTerminalL2RHeuristicScoreIndex);
// boost::hash_combine(hash, state.m_leftBoundaryNonTerminalL2RPossibleFutureOrientations);
for (size_t i=0; i<state.m_rightBoundaryNonTerminalR2LScores.size(); ++i) {
if (state.m_rightBoundaryNonTerminalR2LPossibleFutureOrientations[i]) {
boost::hash_combine(hash, state.m_rightBoundaryNonTerminalR2LScores[i]);
} else {
boost::hash_combine(hash, 0);
}
}
if (!state.m_rightBoundaryRecursionGuard) {
const PhraseOrientationFeatureState *prevState = state.m_rightBoundaryPrevState;
if (prevState->m_rightBoundaryIsSet) {
HashCombineRightBoundaryRecursive(hash, *prevState, useSparseNT);
}
}
};
template<std::size_t N> static bool Smaller(const std::bitset<N>& x, const std::bitset<N>& y) {
for (size_t i=0; i<N; ++i) {
if (x[i] ^ y[i])
@ -264,8 +312,8 @@ public:
struct ReoClassData {
public:
std::vector<MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS> nonTerminalReoClassL2R;
std::vector<MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS> nonTerminalReoClassR2L;
std::vector<MosesTraining::PhraseOrientation::REO_CLASS> nonTerminalReoClassL2R;
std::vector<MosesTraining::PhraseOrientation::REO_CLASS> nonTerminalReoClassR2L;
bool firstNonTerminalIsBoundary;
bool firstNonTerminalPreviousSourceSpanIsAligned;
bool firstNonTerminalFollowingSourceSpanIsAligned;
@ -289,7 +337,7 @@ public:
void SetParameter(const std::string& key, const std::string& value);
void Load();
void Load(AllOptions::ptr const& opts);
void EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase
@ -351,7 +399,7 @@ protected:
ScoreComponentCollection* scoreBreakdown,
const std::string* o) const;
const std::string* ToString(const MosesTraining::Syntax::GHKM::PhraseOrientation::REO_CLASS o) const;
const std::string* ToString(const MosesTraining::PhraseOrientation::REO_CLASS o) const;
static const std::string MORIENT;
static const std::string SORIENT;

View File

@ -65,8 +65,9 @@ void PhrasePairFeature::SetParameter(const std::string& key, const std::string&
}
}
void PhrasePairFeature::Load()
void PhrasePairFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
if (m_domainTrigger) {
// domain trigger terms for each input document
ifstream inFileSource(m_filePathSource.c_str());

View File

@ -44,7 +44,7 @@ class PhrasePairFeature: public StatelessFeatureFunction
public:
PhrasePairFeature(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
void SetParameter(const std::string& key, const std::string& value);
bool IsUseable(const FactorMask &mask) const;

View File

@ -14,11 +14,11 @@ RuleScope::RuleScope(const std::string &line)
{
}
bool IsAmbiguous(const Word &word, bool sourceSyntax)
{
const Word &inputDefaultNonTerminal = StaticData::Instance().GetInputDefaultNonTerminal();
return word.IsNonTerminal() && (!sourceSyntax || word == inputDefaultNonTerminal);
}
// bool IsAmbiguous(const Word &word, bool sourceSyntax)
// {
// const Word &inputDefaultNonTerminal = StaticData::Instance().GetInputDefaultNonTerminal();
// return word.IsNonTerminal() && (!sourceSyntax || word == inputDefaultNonTerminal);
// }
void RuleScope::EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase

View File

@ -38,7 +38,7 @@ void SoftMatchingFeature::SetParameter(const std::string& key, const std::string
bool SoftMatchingFeature::Load(const std::string& filePath)
{
StaticData &staticData = StaticData::InstanceNonConst();
StaticData &SD = StaticData::InstanceNonConst();
InputFileStream inStream(filePath);
std::string line;
@ -52,14 +52,14 @@ bool SoftMatchingFeature::Load(const std::string& filePath)
}
Word LHS, RHS;
LHS.CreateFromString(Output, staticData.GetOutputFactorOrder(), tokens[0], true);
RHS.CreateFromString(Output, staticData.GetOutputFactorOrder(), tokens[1], true);
LHS.CreateFromString(Output, SD.options()->output.factor_order, tokens[0], true);
RHS.CreateFromString(Output, SD.options()->output.factor_order, tokens[1], true);
m_softMatches[RHS[0]->GetId()].push_back(LHS);
GetOrSetFeatureName(RHS, LHS);
}
staticData.SetSoftMatches(m_softMatches);
SD.SetSoftMatches(m_softMatches);
return true;
}
@ -124,9 +124,10 @@ const std::string& SoftMatchingFeature::GetOrSetFeatureName(const Word& RHS, con
boost::unique_lock<boost::shared_mutex> lock(m_accessLock);
#endif
std::string &name = m_nameCache[RHS[0]->GetId()][LHS[0]->GetId()];
const std::vector<FactorType> &outputFactorOrder = StaticData::Instance().GetOutputFactorOrder();
std::string LHS_string = LHS.GetString(outputFactorOrder, false);
std::string RHS_string = RHS.GetString(outputFactorOrder, false);
const std::vector<FactorType> & oFactors
= StaticData::Instance().options()->output.factor_order;
std::string LHS_string = LHS.GetString(oFactors, false);
std::string RHS_string = RHS.GetString(oFactors, false);
name = LHS_string + "->" + RHS_string;
return name;
}

View File

@ -88,8 +88,9 @@ void SoftSourceSyntacticConstraintsFeature::SetParameter(const std::string& key,
}
}
void SoftSourceSyntacticConstraintsFeature::Load()
void SoftSourceSyntacticConstraintsFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
// don't change the loading order!
LoadSourceLabelSet();
if (!m_coreSourceLabelSetFile.empty()) {
@ -311,8 +312,8 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu
std::vector<float> newScores(m_numScoreComponents,0);
const TreeInput& treeInput = static_cast<const TreeInput&>(input);
const StaticData& staticData = StaticData::Instance();
const Word& outputDefaultNonTerminal = staticData.GetOutputDefaultNonTerminal();
// const StaticData& staticData = StaticData::Instance();
// const Word& outputDefaultNonTerminal = staticData.GetOutputDefaultNonTerminal();
size_t nNTs = 1;
bool treeInputMismatchLHSBinary = true;
@ -365,7 +366,7 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu
for (NonTerminalSet::const_iterator treeInputLabelsIt = treeInputLabels.begin();
treeInputLabelsIt != treeInputLabels.end(); ++treeInputLabelsIt) {
if (*treeInputLabelsIt != outputDefaultNonTerminal) {
if (*treeInputLabelsIt != m_options->syntax.output_default_non_terminal) {
boost::unordered_map<const Factor*,size_t>::const_iterator foundTreeInputLabel
= m_sourceLabelIndexesByFactor.find((*treeInputLabelsIt)[0]);
if (foundTreeInputLabel != m_sourceLabelIndexesByFactor.end()) {
@ -387,7 +388,7 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu
for (NonTerminalSet::const_iterator treeInputLabelsIt = treeInputLabels.begin();
treeInputLabelsIt != treeInputLabels.end(); ++treeInputLabelsIt) {
if (*treeInputLabelsIt != outputDefaultNonTerminal) {
if (*treeInputLabelsIt != m_options->syntax.output_default_non_terminal) {
boost::unordered_map<const Factor*,size_t>::const_iterator foundTreeInputLabel
= m_sourceLabelIndexesByFactor.find((*treeInputLabelsIt)[0]);
if (foundTreeInputLabel != m_sourceLabelIndexesByFactor.end()) {
@ -568,7 +569,9 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu
}
if ( treeInputLabelsLHS.size() == 0 ) {
scoreBreakdown.PlusEquals(this,
"LHSPAIR_" + targetLHS->GetString().as_string() + "_" + outputDefaultNonTerminal[0]->GetString().as_string(),
"LHSPAIR_" + targetLHS->GetString().as_string() + "_"
+ m_options->syntax.output_default_non_terminal[0]
->GetString().as_string(),
1);
if (!m_targetSourceLHSJointCountFile.empty()) {
t2sLabelsScore = TransformScore(m_floor);

View File

@ -31,7 +31,7 @@ public:
void SetParameter(const std::string& key, const std::string& value);
void Load();
void Load(AllOptions::ptr const& opts);
void EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase

View File

@ -47,11 +47,12 @@ void SourceGHKMTreeInputMatchFeature::EvaluateWithSourceContext(const InputType
const Word& lhsLabel = targetPhrase.GetTargetLHS();
const StaticData& staticData = StaticData::Instance();
const Word& outputDefaultNonTerminal = staticData.GetOutputDefaultNonTerminal();
std::vector<float> newScores(m_numScoreComponents,0.0); // m_numScoreComponents == 2 // first fires for matches, second for mismatches
std::vector<float> newScores(m_numScoreComponents,0.0);
// m_numScoreComponents == 2 // first fires for matches, second for mismatches
if ( (treeInputLabels.find(lhsLabel) != treeInputLabels.end()) && (lhsLabel != outputDefaultNonTerminal) ) {
if ( (treeInputLabels.find(lhsLabel) != treeInputLabels.end())
&& (lhsLabel != m_options->syntax.output_default_non_terminal) ) {
// match
newScores[0] = 1.0;
} else {
@ -62,6 +63,13 @@ void SourceGHKMTreeInputMatchFeature::EvaluateWithSourceContext(const InputType
scoreBreakdown.PlusEquals(this, newScores);
}
void
SourceGHKMTreeInputMatchFeature::
Load(AllOptions::ptr const& opts)
{
m_options = opts;
// m_output_default_nonterminal = opts->syntax.output_default_non_terminal;
}
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "StatelessFeatureFunction.h"
#include "moses/parameters/AllOptions.h"
namespace Moses
{
@ -40,6 +41,7 @@ public:
void EvaluateWhenApplied(const ChartHypothesis &hypo,
ScoreComponentCollection* accumulator) const {};
void Load(AllOptions::ptr const& opts);
};

View File

@ -36,8 +36,9 @@ void SourceWordDeletionFeature::SetParameter(const std::string& key, const std::
}
}
void SourceWordDeletionFeature::Load()
void SourceWordDeletionFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
if (m_filename.empty())
return;

View File

@ -23,7 +23,7 @@ private:
public:
SourceWordDeletionFeature(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
bool IsUseable(const FactorMask &mask) const;

View File

@ -48,8 +48,9 @@ void TargetBigramFeature::SetParameter(const std::string& key, const std::string
}
}
void TargetBigramFeature::Load()
void TargetBigramFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
if (m_filePath == "*")
return ; //allow all
ifstream inFile(m_filePath.c_str());

View File

@ -34,7 +34,7 @@ class TargetBigramFeature : public StatefulFeatureFunction
public:
TargetBigramFeature(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
bool IsUseable(const FactorMask &mask) const;

View File

@ -74,8 +74,9 @@ void TargetNgramFeature::SetParameter(const std::string& key, const std::string&
}
}
void TargetNgramFeature::Load()
void TargetNgramFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
if (m_file == "") return; //allow all, for now
if (m_file == "*") return; //allow all

View File

@ -203,7 +203,7 @@ class TargetNgramFeature : public StatefulFeatureFunction
public:
TargetNgramFeature(const std::string &line);
void Load();
void Load(AllOptions::ptr const& opts);
bool IsUseable(const FactorMask &mask) const;

View File

@ -34,8 +34,9 @@ void TargetWordInsertionFeature::SetParameter(const std::string& key, const std:
}
}
void TargetWordInsertionFeature::Load()
void TargetWordInsertionFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
if (m_filename.empty())
return;

View File

@ -25,7 +25,7 @@ public:
bool IsUseable(const FactorMask &mask) const;
void Load();
void Load(AllOptions::ptr const& opts);
virtual void EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase

View File

@ -8,8 +8,9 @@
namespace Moses
{
void TreeStructureFeature::Load()
void TreeStructureFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
// syntactic constraints can be hooked in here.
m_constraints = NULL;

View File

@ -74,7 +74,7 @@ public:
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const;
void Load();
void Load(AllOptions::ptr const& opts);
};

View File

@ -72,7 +72,7 @@ private:
std::string MakeNGram(const TargetPhrase &phrase, size_t start, size_t end) const {
std::vector<std::string> words;
while (start != end) {
words.push_back(phrase.GetWord(start).GetString(StaticData::Instance().GetOutputFactorOrder(), false));
words.push_back(phrase.GetWord(start).GetString(StaticData::Instance().options().output.factor_order, false));
start++;
}
return Join(" ", words);

View File

@ -168,7 +168,7 @@ public:
const std::vector<VWFeatureBase*>& targetFeatures =
VWFeatureBase::GetTargetFeatures(GetScoreProducerDescription());
const WordsRange &sourceRange = translationOptionList.Get(0)->GetSourceWordsRange();
const Range &sourceRange = translationOptionList.Get(0)->GetSourceWordsRange();
const InputPath &inputPath = translationOptionList.Get(0)->GetInputPath();
if (m_train) {
@ -323,7 +323,7 @@ public:
Phrase *target = new Phrase();
target->CreateFromString(
Output
, StaticData::Instance().GetOutputFactorOrder()
, StaticData::Instance().options().output.factor_order
, tabbedSentence.GetColumns()[0]
, NULL);

View File

@ -81,7 +81,7 @@ public:
// source sentence word range.
virtual void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const = 0;
// Overload to process target-dependent features, create features once for

View File

@ -19,7 +19,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
for (size_t i = 0; i < input.GetSize(); i++) {
classifier.AddLabelIndependentFeature("bow^" + GetWord(input, i));

View File

@ -19,7 +19,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
for (size_t i = 1; i < input.GetSize(); i++) {
classifier.AddLabelIndependentFeature("bigram^" + GetWord(input, i - 1) + "^" + GetWord(input, i));

View File

@ -24,7 +24,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
const Features& features = *m_tls.GetStored();
for (size_t i = 0; i < features.size(); i++) {

View File

@ -21,7 +21,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
size_t begin = sourceRange.GetStartPos();
size_t end = sourceRange.GetEndPos() + 1;

View File

@ -21,7 +21,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
size_t begin = sourceRange.GetStartPos();
size_t end = sourceRange.GetEndPos() + 1;

View File

@ -52,7 +52,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
int begin = sourceRange.GetStartPos();
int end = sourceRange.GetEndPos() + 1;

View File

@ -21,7 +21,7 @@ public:
void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
int begin = sourceRange.GetStartPos();
int end = sourceRange.GetEndPos() + 1;

View File

@ -24,7 +24,7 @@ public:
virtual void operator()(const InputType &input
, const InputPath &inputPath
, const WordsRange &sourceRange
, const Range &sourceRange
, Discriminative::Classifier &classifier) const {
}

View File

@ -87,8 +87,9 @@ void WordTranslationFeature::SetParameter(const std::string& key, const std::str
}
}
void WordTranslationFeature::Load()
void WordTranslationFeature::Load(AllOptions::ptr const& opts)
{
m_options = opts;
// load word list for restricted feature set
if (m_filePathSource.empty()) {
return;

View File

@ -40,7 +40,7 @@ public:
void SetParameter(const std::string& key, const std::string& value);
bool IsUseable(const FactorMask &mask) const;
void Load();
void Load(AllOptions::ptr const& opts);
void EvaluateWithSourceContext(const InputType &input
, const InputPath &inputPath

View File

@ -18,9 +18,7 @@ namespace Moses
//! populate this InputType with data from in stream
int ForestInput::
Read(std::istream &in,
std::vector<FactorType> const& factorOrder,
AllOptions const& opts)
Read(std::istream &in)
{
using Syntax::F2S::Forest;
@ -48,7 +46,7 @@ Read(std::istream &in,
std::getline(in, line);
} else {
do {
ParseHyperedgeLine(line, factorOrder);
ParseHyperedgeLine(line);
std::getline(in, line);
} while (line != "");
}
@ -58,7 +56,7 @@ Read(std::istream &in,
// not sure ForestInput needs to.
std::stringstream strme;
strme << "<s> " << sentence << " </s>" << std::endl;
Sentence::Read(strme, factorOrder, opts);
Sentence::Read(strme);
// Find the maximum end position of any vertex (0 if forest is empty).
std::size_t maxEnd = FindMaxEnd(*m_forest);
@ -70,6 +68,9 @@ Read(std::istream &in,
assert(topVertices.size() >= 1);
}
const std::vector<FactorType>& factorOrder = m_options->input.factor_order;
// Add <s> vertex.
Forest::Vertex *startSymbol = NULL;
{
@ -122,7 +123,9 @@ Read(std::istream &in,
return 1;
}
Syntax::F2S::Forest::Vertex *ForestInput::AddOrDeleteVertex(Forest::Vertex *v)
Syntax::F2S::Forest::Vertex*
ForestInput::
AddOrDeleteVertex(Forest::Vertex *v)
{
std::pair<VertexSet::iterator, bool> ret = m_vertexSet.insert(v);
if (ret.second) {
@ -172,14 +175,16 @@ void ForestInput::FindTopVertices(Forest &forest,
std::back_inserter(topVertices));
}
void ForestInput::ParseHyperedgeLine(
const std::string &line, const std::vector<FactorType>& factorOrder)
void
ForestInput::
ParseHyperedgeLine(const std::string &line)
{
const std::vector<FactorType>& factorOrder = m_options->input.factor_order;
using Syntax::F2S::Forest;
const util::AnyCharacter delimiter(" \t");
util::TokenIter<util::AnyCharacter, true> p(line, delimiter);
Forest::Vertex *v = AddOrDeleteVertex(ParseVertex(*p, factorOrder));
Forest::Vertex *v = AddOrDeleteVertex(ParseVertex(*p));
Forest::Hyperedge *e = new Forest::Hyperedge();
e->head = v;
++p;
@ -188,7 +193,7 @@ void ForestInput::ParseHyperedgeLine(
//throw Exception("");
}
for (++p; *p != "|||"; ++p) {
v = ParseVertex(*p, factorOrder);
v = ParseVertex(*p);
if (!v->pvertex.symbol.IsNonTerminal()) {
// Egret does not give start/end for terminals.
v->pvertex.span = Range(e->head->pvertex.span.GetStartPos(),
@ -203,11 +208,11 @@ void ForestInput::ParseHyperedgeLine(
e->head->incoming.push_back(e);
}
Syntax::F2S::Forest::Vertex *ForestInput::ParseVertex(
const StringPiece &s, const std::vector<FactorType>& factorOrder)
Syntax::F2S::Forest::Vertex*
ForestInput::ParseVertex(const StringPiece &s)
{
using Syntax::F2S::Forest;
const std::vector<FactorType>& factorOrder = m_options->input.factor_order;
Word symbol;
std::size_t pos = s.rfind('[');
if (pos == std::string::npos) {

View File

@ -21,7 +21,7 @@ class ForestInput : public Sentence
public:
friend std::ostream &operator<<(std::ostream&, const ForestInput &);
ForestInput() : Sentence(), m_rootVertex(NULL) {}
ForestInput(AllOptions::ptr const& opts) : Sentence(opts), m_rootVertex(NULL) {}
InputTypeEnum GetType() const {
return ForestInputType;
@ -29,9 +29,7 @@ public:
//! populate this InputType with data from in stream
virtual int
Read(std::istream& in,
std::vector<FactorType> const& factorOrder,
AllOptions const& opts);
Read(std::istream& in);
//! Output debugging info to stream out
virtual void Print(std::ostream&) const;
@ -76,11 +74,9 @@ private:
void FindTopVertices(Forest &, std::vector<Forest::Vertex *> &);
void ParseHyperedgeLine(const std::string &,
const std::vector<FactorType> &);
void ParseHyperedgeLine(const std::string &);
Forest::Vertex *ParseVertex(const StringPiece &,
const std::vector<FactorType> &);
Forest::Vertex *ParseVertex(const StringPiece &);
boost::shared_ptr<Forest> m_forest;
Forest::Vertex *m_rootVertex;

View File

@ -44,8 +44,9 @@ GenerationDictionary::GenerationDictionary(const std::string &line)
ReadParameters();
}
void GenerationDictionary::Load()
void GenerationDictionary::Load(AllOptions::ptr const& opts)
{
m_options = opts;
FactorCollection &factorCollection = FactorCollection::Instance();
const size_t numFeatureValuesInConfig = this->GetNumScoreComponents();

View File

@ -62,7 +62,7 @@ public:
virtual ~GenerationDictionary();
//! load data file
void Load();
void Load(AllOptions::ptr const& opts);
/** number of unique input entries in the generation table.
* NOT the number of lines in the generation table

View File

@ -56,7 +56,7 @@ WriteHypos(const ChartHypothesisCollection& hypos,
ChartHypothesisCollection::const_iterator iter;
for (iter = hypos.begin() ; iter != hypos.end() ; ++iter) {
ChartHypothesis &mainHypo = **iter;
if (StaticData::Instance().options().output.DontPruneSearchGraph ||
if (StaticData::Instance().options()->output.DontPruneSearchGraph ||
reachable.find(mainHypo.GetId()) != reachable.end()) {
(*m_out) << m_lineNumber << " " << mainHypo << endl;
}
@ -90,7 +90,7 @@ WriteHypos(const ChartHypothesisCollection& hypos,
ChartHypothesisCollection::const_iterator iter;
for (iter = hypos.begin() ; iter != hypos.end() ; ++iter) {
const ChartHypothesis* mainHypo = *iter;
if (!StaticData::Instance().options().output.DontPruneSearchGraph &&
if (!StaticData::Instance().options()->output.DontPruneSearchGraph &&
reachable.find(mainHypo->GetId()) == reachable.end()) {
//Ignore non reachable nodes
continue;

View File

@ -337,57 +337,22 @@ GetTargetPhraseStringRep() const
return GetTargetPhraseStringRep(allFactors);
}
void
size_t
Hypothesis::
OutputAlignment(std::ostream &out, WordAlignmentSort sortOrder) const
OutputAlignment(std::ostream &out, bool recursive=true) const
{
std::vector<const Hypothesis *> edges;
const Hypothesis *currentHypo = this;
while (currentHypo) {
edges.push_back(currentHypo);
currentHypo = currentHypo->GetPrevHypo();
}
WordAlignmentSort const& waso = m_manager.options()->output.WA_SortOrder;
TargetPhrase const& tp = GetCurrTargetPhrase();
OutputAlignment(out, edges, sortOrder);
}
void
Hypothesis::
OutputAlignment(ostream &out,
vector<const Hypothesis *> const& edges,
WordAlignmentSort waso)
{
size_t targetOffset = 0;
for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--) {
const Hypothesis &edge = *edges[currEdge];
const TargetPhrase &tp = edge.GetCurrTargetPhrase();
size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos();
OutputAlignment(out, tp.GetAlignTerm(), sourceOffset, targetOffset, waso);
targetOffset += tp.GetSize();
}
// Used by --print-alignment-info, so no endl
}
void
Hypothesis::
OutputAlignment(ostream &out, const AlignmentInfo &ai,
size_t sourceOffset, size_t targetOffset,
WordAlignmentSort waso)
{
typedef std::vector< const std::pair<size_t,size_t>* > AlignVec;
AlignVec alignments = ai.GetSortedAlignments(waso);
AlignVec::const_iterator it;
for (it = alignments.begin(); it != alignments.end(); ++it) {
const std::pair<size_t,size_t> &alignment = **it;
out << alignment.first + sourceOffset << "-"
<< alignment.second + targetOffset << " ";
}
// call with head recursion to output things in the right order
size_t trg_off = recursive && m_prevHypo ? m_prevHypo->OutputAlignment(out) : 0;
size_t src_off = GetCurrSourceWordsRange().GetStartPos();
typedef std::pair<size_t,size_t> const* entry;
std::vector<entry> alnvec = tp.GetAlignTerm().GetSortedAlignments(waso);
BOOST_FOREACH(entry e, alnvec)
out << e->first + src_off << "-" << e->second + trg_off << " ";
return trg_off + tp.GetSize();
}
void
@ -411,102 +376,6 @@ OutputInput(std::ostream& os) const
if (inp_phrases[i]) os << *inp_phrases[i];
}
void
Hypothesis::
OutputBestSurface(std::ostream &out, const std::vector<FactorType> &outputFactorOrder,
const ReportingOptions &options) const
{
if (m_prevHypo) {
// recursively retrace this best path through the lattice, starting from the end of the hypothesis sentence
m_prevHypo->OutputBestSurface(out, outputFactorOrder, options);
}
OutputSurface(out, *this, outputFactorOrder, options);
}
//////////////////////////////////////////////////////////////////////////
/***
* print surface factor only for the given phrase
*/
void
Hypothesis::
OutputSurface(std::ostream &out, const Hypothesis &edge,
const std::vector<FactorType> &outputFactorOrder,
const ReportingOptions &options) const
{
UTIL_THROW_IF2(outputFactorOrder.size() == 0,
"Must specific at least 1 output factor");
const TargetPhrase& phrase = edge.GetCurrTargetPhrase();
// TODO: slay the rest of StaticData here and move stuff into ReportingOptions
bool markUnknown = GetManager().options().unk.mark;
bool featureLabels = StaticData::Instance().options().nbest.include_feature_labels;
if (options.ReportAllFactors == true) {
out << phrase;
} else {
FactorType placeholderFactor
= StaticData::Instance().options().input.placeholder_factor;
std::map<size_t, const Factor*> placeholders;
if (placeholderFactor != NOT_FOUND) {
// creates map of target position -> factor for placeholders
placeholders = GetPlaceholders(edge, placeholderFactor);
}
size_t size = phrase.GetSize();
for (size_t pos = 0 ; pos < size ; pos++) {
const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[0]);
if (placeholders.size()) {
// do placeholders
std::map<size_t, const Factor*>::const_iterator iter = placeholders.find(pos);
if (iter != placeholders.end()) {
factor = iter->second;
}
}
UTIL_THROW_IF2(factor == NULL,
"No factor 0 at position " << pos);
//preface surface form with UNK if marking unknowns
const Word &word = phrase.GetWord(pos);
if(markUnknown && word.IsOOV()) {
out << GetManager().options().unk.prefix << *factor
<< GetManager().options().unk.suffix;
} else {
out << *factor;
}
for (size_t i = 1 ; i < outputFactorOrder.size() ; i++) {
const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[i]);
UTIL_THROW_IF2(factor == NULL,
"No factor " << i << " at position " << pos);
out << "|" << *factor;
}
out << " ";
}
}
// trace ("report segmentation") option "-t" / "-tt"
if (options.ReportSegmentation > 0 && phrase.GetSize() > 0) {
const Range &sourceRange = edge.GetCurrSourceWordsRange();
const int sourceStart = sourceRange.GetStartPos();
const int sourceEnd = sourceRange.GetEndPos();
out << "|" << sourceStart << "-" << sourceEnd; // enriched "-tt"
if (options.ReportSegmentation == 2) {
out << ",wa=";
const AlignmentInfo &ai = edge.GetCurrTargetPhrase().GetAlignTerm();
Hypothesis::OutputAlignment(out, ai, 0, 0, options.WA_SortOrder);
out << ",total=";
out << edge.GetScore() - edge.GetPrevHypo()->GetScore();
out << ",";
ScoreComponentCollection scoreBreakdown(edge.GetScoreBreakdown());
scoreBreakdown.MinusEquals(edge.GetPrevHypo()->GetScoreBreakdown());
scoreBreakdown.OutputAllFeatureScores(out, featureLabels);
}
out << "| ";
}
}
std::map<size_t, const Factor*>
Hypothesis::
GetPlaceholders(const Hypothesis &hypo, FactorType placeholderFactor) const

View File

@ -209,8 +209,8 @@ public:
return m_arcList;
}
const ScoreComponentCollection& GetScoreBreakdown() const {
if (!m_scoreBreakdown.get()) {
m_scoreBreakdown.reset(new ScoreComponentCollection());
if (!m_scoreBreakdown) {
m_scoreBreakdown.reset(new ScoreComponentCollection);
m_scoreBreakdown->PlusEquals(m_currScoreBreakdown);
if (m_prevHypo) {
m_scoreBreakdown->PlusEquals(m_prevHypo->GetScoreBreakdown());
@ -239,26 +239,11 @@ public:
return m_transOpt;
}
void
OutputAlignment(std::ostream &out, WordAlignmentSort sortOrder) const;
static void
OutputAlignment(std::ostream &out,
const std::vector<const Hypothesis *> &edges,
WordAlignmentSort waso);
static void
OutputAlignment(std::ostream &out, const Moses::AlignmentInfo &ai,
size_t sourceOffset, size_t targetOffset,
WordAlignmentSort waso);
size_t OutputAlignment(std::ostream &out, bool recursive) const;
void OutputInput(std::ostream& os) const;
static void OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo);
void OutputBestSurface(std::ostream &out, const std::vector<Moses::FactorType> &outputFactorOrder, const ReportingOptions &options) const;
void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<FactorType> &outputFactorOrder,
const ReportingOptions &options) const;
// creates a map of TARGET positions which should be replaced by word using placeholder
std::map<size_t, const Moses::Factor*> GetPlaceholders(const Moses::Hypothesis &hypo, Moses::FactorType placeholderFactor) const;

View File

@ -36,10 +36,10 @@ namespace Moses
HypothesisStackCubePruning::HypothesisStackCubePruning(Manager& manager) :
HypothesisStack(manager)
{
m_nBestIsEnabled = manager.options().nbest.enabled;
m_nBestIsEnabled = manager.options()->nbest.enabled;
m_bestScore = -std::numeric_limits<float>::infinity();
m_worstScore = -std::numeric_limits<float>::infinity();
m_deterministic = manager.options().cube.deterministic_search;
m_deterministic = manager.options()->cube.deterministic_search;
}
/** remove all hypotheses from the collection */
@ -244,7 +244,7 @@ void HypothesisStackCubePruning::CleanupArcList()
iterator iter;
for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) {
Hypothesis *mainHypo = *iter;
mainHypo->CleanupArcList(this->m_manager.options().nbest.nbest_size, this->m_manager.options().NBestDistinct());
mainHypo->CleanupArcList(this->m_manager.options()->nbest.nbest_size, this->m_manager.options()->NBestDistinct());
}
}

View File

@ -25,7 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "HypothesisStackNormal.h"
#include "TypeDef.h"
#include "Util.h"
#include "StaticData.h"
#include "Manager.h"
#include "util/exception.hh"
@ -36,7 +35,7 @@ namespace Moses
HypothesisStackNormal::HypothesisStackNormal(Manager& manager) :
HypothesisStack(manager)
{
m_nBestIsEnabled = manager.options().nbest.enabled;
m_nBestIsEnabled = manager.options()->nbest.enabled;
m_bestScore = -std::numeric_limits<float>::infinity();
m_worstScore = -std::numeric_limits<float>::infinity();
}
@ -75,8 +74,12 @@ pair<HypothesisStackNormal::iterator, bool> HypothesisStackNormal::Add(Hypothesi
// prune only if stack is twice as big as needed (lazy pruning)
size_t toleratedSize = 2*m_maxHypoStackSize-1;
// add in room for stack diversity
if (m_minHypoStackDiversity)
toleratedSize += m_minHypoStackDiversity << StaticData::Instance().GetMaxDistortion();
if (m_minHypoStackDiversity) {
// so what happens if maxdistortion is negative?
toleratedSize += m_minHypoStackDiversity
<< m_manager.options()->reordering.max_distortion;
}
if (m_hypos.size() > toleratedSize) {
PruneToSize(m_maxHypoStackSize);
} else {
@ -97,8 +100,8 @@ bool HypothesisStackNormal::AddPrune(Hypothesis *hypo)
}
// too bad for stack. don't bother adding hypo into collection
if (!StaticData::Instance().GetDisableDiscarding() &&
hypo->GetFutureScore() < m_worstScore
if (m_manager.options()->search.disable_discarding == false
&& hypo->GetFutureScore() < m_worstScore
&& ! ( m_minHypoStackDiversity > 0
&& hypo->GetFutureScore() >= GetWorstScoreForBitmap( hypo->GetWordsBitmap() ) ) ) {
m_manager.GetSentenceStats().AddDiscarded();
@ -266,7 +269,7 @@ void HypothesisStackNormal::CleanupArcList()
iterator iter;
for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) {
Hypothesis *mainHypo = *iter;
mainHypo->CleanupArcList(this->m_manager.options().nbest.nbest_size, this->m_manager.options().NBestDistinct());
mainHypo->CleanupArcList(this->m_manager.options()->nbest.nbest_size, this->m_manager.options()->NBestDistinct());
}
}

View File

@ -63,8 +63,9 @@ using namespace std;
namespace Moses
{
IOWrapper::IOWrapper()
: m_nBestStream(NULL)
IOWrapper::IOWrapper(AllOptions const& opts)
: m_options(new AllOptions(opts))
, m_nBestStream(NULL)
, m_surpressSingleBestOutput(false)
, m_look_ahead(0)
, m_look_back(0)
@ -77,20 +78,19 @@ IOWrapper::IOWrapper()
Parameter const& P = staticData.GetParameter();
// context buffering for context-sensitive decoding
m_look_ahead = staticData.options().context.look_ahead;
m_look_back = staticData.options().context.look_back;
m_inputType = staticData.options().input.input_type;
m_look_ahead = staticData.options()->context.look_ahead;
m_look_back = staticData.options()->context.look_back;
m_inputType = staticData.options()->input.input_type;
UTIL_THROW_IF2((m_look_ahead || m_look_back) && m_inputType != SentenceInput,
"Context-sensitive decoding currently works only with sentence input.");
m_currentLine = staticData.GetStartTranslationId();
m_inputFactorOrder = &staticData.GetInputFactorOrder();
m_inputFactorOrder = &staticData.options()->input.factor_order;
size_t nBestSize = staticData.options().nbest.nbest_size;
string nBestFilePath = staticData.options().nbest.output_file_path;
size_t nBestSize = staticData.options()->nbest.nbest_size;
string nBestFilePath = staticData.options()->nbest.output_file_path;
staticData.GetParameter().SetParameter<string>(m_inputFilePath, "input-file", "");
if (m_inputFilePath.empty()) {
@ -129,8 +129,8 @@ IOWrapper::IOWrapper()
P.SetParameter<string>(path, "output-word-graph", "");
if (path.size()) m_wordGraphCollector.reset(new OutputCollector(path));
size_t latticeSamplesSize = staticData.GetLatticeSamplesSize();
string latticeSamplesFile = staticData.GetLatticeSamplesFilePath();
size_t latticeSamplesSize = staticData.options()->output.lattice_sample_size;
string latticeSamplesFile = staticData.options()->output.lattice_sample_filepath;
if (latticeSamplesSize) {
m_latticeSamplesCollector.reset(new OutputCollector(latticeSamplesFile));
if (m_latticeSamplesCollector->OutputIsCout()) {

View File

@ -61,8 +61,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "moses/LatticeMBR.h"
#include "moses/ChartKBestExtractor.h"
#include "moses/Syntax/KBestExtractor.h"
#include "moses/parameters/AllOptions.h"
#include <boost/format.hpp>
#include <boost/shared_ptr.hpp>
namespace Moses
{
@ -81,6 +83,7 @@ struct SHyperedge;
class IOWrapper
{
protected:
boost::shared_ptr<AllOptions const> m_options;
const std::vector<Moses::FactorType> *m_inputFactorOrder;
std::string m_inputFilePath;
Moses::InputFileStream *m_inputFile;
@ -124,7 +127,7 @@ protected:
std::string m_hypergraph_output_filepattern;
public:
IOWrapper();
IOWrapper(AllOptions const& opts);
~IOWrapper();
// Moses::InputType* GetInput(Moses::InputType *inputType);
@ -216,7 +219,6 @@ boost::shared_ptr<InputType>
IOWrapper::
BufferInput()
{
AllOptions const& opts = StaticData::Instance().options();
boost::shared_ptr<itype> source;
boost::shared_ptr<InputType> ret;
if (m_future_input.size()) {
@ -224,14 +226,14 @@ BufferInput()
m_future_input.pop_front();
m_buffered_ahead -= ret->GetSize();
} else {
source.reset(new itype);
if (!source->Read(*m_inputStream, *m_inputFactorOrder, opts))
source.reset(new itype(m_options));
if (!source->Read(*m_inputStream))
return ret;
ret = source;
}
while (m_buffered_ahead < m_look_ahead) {
source.reset(new itype);
if (!source->Read(*m_inputStream, *m_inputFactorOrder, opts))
source.reset(new itype(m_options));
if (!source->Read(*m_inputStream))
break;
m_future_input.push_back(source);
m_buffered_ahead += source->GetSize();

View File

@ -208,7 +208,7 @@ Manager::Manager(ttasksptr const& ttask)
: BaseManager(ttask)
, cells_(m_source, ChartCellBaseFactory(), parser_)
, parser_(ttask, cells_)
, n_best_(search::NBestConfig(StaticData::Instance().options().nbest.nbest_size))
, n_best_(search::NBestConfig(StaticData::Instance().options()->nbest.nbest_size))
{ }
Manager::~Manager()
@ -232,8 +232,8 @@ PopulateBest(const Model &model, const std::vector<lm::WordIndex> &words, Best &
const StaticData &data = StaticData::Instance();
const float lm_weight = data.GetWeights(&abstract)[0];
const float oov_weight = abstract.OOVFeatureEnabled() ? data.GetWeights(&abstract)[1] : 0.0;
size_t cpl = data.options().cube.pop_limit;
size_t nbs = data.options().nbest.nbest_size;
size_t cpl = data.options()->cube.pop_limit;
size_t nbs = data.options()->nbest.nbest_size;
search::Config config(lm_weight * log_10, cpl, search::NBestConfig(nbs));
search::Context<Model> context(config, model);
@ -261,7 +261,7 @@ PopulateBest(const Model &model, const std::vector<lm::WordIndex> &words, Best &
template <class Model> void Manager::LMCallback(const Model &model, const std::vector<lm::WordIndex> &words)
{
std::size_t nbest = StaticData::Instance().options().nbest.nbest_size;
std::size_t nbest = StaticData::Instance().options()->nbest.nbest_size;
if (nbest <= 1) {
search::History ret = PopulateBest(model, words, single_best_);
if (ret) {
@ -329,7 +329,7 @@ OutputNBestList(OutputCollector *collector,
{
const StaticData &staticData = StaticData::Instance();
const std::vector<Moses::FactorType> &outputFactorOrder
= staticData.GetOutputFactorOrder();
= options()->output.factor_order;
std::ostringstream out;
// wtf? copied from the original OutputNBestList
@ -351,7 +351,7 @@ OutputNBestList(OutputCollector *collector,
out << translationId << " ||| ";
OutputSurface(out, outputPhrase); // , outputFactorOrder, false);
out << " ||| ";
bool with_labels = options().nbest.include_feature_labels;
bool with_labels = options()->nbest.include_feature_labels;
features.OutputAllFeatureScores(out, with_labels);
out << " ||| " << i->GetScore() << '\n';
}
@ -509,7 +509,7 @@ void Manager::OutputBestHypo(OutputCollector *collector, search::Applied applied
if (collector == NULL) return;
std::ostringstream out;
FixPrecision(out);
if (options().output.ReportHypoScore) {
if (options()->output.ReportHypoScore) {
out << applied.GetScore() << ' ';
}
Phrase outPhrase;
@ -519,7 +519,7 @@ void Manager::OutputBestHypo(OutputCollector *collector, search::Applied applied
"Output phrase should have contained at least 2 words (beginning and end-of-sentence)");
outPhrase.RemoveWord(0);
outPhrase.RemoveWord(outPhrase.GetSize() - 1);
out << outPhrase.GetStringRep(StaticData::Instance().GetOutputFactorOrder());
out << outPhrase.GetStringRep(options()->output.factor_order);
out << '\n';
collector->Write(translationId, out.str());
@ -531,7 +531,7 @@ Manager::
OutputBestNone(OutputCollector *collector, long translationId) const
{
if (collector == NULL) return;
if (options().output.ReportHypoScore) {
if (options()->output.ReportHypoScore) {
collector->Write(translationId, "0 \n");
} else {
collector->Write(translationId, "\n");

View File

@ -29,8 +29,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
namespace Moses
{
InputType::InputType(long translationId)
: m_translationId(translationId)
InputType::InputType(AllOptions::ptr const& opts, long translationId)
: m_options(opts)
, m_translationId(translationId)
, m_reorderingConstraint(opts->reordering.max_distortion)
{
m_frontSpanCoveredLength = 0;
m_sourceCompleted.resize(0);

View File

@ -45,6 +45,7 @@ class TranslationTask;
class InputType
{
protected:
AllOptions::ptr m_options;
long m_translationId; //< contiguous Id
long m_documentId;
long m_topicId;
@ -67,11 +68,15 @@ public:
size_t m_frontSpanCoveredLength;
// how many words from the beginning are covered
InputType(long translationId = 0);
InputType(AllOptions::ptr const& opts, long translationId = 0);
virtual ~InputType();
virtual InputTypeEnum GetType() const = 0;
AllOptions::ptr const& options() const {
return m_options;
}
long GetTranslationId() const {
return m_translationId;
}
@ -185,9 +190,10 @@ public:
//! populate this InputType with data from in stream
virtual int
Read(std::istream& in,
std::vector<FactorType> const& factorOrder,
AllOptions const& opts) =0;
Read(std::istream& in) = 0;
// ,
// std::vector<FactorType> const& factorOrder,
// AllOptions const& opts) =0;
//! Output debugging info to stream out
virtual void Print(std::ostream&) const =0;

View File

@ -105,7 +105,7 @@ lib moses :
TranslationModel/RuleTable/*.cpp
TranslationModel/Scope3Parser/*.cpp
TranslationModel/CYKPlusParser/*.cpp
../phrase-extract/extract-ghkm/PhraseOrientation.cpp
../phrase-extract/PhraseOrientation.cpp
FF/*.cpp
FF/bilingual-lm/*.cpp
FF/OSM-Feature/*.cpp

View File

@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "moses/TypeDef.h"
#include "moses/StaticData.h"
#include "moses/parameters/AllOptions.h"
//#include "BackwardLMState.h"
#include "moses/LM/Backward.h"
@ -61,12 +62,14 @@ namespace Moses
// Apparently some Boost versions use templates and are pretty strict about types matching.
#define SLOPPY_CHECK_CLOSE(ref, value, tol) BOOST_CHECK_CLOSE(static_cast<double>(ref), static_cast<double>(value), static_cast<double>(tol));
AllOptions::ptr DefaultOptions(new AllOptions);
class BackwardLanguageModelTest
{
public:
BackwardLanguageModelTest() :
dummyInput(new Sentence),
dummyInput(new Sentence(DefaultOptions)),
backwardLM(
static_cast< BackwardLanguageModel<lm::ngram::ProbingModel> * >(
ConstructBackwardLM(

View File

@ -20,8 +20,9 @@ BilingualLM::BilingualLM(const std::string &line)
}
void BilingualLM::Load()
void BilingualLM::Load(AllOptions::ptr const& opts)
{
m_options = opts;
ReadParameters();
loadModel();
}

View File

@ -117,7 +117,7 @@ public:
return new BilingualLMState(0);
}
void Load();
void Load(AllOptions::ptr const& opts);
FFState* EvaluateWhenApplied(
const Hypothesis& cur_hypo,

View File

@ -204,7 +204,7 @@ LanguageModelDALM::~LanguageModelDALM()
delete m_lm;
}
void LanguageModelDALM::Load()
void LanguageModelDALM::Load(AllOptions const& opts)
{
/////////////////////
// READING INIFILE //

View File

@ -28,7 +28,7 @@ public:
LanguageModelDALM(const std::string &line);
virtual ~LanguageModelDALM();
void Load();
void Load(AllOptions::ptr const& opts);
virtual const FFState *EmptyHypothesisState(const InputType &/*input*/) const;

Some files were not shown because too many files have changed in this diff Show More