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
|
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
#include "SearchOptions.h"
namespace Moses
{
SearchOptions::
SearchOptions()
: algo(Normal)
, stack_size(DEFAULT_MAX_HYPOSTACK_SIZE)
, stack_diversity(0)
, disable_discarding(false)
, max_phrase_length(DEFAULT_MAX_PHRASE_LENGTH)
, max_trans_opt_per_cov(DEFAULT_MAX_TRANS_OPT_SIZE)
, max_partial_trans_opt(DEFAULT_MAX_PART_TRANS_OPT_SIZE)
, beam_width(DEFAULT_BEAM_WIDTH)
, timeout(0)
, consensus(false)
, early_discarding_threshold(DEFAULT_EARLY_DISCARDING_THRESHOLD)
, trans_opt_threshold(DEFAULT_TRANSLATION_OPTION_THRESHOLD)
{ }
SearchOptions::
SearchOptions(Parameter const& param)
: stack_diversity(0)
{
init(param);
}
bool
SearchOptions::
init(Parameter const& param)
{
param.SetParameter(algo, "search-algorithm", Normal);
param.SetParameter(stack_size, "stack", DEFAULT_MAX_HYPOSTACK_SIZE);
param.SetParameter(stack_diversity, "stack-diversity", size_t(0));
param.SetParameter(beam_width, "beam-threshold", DEFAULT_BEAM_WIDTH);
param.SetParameter(early_discarding_threshold, "early-discarding-threshold",
DEFAULT_EARLY_DISCARDING_THRESHOLD);
param.SetParameter(timeout, "time-out", 0);
param.SetParameter(segment_timeout, "segment-time-out", 0);
param.SetParameter(max_phrase_length, "max-phrase-length",
DEFAULT_MAX_PHRASE_LENGTH);
param.SetParameter(trans_opt_threshold, "translation-option-threshold",
DEFAULT_TRANSLATION_OPTION_THRESHOLD);
param.SetParameter(max_trans_opt_per_cov, "max-trans-opt-per-coverage",
DEFAULT_MAX_TRANS_OPT_SIZE);
param.SetParameter(max_partial_trans_opt, "max-partial-trans-opt",
DEFAULT_MAX_PART_TRANS_OPT_SIZE);
param.SetParameter(consensus, "consensus-decoding", false);
param.SetParameter(disable_discarding, "disable-discarding", false);
// transformation to log of a few scores
beam_width = TransformScore(beam_width);
trans_opt_threshold = TransformScore(trans_opt_threshold);
early_discarding_threshold = TransformScore(early_discarding_threshold);
return true;
}
bool
is_syntax(SearchAlgorithm algo)
{
return (algo == CYKPlus || algo == ChartIncremental ||
algo == SyntaxS2T || algo == SyntaxT2S ||
algo == SyntaxF2S || algo == SyntaxT2S_SCFG);
}
#ifdef HAVE_XMLRPC_C
bool
SearchOptions::
update(std::map<std::string,xmlrpc_c::value>const& params)
{
typedef std::map<std::string, xmlrpc_c::value> params_t;
params_t::const_iterator si = params.find("search-algorithm");
if (si != params.end())
{
// use named parameters
std::string spec = xmlrpc_c::value_string(si->second);
if (spec == "normal" || spec == "0") algo = Normal;
else if (spec == "cube" || spec == "1") algo = CubePruning;
else throw xmlrpc_c::fault("Unsupported search algorithm",
xmlrpc_c::fault::CODE_PARSE);
}
si = params.find("stack");
if (si != params.end()) stack_size = xmlrpc_c::value_int(si->second);
si = params.find("stack-diversity");
if (si != params.end()) stack_diversity = xmlrpc_c::value_int(si->second);
si = params.find("beam-threshold");
if (si != params.end()) beam_width = xmlrpc_c::value_double(si->second);
si = params.find("time-out");
if (si != params.end()) timeout = xmlrpc_c::value_int(si->second);
si = params.find("max-phrase-length");
if (si != params.end()) max_phrase_length = xmlrpc_c::value_int(si->second);
return true;
}
#endif
}
|