diff options
Diffstat (limited to 'decoder/cfg_options.h')
-rwxr-xr-x | decoder/cfg_options.h | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/decoder/cfg_options.h b/decoder/cfg_options.h index 5dca168e..331363d2 100755 --- a/decoder/cfg_options.h +++ b/decoder/cfg_options.h @@ -10,11 +10,14 @@ struct CFGOptions { CFGFormat format; CFGBinarize binarize; std::string out,source_out,unbin_out; + bool uniq; void set_defaults() { format.set_defaults(); binarize.set_defaults(); - out=""; + out=source_out=unbin_out=""; + uniq=false; } + CFGOptions() { set_defaults(); } template <class Opts> // template to support both printable_opts and boost nonprintable void AddOptions(Opts *opts) { @@ -22,6 +25,8 @@ struct CFGOptions { ("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: + ("cfg_uniq", defaulted_value(&uniq),"in case of duplicate rules, keep only the one with highest prob") + ; binarize.AddOptions(opts); format.AddOptions(opts); @@ -29,10 +34,6 @@ struct CFGOptions { void Validate() { format.Validate(); binarize.Validate(); -// 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_out.empty()) return; @@ -41,24 +42,33 @@ struct CFGOptions { 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) { + // executes all options except source_cfg_output, building target hgcfg + void prepare(HgCFG &hgcfg) { if (out.empty() && unbin_out.empty()) return; CFG &cfg=hgcfg.GetCFG(); maybe_print(cfg,unbin_out); + maybe_uniq(hgcfg); maybe_binarize(hgcfg); maybe_print(cfg,out,""); } + char const* description() const { + return "CFG output options"; + } + 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_uniq(HgCFG &hgcfg) { + if (hgcfg.uniqed) return; + hgcfg.GetCFG().UniqRules(); + hgcfg.uniqed=true; + } void maybe_binarize(HgCFG &hgcfg) { if (hgcfg.binarized) return; - CFG &cfg=hgcfg.GetCFG(); - cfg.Binarize(binarize); + hgcfg.GetCFG().Binarize(binarize); hgcfg.binarized=true; } }; |