diff options
author | graehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-10 10:02:04 +0000 |
---|---|---|
committer | graehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-10 10:02:04 +0000 |
commit | 32154b45828f05add1db7c89752ef4220c0fdf16 (patch) | |
tree | fa99e4d4847a89d41b464e9ae3c9aacf611e5500 /decoder/cfg.cc | |
parent | 43db0573b15719d48b89b3a1ad2828036d008560 (diff) |
cdec --cfg_output=-
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@499 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/cfg.cc')
-rwxr-xr-x | decoder/cfg.cc | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc index b83fc54d..ace0ebb0 100755 --- a/decoder/cfg.cc +++ b/decoder/cfg.cc @@ -5,6 +5,7 @@ using namespace std; void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool push_weights) { + uninit=false; hg_=&hg; Hypergraph::NodeProbs np; goal_inside=hg.ComputeNodeViterbi(&np); @@ -13,8 +14,10 @@ void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool pus nts.resize(nn); goal_nt=nn-1; rules.resize(ne); - for (int i=0;i<nn;++i) + for (int i=0;i<nn;++i) { nts[i].ruleids=hg.nodes_[i].in_edges_; + hg.SetNodeOrigin(i,nts[i].from); + } for (int i=0;i<ne;++i) { Rule &cfgr=rules[i]; Hypergraph::Edge const& e=hg.edges_[i]; @@ -43,12 +46,34 @@ void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool pus } } -namespace { +void CFG::Clear() { + rules.clear(); + nts.clear(); + goal_nt=-1; + hg_=0; +} + +void CFG::PrintRule(std::ostream &o,RuleHandle rulei,CFGFormat const& f) const { + Rule const& r=rules[rulei]; + f.print_lhs(o,*this,r.lhs); + f.print_rhs(o,*this,r.rhs.begin(),r.rhs.end()); + f.print_features(o,r.p,r.f); } void CFG::Print(std::ostream &o,CFGFormat const& f) const { - char const* partsep=" ||| "; - if (!f.goal_nt_name.empty()) - o << '['<<f.goal_nt_name <<']' << partsep; // print rhs - //TODO: + assert(!uninit); + if (!f.goal_nt_name.empty()) { + o << '['<<f.goal_nt_name <<']'; + f.print_rhs(o,*this,&goal_nt,&goal_nt+1); + if (pushed_inside!=1) + f.print_features(o,pushed_inside); + o<<'\n'; + } + for (int i=0;i<nts.size();++i) { + Ruleids const& ntr=nts[i].ruleids; + for (Ruleids::const_iterator j=ntr.begin(),jj=ntr.end();j!=jj;++j) { + PrintRule(o,*j,f); + o<<'\n'; + } + } } |