mosesdecoder/moses/parameters/InputOptions.cpp

106 lines
3.1 KiB
C++
Raw Normal View History

2015-08-05 04:15:34 +03:00
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
#include "InputOptions.h"
#include <vector>
#include <iostream>
2015-12-08 02:34:57 +03:00
// #include "moses/StaticData.h"
#include "moses/TypeDef.h"
2015-08-05 04:15:34 +03:00
namespace Moses {
InputOptions::
InputOptions()
: continue_partial_translation(false)
, input_type(SentenceInput)
, xml_policy(XmlPassThrough)
, placeholder_factor(NOT_FOUND)
2015-08-05 04:15:34 +03:00
{
xml_brackets.first = "<";
xml_brackets.second = ">";
factor_order.assign(1,0);
2015-12-12 19:23:37 +03:00
factor_delimiter = "|";
2015-08-05 04:15:34 +03:00
}
bool
InputOptions::
init(Parameter const& param)
{
param.SetParameter(input_type, "inputtype", SentenceInput);
2015-12-08 02:34:57 +03:00
#if 0
2015-08-05 04:15:34 +03:00
if (input_type == SentenceInput)
{ VERBOSE(2, "input type is: text input"); }
else if (input_type == ConfusionNetworkInput)
{ VERBOSE(2, "input type is: confusion net"); }
else if (input_type == WordLatticeInput)
{ VERBOSE(2, "input type is: word lattice"); }
else if (input_type == TreeInputType)
{ VERBOSE(2, "input type is: tree"); }
else if (input_type == TabbedSentenceInput)
{ VERBOSE(2, "input type is: tabbed sentence"); }
else if (input_type == ForestInputType)
{ VERBOSE(2, "input type is: forest"); }
2015-12-08 02:34:57 +03:00
#endif
2015-08-05 04:15:34 +03:00
param.SetParameter(continue_partial_translation,
"continue-partial-translation", false);
2015-08-05 04:15:34 +03:00
param.SetParameter<XmlInputType>(xml_policy, "xml-input", XmlPassThrough);
// specify XML tags opening and closing brackets for XML option
// Do we really want this to be configurable???? UG
const PARAM_VEC *pspec;
pspec = param.GetParam("xml-brackets");
if (pspec && pspec->size())
{
2015-11-10 23:42:17 +03:00
std::vector<std::string> brackets = Tokenize(pspec->at(0));
if(brackets.size()!=2)
{
std::cerr << "invalid xml-brackets value, "
<< "must specify exactly 2 blank-delimited strings "
2015-11-03 22:36:43 +03:00
<< "for XML tags opening and closing brackets"
<< std::endl;
2015-11-10 23:42:17 +03:00
exit(1);
}
2015-11-03 22:36:43 +03:00
2015-11-10 23:42:17 +03:00
xml_brackets.first= brackets[0];
xml_brackets.second=brackets[1];
2015-11-03 22:36:43 +03:00
2015-12-08 02:34:57 +03:00
#if 0
2015-11-10 23:42:17 +03:00
VERBOSE(1,"XML tags opening and closing brackets for XML input are: "
<< xml_brackets.first << " and "
<< xml_brackets.second << std::endl);
2015-12-08 02:34:57 +03:00
#endif
2015-08-05 04:15:34 +03:00
}
2015-11-03 22:36:43 +03:00
pspec = param.GetParam("input-factors");
if (pspec) factor_order = Scan<FactorType>(*pspec);
if (factor_order.empty()) factor_order.assign(1,0);
param.SetParameter(placeholder_factor, "placeholder-factor", NOT_FOUND);
2015-12-12 19:23:37 +03:00
param.SetParameter<std::string>(factor_delimiter, "factor-delimiter", "|");
param.SetParameter<std::string>(input_file_path,"input-file","");
return true;
}
#ifdef HAVE_XMLRPC_C
bool
InputOptions::
update(std::map<std::string,xmlrpc_c::value>const& param)
{
typedef std::map<std::string, xmlrpc_c::value> params_t;
params_t::const_iterator si = param.find("xml-input");
if (si != param.end())
xml_policy = Scan<XmlInputType>(xmlrpc_c::value_string(si->second));
2015-08-05 04:15:34 +03:00
return true;
}
#else
bool
InputOptions::
update(std::map<std::string,xmlrpc_c::value>const& param)
{}
#endif
2015-08-05 04:15:34 +03:00
}