summaryrefslogtreecommitdiff
path: root/decoder/cfg.h
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-10 10:02:04 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-10 10:02:04 +0000
commit32154b45828f05add1db7c89752ef4220c0fdf16 (patch)
treefa99e4d4847a89d41b464e9ae3c9aacf611e5500 /decoder/cfg.h
parent43db0573b15719d48b89b3a1ad2828036d008560 (diff)
cdec --cfg_output=-
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@499 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/cfg.h')
-rwxr-xr-xdecoder/cfg.h24
1 files changed, 23 insertions, 1 deletions
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<WordID> RHS; // same as in trule rhs: >0 means token, <=0 means -node index (not variable index)
typedef std::vector<RuleHandle> 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