00001
00002 #include "InputOptions.h"
00003 #include <vector>
00004 #include <iostream>
00005
00006 #include "moses/TypeDef.h"
00007
00008 namespace Moses {
00009
00010 InputOptions::
00011 InputOptions()
00012 : continue_partial_translation(false)
00013 , input_type(SentenceInput)
00014 , xml_policy(XmlPassThrough)
00015 , placeholder_factor(NOT_FOUND)
00016 {
00017 xml_brackets.first = "<";
00018 xml_brackets.second = ">";
00019 factor_order.assign(1,0);
00020 factor_delimiter = "|";
00021 }
00022
00023 bool
00024 InputOptions::
00025 init(Parameter const& param)
00026 {
00027 param.SetParameter(input_type, "inputtype", SentenceInput);
00028 #if 0
00029 if (input_type == SentenceInput)
00030 { VERBOSE(2, "input type is: text input"); }
00031 else if (input_type == ConfusionNetworkInput)
00032 { VERBOSE(2, "input type is: confusion net"); }
00033 else if (input_type == WordLatticeInput)
00034 { VERBOSE(2, "input type is: word lattice"); }
00035 else if (input_type == TreeInputType)
00036 { VERBOSE(2, "input type is: tree"); }
00037 else if (input_type == TabbedSentenceInput)
00038 { VERBOSE(2, "input type is: tabbed sentence"); }
00039 else if (input_type == ForestInputType)
00040 { VERBOSE(2, "input type is: forest"); }
00041 #endif
00042
00043
00044 param.SetParameter(continue_partial_translation,
00045 "continue-partial-translation", false);
00046
00047 param.SetParameter<XmlInputType>(xml_policy, "xml-input", XmlPassThrough);
00048
00049
00050
00051 const PARAM_VEC *pspec;
00052 pspec = param.GetParam("xml-brackets");
00053 if (pspec && pspec->size())
00054 {
00055 std::vector<std::string> brackets = Tokenize(pspec->at(0));
00056 if(brackets.size()!=2)
00057 {
00058 std::cerr << "invalid xml-brackets value, "
00059 << "must specify exactly 2 blank-delimited strings "
00060 << "for XML tags opening and closing brackets"
00061 << std::endl;
00062 exit(1);
00063 }
00064
00065 xml_brackets.first= brackets[0];
00066 xml_brackets.second=brackets[1];
00067
00068 #if 0
00069 VERBOSE(1,"XML tags opening and closing brackets for XML input are: "
00070 << xml_brackets.first << " and "
00071 << xml_brackets.second << std::endl);
00072 #endif
00073 }
00074
00075 pspec = param.GetParam("input-factors");
00076 if (pspec) factor_order = Scan<FactorType>(*pspec);
00077 if (factor_order.empty()) factor_order.assign(1,0);
00078 param.SetParameter(placeholder_factor, "placeholder-factor", NOT_FOUND);
00079
00080 param.SetParameter<std::string>(factor_delimiter, "factor-delimiter", "|");
00081 param.SetParameter<std::string>(input_file_path,"input-file","");
00082
00083 return true;
00084 }
00085
00086
00087 #ifdef HAVE_XMLRPC_C
00088 bool
00089 InputOptions::
00090 update(std::map<std::string,xmlrpc_c::value>const& param)
00091 {
00092 typedef std::map<std::string, xmlrpc_c::value> params_t;
00093 params_t::const_iterator si = param.find("xml-input");
00094 if (si != param.end())
00095 xml_policy = Scan<XmlInputType>(xmlrpc_c::value_string(si->second));
00096 return true;
00097 }
00098 #else
00099 bool
00100 InputOptions::
00101 update(std::map<std::string,xmlrpc_c::value>const& param)
00102 {}
00103 #endif
00104
00105 }