00001
00002 #include "ReportingOptions.h"
00003 #include "moses/Parameter.h"
00004
00005 namespace Moses {
00006 using namespace std;
00007
00008 ReportingOptions::
00009 ReportingOptions()
00010 : start_translation_id(0)
00011 , ReportAllFactors(false)
00012 , ReportSegmentation(0)
00013 , PrintAlignmentInfo(false)
00014 , PrintAllDerivations(false)
00015 , PrintTranslationOptions(false)
00016 , WA_SortOrder(NoSort)
00017 , WordGraph(false)
00018 , DontPruneSearchGraph(false)
00019 , RecoverPath(false)
00020 , ReportHypoScore(false)
00021 , PrintID(false)
00022 , PrintPassThrough(false)
00023 , include_lhs_in_search_graph(false)
00024 , lattice_sample_size(0)
00025 {
00026 factor_order.assign(1,0);
00027 factor_delimiter = "|";
00028 }
00029
00030 bool
00031 ReportingOptions::
00032 init(Parameter const& param)
00033 {
00034 param.SetParameter<long>(start_translation_id, "start-translation-id", 0);
00035
00036
00037 param.SetParameter(ReportAllFactors, "report-all-factors", false);
00038
00039
00040 ReportSegmentation = (param.GetParam("report-segmentation-enriched")
00041 ? 2 : param.GetParam("report-segmentation")
00042 ? 1 : 0);
00043
00044
00045 param.SetParameter(PrintAlignmentInfo, "print-alignment-info", false);
00046 param.SetParameter(WA_SortOrder, "sort-word-alignment", NoSort);
00047 std::string e;
00048 param.SetParameter(AlignmentOutputFile,"alignment-output-file", e);
00049
00050
00051 param.SetParameter(PrintAllDerivations, "print-all-derivations", false);
00052 param.SetParameter(PrintTranslationOptions, "print-translation-option", false);
00053
00054
00055 PARAM_VEC const* params;
00056 params = param.GetParam("output-word-graph");
00057 WordGraph = (params && params->size() == 2);
00058
00059
00060 param.SetParameter(SearchGraph, "output-search-graph", e);
00061 param.SetParameter(SearchGraphExtended, "output-search-graph-extended", e);
00062 param.SetParameter(SearchGraphSLF,"output-search-graph-slf", e);
00063 param.SetParameter(SearchGraphHG, "output-search-graph-hypergraph", e);
00064 #ifdef HAVE_PROTOBUF
00065 param.SetParameter(SearchGraphPB, "output-search-graph-pb", e);
00066 #endif
00067
00068 param.SetParameter(DontPruneSearchGraph, "unpruned-search-graph", false);
00069 param.SetParameter(include_lhs_in_search_graph,
00070 "include-lhs-in-search-graph", false );
00071
00072
00073
00074 param.SetParameter(RecoverPath, "recover-input-path",false);
00075 param.SetParameter(ReportHypoScore, "output-hypo-score",false);
00076 param.SetParameter(PrintID, "print-id",false);
00077 param.SetParameter(PrintPassThrough, "print-passthrough",false);
00078 param.SetParameter(detailed_all_transrep_filepath,
00079 "translation-all-details", e);
00080 param.SetParameter(detailed_transrep_filepath, "translation-details", e);
00081 param.SetParameter(detailed_tree_transrep_filepath,
00082 "tree-translation-details", e);
00083
00084 params = param.GetParam("lattice-samples");
00085 if (params) {
00086 if (params->size() ==2 ) {
00087 lattice_sample_filepath = params->at(0);
00088 lattice_sample_size = Scan<size_t>(params->at(1));
00089 } else {
00090 std::cerr <<"wrong format for switch -lattice-samples file size";
00091 return false;
00092 }
00093 }
00094
00095
00096 if (ReportAllFactors) {
00097 factor_order.clear();
00098 for (size_t i = 0; i < MAX_NUM_FACTORS; ++i)
00099 factor_order.push_back(i);
00100 } else {
00101 params= param.GetParam("output-factors");
00102 if (params) factor_order = Scan<FactorType>(*params);
00103 if (factor_order.empty()) factor_order.assign(1,0);
00104 }
00105
00106 param.SetParameter(factor_delimiter, "factor-delimiter", std::string("|"));
00107 param.SetParameter(factor_delimiter, "output-factor-delimiter", factor_delimiter);
00108
00109 return true;
00110 }
00111
00112 #ifdef HAVE_XMLRPC_C
00113 bool
00114 ReportingOptions::
00115 update(std::map<std::string, xmlrpc_c::value>const& param)
00116 {
00117 ReportAllFactors = check(param, "report-all-factors", ReportAllFactors);
00118
00119
00120 std::map<std::string, xmlrpc_c::value>::const_iterator m;
00121 m = param.find("output-factors");
00122 if (m != param.end()) {
00123 factor_order=Tokenize<FactorType>(xmlrpc_c::value_string(m->second),",");
00124 }
00125
00126 if (ReportAllFactors) {
00127 factor_order.clear();
00128 for (size_t i = 0; i < MAX_NUM_FACTORS; ++i)
00129 factor_order.push_back(i);
00130 }
00131
00132 m = param.find("no-ReportSegmentation");
00133 if (m == param.end() || !Scan<bool>(xmlrpc_c::value_string(m->second))) {
00134
00135
00136 m = param.find("align");
00137 if (m != param.end() && Scan<bool>(xmlrpc_c::value_string(m->second)))
00138 ReportSegmentation = 1;
00139
00140 }
00141
00142 PrintAlignmentInfo = check(param,"word-align",PrintAlignmentInfo);
00143
00144 m = param.find("factor-delimiter");
00145 if (m != param.end()) {
00146 factor_delimiter = Trim(xmlrpc_c::value_string(m->second));
00147 }
00148
00149 m = param.find("output-factor-delimiter");
00150 if (m != param.end()) {
00151 factor_delimiter = Trim(xmlrpc_c::value_string(m->second));
00152 }
00153
00154 return true;
00155 }
00156 #endif
00157 }