Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ReportingOptions.cpp « parameters « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 210950a3cb3d20cac7f3cdc837a8e35f88158aa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
#include "ReportingOptions.h"
#include "moses/Parameter.h"

namespace Moses {
  using namespace std;

  ReportingOptions::
  ReportingOptions()
    : start_translation_id(0)
    , ReportAllFactors(false)
    , ReportSegmentation(0)
    , PrintAlignmentInfo(false)
    , PrintAllDerivations(false)
    , PrintTranslationOptions(false)
    , WA_SortOrder(NoSort)
    , WordGraph(false)
    , DontPruneSearchGraph(false)
    , RecoverPath(false)
    , ReportHypoScore(false)
    , PrintID(false)
    , PrintPassThrough(false)
    , include_lhs_in_search_graph(false)
    , lattice_sample_size(0)
  {
    factor_order.assign(1,0);
    factor_delimiter = "|";
  }
  
  bool
  ReportingOptions::
  init(Parameter const& param)
  {
    param.SetParameter<long>(start_translation_id, "start-translation-id", 0);

    // including factors in the output
    param.SetParameter(ReportAllFactors, "report-all-factors", false);
    
    // segmentation reporting 
    ReportSegmentation = (param.GetParam("report-segmentation-enriched")
                          ? 2 : param.GetParam("report-segmentation")
                          ? 1 : 0);
    
    // word alignment reporting
    param.SetParameter(PrintAlignmentInfo, "print-alignment-info", false);
    param.SetParameter(WA_SortOrder, "sort-word-alignment", NoSort);
    std::string e; // hack to save us param.SetParameter<string>(...)
    param.SetParameter(AlignmentOutputFile,"alignment-output-file", e);
    
    
    param.SetParameter(PrintAllDerivations, "print-all-derivations", false);
    param.SetParameter(PrintTranslationOptions, "print-translation-option", false);
    
    // output a word graph
    PARAM_VEC const* params;
    params = param.GetParam("output-word-graph");
    WordGraph = (params && params->size() == 2); // what are the two options?
    
    // dump the search graph
    param.SetParameter(SearchGraph, "output-search-graph", e);
    param.SetParameter(SearchGraphExtended, "output-search-graph-extended", e);
    param.SetParameter(SearchGraphSLF,"output-search-graph-slf", e);
    param.SetParameter(SearchGraphHG, "output-search-graph-hypergraph", e);
#ifdef HAVE_PROTOBUF
    param.SetParameter(SearchGraphPB, "output-search-graph-pb", e);
#endif
    
    param.SetParameter(DontPruneSearchGraph, "unpruned-search-graph", false);
    param.SetParameter(include_lhs_in_search_graph,
                       "include-lhs-in-search-graph", false );

    
    // miscellaneous 
    param.SetParameter(RecoverPath, "recover-input-path",false);
    param.SetParameter(ReportHypoScore, "output-hypo-score",false); 
    param.SetParameter(PrintID, "print-id",false);
    param.SetParameter(PrintPassThrough, "print-passthrough",false);
    param.SetParameter(detailed_all_transrep_filepath, 
                       "translation-all-details", e);
    param.SetParameter(detailed_transrep_filepath, "translation-details", e);
    param.SetParameter(detailed_tree_transrep_filepath, 
                       "tree-translation-details", e);

    params = param.GetParam("lattice-samples");
    if (params) {
      if (params->size() ==2 ) {
        lattice_sample_filepath = params->at(0);
        lattice_sample_size = Scan<size_t>(params->at(1));
      } else {
        std::cerr <<"wrong format for switch -lattice-samples file size";
        return false;
      }
    }

    
    if (ReportAllFactors) {
      factor_order.clear();
      for (size_t i = 0; i < MAX_NUM_FACTORS; ++i)
        factor_order.push_back(i);
    } else {
      params= param.GetParam("output-factors");
      if (params) factor_order = Scan<FactorType>(*params);
      if (factor_order.empty()) factor_order.assign(1,0);
    }
    
    param.SetParameter(factor_delimiter, "factor-delimiter", std::string("|"));
    param.SetParameter(factor_delimiter, "output-factor-delimiter", factor_delimiter);
    
    return true;
  }
  
#ifdef HAVE_XMLRPC_C
  bool 
  ReportingOptions::
  update(std::map<std::string, xmlrpc_c::value>const& param)
  {
    ReportAllFactors = check(param, "report-all-factors", ReportAllFactors);
    
    
    std::map<std::string, xmlrpc_c::value>::const_iterator m;
    m = param.find("output-factors");
    if (m  != param.end()) {
      factor_order=Tokenize<FactorType>(xmlrpc_c::value_string(m->second),",");
    }

    if (ReportAllFactors) {
      factor_order.clear();
      for (size_t i = 0; i < MAX_NUM_FACTORS; ++i)
        factor_order.push_back(i);
    }
    
    m = param.find("align");
    if (m != param.end() && Scan<bool>(xmlrpc_c::value_string(m->second)))
      ReportSegmentation = 1;
    
    PrintAlignmentInfo = check(param,"word-align",PrintAlignmentInfo);

    m = param.find("factor-delimiter");
    if (m != param.end()) { 
      factor_delimiter = Trim(xmlrpc_c::value_string(m->second));
    }

    m = param.find("output-factor-delimiter");
    if (m != param.end()) { 
      factor_delimiter = Trim(xmlrpc_c::value_string(m->second));
    }
    
    return true;
  }
#endif
}