summaryrefslogtreecommitdiff
path: root/decoder/cfg_options.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder/cfg_options.h')
-rwxr-xr-xdecoder/cfg_options.h36
1 files changed, 22 insertions, 14 deletions
diff --git a/decoder/cfg_options.h b/decoder/cfg_options.h
index 10321a7f..5dca168e 100755
--- a/decoder/cfg_options.h
+++ b/decoder/cfg_options.h
@@ -9,19 +9,19 @@
struct CFGOptions {
CFGFormat format;
CFGBinarize binarize;
- std::string cfg_output,source_cfg_output,cfg_unbin_output;
+ std::string out,source_out,unbin_out;
void set_defaults() {
format.set_defaults();
binarize.set_defaults();
- cfg_output="";
+ out="";
}
CFGOptions() { set_defaults(); }
template <class Opts> // template to support both printable_opts and boost nonprintable
void AddOptions(Opts *opts) {
opts->add_options()
- ("cfg_output", defaulted_value(&cfg_output),"write final target CFG (before FSA rescoring) to this file")
- ("source_cfg_output", defaulted_value(&source_cfg_output),"write source CFG (after prelm-scoring, prelm-prune) to this file")
- ("cfg_unbin_output", defaulted_value(&cfg_unbin_output),"write pre-binarization CFG to this file") //TODO:
+ ("cfg_output", defaulted_value(&out),"write final target CFG (before FSA rescoring) to this file")
+ ("source_cfg_output", defaulted_value(&source_out),"write source CFG (after prelm-scoring, prelm-prune) to this file")
+ ("cfg_unbin_output", defaulted_value(&unbin_out),"write pre-binarization CFG to this file") //TODO:
;
binarize.AddOptions(opts);
format.AddOptions(opts);
@@ -29,28 +29,36 @@ struct CFGOptions {
void Validate() {
format.Validate();
binarize.Validate();
-// if (cfg_output.empty()) binarize.bin_name_nts=false;
+// if (out.empty()) binarize.bin_name_nts=false;
}
char const* description() const {
return "CFG output options";
}
void maybe_output_source(Hypergraph const& hg) {
- if (source_cfg_output.empty()) return;
- std::cerr<<"Printing source CFG to "<<source_cfg_output<<": "<<format<<'\n';
- WriteFile o(source_cfg_output);
+ if (source_out.empty()) return;
+ std::cerr<<"Printing source CFG to "<<source_out<<": "<<format<<'\n';
+ WriteFile o(source_out);
CFG cfg(hg,false,format.features,format.goal_nt());
cfg.Print(o.get(),format);
}
+ void maybe_print(CFG &cfg,std::string cfg_output,char const* desc=" unbinarized") {
+ WriteFile o(cfg_output);
+ std::cerr<<"Printing target"<<desc<<" CFG to "<<cfg_output<<": "<<format<<'\n';
+ cfg.Print(o.get(),format);
+ }
+
void maybe_output(HgCFG &hgcfg) {
- if (cfg_output.empty()) return;
- std::cerr<<"Printing target CFG to "<<cfg_output<<": "<<format<<'\n';
- WriteFile o(cfg_output);
+ if (out.empty() && unbin_out.empty()) return;
+ CFG &cfg=hgcfg.GetCFG();
+ maybe_print(cfg,unbin_out);
maybe_binarize(hgcfg);
- hgcfg.GetCFG().Print(o.get(),format);
+ maybe_print(cfg,out,"");
}
+
void maybe_binarize(HgCFG &hgcfg) {
if (hgcfg.binarized) return;
- hgcfg.GetCFG().Binarize(binarize);
+ CFG &cfg=hgcfg.GetCFG();
+ cfg.Binarize(binarize);
hgcfg.binarized=true;
}
};