summaryrefslogtreecommitdiff
path: root/decoder/cfg_options.h
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 04:08:59 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 04:08:59 +0000
commit541915be79d90329f40381ef75c98c794ea0298c (patch)
tree197f5b99107d7487c39d5b46b8bc243c6a19cc2a /decoder/cfg_options.h
parent695ee5c0b87365857925ecb53a45b97ba4582974 (diff)
cfg test
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@552 ec762483-ff6d-05da-a07a-a48fb63a330f
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;
}
};