diff options
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'; + } + } } |