From 32154b45828f05add1db7c89752ef4220c0fdf16 Mon Sep 17 00:00:00 2001 From: "graehl@gmail.com" Date: Tue, 10 Aug 2010 10:02:04 +0000 Subject: cdec --cfg_output=- git-svn-id: https://ws10smt.googlecode.com/svn/trunk@499 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/cfg.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'decoder/cfg.h') diff --git a/decoder/cfg.h b/decoder/cfg.h index 8d7a5eee..e325c4cd 100755 --- a/decoder/cfg.h +++ b/decoder/cfg.h @@ -25,6 +25,7 @@ #include "prob.h" //#include "int_or_pointer.h" #include "small_vector.h" +#include "nt_span.h" class Hypergraph; class CFGFormat; // #include "cfg_format.h" @@ -35,6 +36,10 @@ struct CFG { typedef SmallVector RHS; // same as in trule rhs: >0 means token, <=0 means -node index (not variable index) typedef std::vector Ruleids; + void print_nt_name(std::ostream &o,NTHandle n) const { + o << nts[n].from; + } + struct Rule { int lhs; // index into nts RHS rhs; @@ -47,17 +52,33 @@ struct CFG { struct NT { Ruleids ruleids; // index into CFG rules with lhs = this NT. aka in_edges_ + NTSpan from; // optional name - still needs id to disambiguate }; - CFG() : hg_() { } + CFG() : hg_() { uninit=true; } // provided hg will have weights pushed up to root CFG(Hypergraph const& hg,bool target_side=true,bool copy_features=false,bool push_weights=true) { Init(hg,target_side,copy_features,push_weights); } + bool Uninitialized() const { return uninit; } + void Clear(); + bool Empty() const { return nts.empty(); } void Init(Hypergraph const& hg,bool target_side=true,bool copy_features=false,bool push_weights=true); void Print(std::ostream &o,CFGFormat const& format) const; // see cfg_format.h + void PrintRule(std::ostream &o,RuleHandle rulei,CFGFormat const& format) const; + void Swap(CFG &o) { // make sure this includes all fields (easier to see here than in .cc) + using namespace std; + swap(uninit,o.uninit); + swap(hg_,o.hg_); + swap(goal_inside,o.goal_inside); + swap(pushed_inside,o.pushed_inside); + swap(rules,o.rules); + swap(nts,o.nts); + swap(goal_nt,o.goal_nt); + } protected: + bool uninit; Hypergraph const* hg_; // shouldn't be used for anything, esp. after binarization prob_t goal_inside,pushed_inside; // when we push viterbi weights to goal, we store the removed probability in pushed_inside // rules/nts will have same index as hg edges/nodes @@ -68,4 +89,5 @@ protected: int goal_nt; }; + #endif -- cgit v1.2.3