mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-16 15:00:33 +03:00
Update some options via xmlrpc_c calls.
This commit is contained in:
parent
fcd0c17af3
commit
c4fc7e6610
@ -53,4 +53,23 @@ namespace Moses
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
AllOptions::
|
||||
update(std::map<std::string,xmlrpc_c::value>const& param)
|
||||
{
|
||||
if (!search.update(param)) return false;
|
||||
if (!cube.update(param)) return false;
|
||||
if (!nbest.update(param)) return false;
|
||||
if (!reordering.update(param)) return false;
|
||||
if (!context.update(param)) return false;
|
||||
if (!input.update(param)) return false;
|
||||
if (!mbr.update(param)) return false;
|
||||
if (!lmbr.update(param)) return false;
|
||||
return sanity_check();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
#include "SearchOptions.h"
|
||||
#include "CubePruningOptions.h"
|
||||
#include "NBestOptions.h"
|
||||
@ -10,11 +11,10 @@
|
||||
#include "InputOptions.h"
|
||||
#include "MBR_Options.h"
|
||||
#include "LMBR_Options.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
struct
|
||||
AllOptions
|
||||
AllOptions : public OptionsBaseClass
|
||||
{
|
||||
SearchOptions search;
|
||||
CubePruningOptions cube;
|
||||
@ -33,6 +33,11 @@ namespace Moses
|
||||
bool sanity_check();
|
||||
AllOptions() {}
|
||||
AllOptions(Parameter const& param);
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool update(std::map<std::string,xmlrpc_c::value>const& param);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -2,11 +2,12 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct
|
||||
BeamSearchOptions
|
||||
BeamSearchOptions : public OptionsBaseClass
|
||||
{
|
||||
bool init(Parameter const& param);
|
||||
BeamSearchOptions(Parameter const& param);
|
||||
|
@ -1,9 +1,12 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct BookkeepingOptions {
|
||||
struct BookkeepingOptions : public OptionsBaseClass
|
||||
{
|
||||
bool need_alignment_info;
|
||||
bool init(Parameter const& param);
|
||||
};
|
||||
|
@ -4,11 +4,12 @@
|
||||
#include "moses/Parameter.h"
|
||||
#include "moses/TypeDef.h"
|
||||
#include "moses/Util.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
class ContextParameters
|
||||
class ContextParameters : public OptionsBaseClass
|
||||
{
|
||||
public:
|
||||
ContextParameters();
|
||||
|
@ -1,4 +1,4 @@
|
||||
// -*- mode: c++; cc-style: gnu -*-
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#include "CubePruningOptions.h"
|
||||
|
||||
namespace Moses
|
||||
@ -16,4 +16,37 @@ namespace Moses
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
CubePruningOptions::
|
||||
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("cube-pruning-pop-limit");
|
||||
if (si != params.end()) pop_limit = xmlrpc_c::value_int(si->second);
|
||||
|
||||
si = params.find("cube-pruning-diversity");
|
||||
if (si != params.end()) diversity = xmlrpc_c::value_int(si->second);
|
||||
|
||||
si = params.find("cube-pruning-lazy-scoring");
|
||||
if (si != params.end())
|
||||
{
|
||||
std::string spec = xmlrpc_c::value_string(si->second);
|
||||
if (spec == "true" or spec == "on" or spec == "1")
|
||||
lazy_scoring = true;
|
||||
else if (spec == "false" or spec == "off" or spec == "0")
|
||||
lazy_scoring = false;
|
||||
else
|
||||
{
|
||||
char const* msg
|
||||
= "Error parsing specification for cube-pruning-lazy-scoring";
|
||||
xmlrpc_c::fault(msg, xmlrpc_c::fault::CODE_PARSE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,11 +2,12 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct
|
||||
CubePruningOptions
|
||||
CubePruningOptions : public OptionsBaseClass
|
||||
{
|
||||
size_t pop_limit;
|
||||
size_t diversity;
|
||||
@ -15,6 +16,11 @@ namespace Moses
|
||||
bool init(Parameter const& param);
|
||||
CubePruningOptions(Parameter const& param);
|
||||
CubePruningOptions() {};
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params);
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include <string>
|
||||
#include "OptionsBaseClass.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
struct
|
||||
InputOptions
|
||||
InputOptions : public OptionsBaseClass
|
||||
{
|
||||
bool continue_partial_translation;
|
||||
bool default_non_term_only_for_empty_range; // whatever that means
|
||||
|
@ -3,12 +3,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
// Options for mimum bayes risk decoding
|
||||
struct
|
||||
LMBR_Options
|
||||
LMBR_Options : public OptionsBaseClass
|
||||
{
|
||||
bool enabled;
|
||||
bool use_lattice_hyp_set; //! to use nbest as hypothesis set during lattice MBR
|
||||
|
17
moses/parameters/LookupOptions.h
Normal file
17
moses/parameters/LookupOptions.h
Normal file
@ -0,0 +1,17 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct
|
||||
LookupOptions : public OptionsBaseClass
|
||||
{
|
||||
bool init(Parameter const& param);
|
||||
ReorderingOptions() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,13 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
// Options for mimum bayes risk decoding
|
||||
struct
|
||||
MBR_Options
|
||||
MBR_Options : public OptionsBaseClass
|
||||
{
|
||||
bool enabled;
|
||||
size_t size; //! number of translation candidates considered
|
||||
|
@ -1,10 +1,11 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct NBestOptions
|
||||
struct NBestOptions : public OptionsBaseClass
|
||||
{
|
||||
size_t nbest_size;
|
||||
size_t factor;
|
||||
|
15
moses/parameters/OptionsBaseClass.cpp
Normal file
15
moses/parameters/OptionsBaseClass.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#include "OptionsBaseClass.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
OptionsBaseClass::
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
17
moses/parameters/OptionsBaseClass.h
Normal file
17
moses/parameters/OptionsBaseClass.h
Normal file
@ -0,0 +1,17 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#pragma once
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <map>
|
||||
namespace Moses
|
||||
{
|
||||
struct OptionsBaseClass
|
||||
{
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
virtual bool
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params);
|
||||
#endif
|
||||
};
|
||||
}
|
@ -2,11 +2,12 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct
|
||||
ReorderingOptions
|
||||
ReorderingOptions : public OptionsBaseClass
|
||||
{
|
||||
int max_distortion;
|
||||
bool monotone_at_punct;
|
||||
|
90
moses/parameters/ReportingOptions.cpp
Normal file
90
moses/parameters/ReportingOptions.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#if 0
|
||||
#include "ReportingOptions.h"
|
||||
#include "moses/Parameter.h"
|
||||
|
||||
namespace Moses {
|
||||
using namespace std;
|
||||
bool
|
||||
ReportingOptions::
|
||||
init(Parameter const& param)
|
||||
{
|
||||
PARAM_VEC const* params;
|
||||
|
||||
param.SetParameter(segmentation, "report-segmentation", false );
|
||||
param.SetParameter(segmentation_enriched, "report-segmentation-enriched", false);
|
||||
param.SetParameter(all_factors, "report-all-factors", false );
|
||||
|
||||
// print ...
|
||||
param.SetParameter(id, "print-id", false );
|
||||
param.SetParameter(aln_info, "print-alignment-info", false);
|
||||
param.SetParameter(passthrough, "print-passthrough", false );
|
||||
|
||||
param.SetParameter<string>(detailed_transrep_filepath, "translation-details", "");
|
||||
param.SetParameter<string>(detailed_tree_transrep_filepath,
|
||||
"tree-translation-details", "");
|
||||
param.SetParameter<string>(detailed_all_transrep_filepath,
|
||||
"translation-all-details", "");
|
||||
|
||||
// output search graph
|
||||
param.SetParameter<string>(output,
|
||||
"translation-all-details", "");
|
||||
|
||||
|
||||
|
||||
param.SetParameter(sort_word_alignment, "sort-word-alignment", NoSort);
|
||||
|
||||
|
||||
// Is there a reason why we can't use SetParameter here? [UG]
|
||||
= param.GetParam("alignment-output-file");
|
||||
if (params && params->size()) {
|
||||
m_alignmentOutputFile = Scan<std::string>(params->at(0));
|
||||
}
|
||||
|
||||
params = param.GetParam("output-word-graph");
|
||||
output_word_graph = (params && params->size() == 2);
|
||||
|
||||
// bizarre code ahead! Why do we need to do the checks here?
|
||||
// as adapted from StaticData.cpp
|
||||
params = param.GetParam("output-search-graph");
|
||||
if (params && params->size()) {
|
||||
if (params->size() != 1) {
|
||||
std::cerr << "ERROR: wrong format for switch -output-search-graph file";
|
||||
return false;
|
||||
}
|
||||
output_search_graph = true;
|
||||
}
|
||||
else if (m_parameter->GetParam("output-search-graph-extended") &&
|
||||
m_parameter->GetParam("output-search-graph-extended")->size()) {
|
||||
if (m_parameter->GetParam("output-search-graph-extended")->size() != 1) {
|
||||
std::cerr << "ERROR: wrong format for switch -output-search-graph-extended file";
|
||||
return false;
|
||||
}
|
||||
output_search_graph = true;
|
||||
m_outputSearchGraphExtended = true;
|
||||
} else {
|
||||
m_outputSearchGraph = false;
|
||||
}
|
||||
|
||||
params = m_parameter->GetParam("output-search-graph-slf");
|
||||
output_search_graph_slf = params && params->size();
|
||||
params = m_parameter->GetParam("output-search-graph-hypergraph");
|
||||
output_search_graph_hypergraph = params && params->size();
|
||||
|
||||
#ifdef HAVE_PROTOBUF
|
||||
params = m_parameter->GetParam("output-search-graph-pb");
|
||||
if (params && params->size()) {
|
||||
if (params->size() != 1) {
|
||||
cerr << "ERROR: wrong format for switch -output-search-graph-pb path";
|
||||
return false;
|
||||
}
|
||||
m_outputSearchGraphPB = true;
|
||||
} else
|
||||
m_outputSearchGraphPB = false;
|
||||
#endif
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
42
moses/parameters/ReportingOptions.h
Normal file
42
moses/parameters/ReportingOptions.h
Normal file
@ -0,0 +1,42 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct
|
||||
ReportingOptions
|
||||
{
|
||||
|
||||
WordAlignmentSort sort_word_alignment; // 0: no, 1: target order
|
||||
|
||||
|
||||
bool segmentation; // m_reportSegmentation;
|
||||
bool segmentation_enriched; // m_reportSegmentationEnriched;
|
||||
bool all_factors; // m_reportAllFactors;
|
||||
|
||||
bool output_word_graph;
|
||||
bool output_search_graph;
|
||||
bool output_search_graph_extended;
|
||||
bool output_search_graph_slf;
|
||||
bool output_search_graph_hypergraph;
|
||||
bool output_search_graph_protobuf;
|
||||
|
||||
// print ..
|
||||
bool aln_info; // m_PrintAlignmentInfo;
|
||||
bool id; // m_PrintID;
|
||||
bool passthrough; // m_PrintPassthroughInformation;
|
||||
|
||||
// transrep = translation reporting
|
||||
std::string detailed_transrep_filepath;
|
||||
std::string detailed_tree_transrep_filepath;
|
||||
std::string detailed_all_transrep_filepath;
|
||||
|
||||
std::string aln_output_file; // m_alignmentOutputFile;
|
||||
|
||||
bool init(Parameter const& param);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ namespace Moses
|
||||
param.SetParameter(max_partial_trans_opt, "max-partial-trans-opt",
|
||||
DEFAULT_MAX_PART_TRANS_OPT_SIZE);
|
||||
|
||||
|
||||
param.SetParameter(consensus, "consensus-decoding", false);
|
||||
|
||||
// transformation to log of a few scores
|
||||
@ -48,5 +47,43 @@ namespace Moses
|
||||
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-algoritm");
|
||||
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
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,14 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
bool is_syntax(SearchAlgorithm algo);
|
||||
|
||||
struct
|
||||
SearchOptions
|
||||
SearchOptions : public OptionsBaseClass
|
||||
{
|
||||
SearchAlgorithm algo;
|
||||
|
||||
@ -37,10 +38,16 @@ namespace Moses
|
||||
SearchOptions(Parameter const& param);
|
||||
SearchOptions() {}
|
||||
|
||||
bool UseEarlyDiscarding() const {
|
||||
bool
|
||||
UseEarlyDiscarding() const {
|
||||
return early_discarding_threshold != -std::numeric_limits<float>::infinity();
|
||||
}
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -246,6 +246,8 @@ parse_request(std::map<std::string, xmlrpc_c::value> const& params)
|
||||
// params_t const params = m_paramList.getStruct(0);
|
||||
m_paramList.verifyEnd(1); // ??? UG
|
||||
|
||||
m_options.update(params);
|
||||
|
||||
// source text must be given, or we don't know what to translate
|
||||
typedef std::map<std::string, xmlrpc_c::value> params_t;
|
||||
params_t::const_iterator si = params.find("text");
|
||||
|
Loading…
Reference in New Issue
Block a user