summaryrefslogtreecommitdiff
path: root/decoder/cfg.cc
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 01:34:57 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 01:34:57 +0000
commit5368e9dda4edf813618f3d5179973ff6a3c11b7a (patch)
tree03f1088054d848870eba6e31ba585c575b129116 /decoder/cfg.cc
parentb5bd75ab4a66e61e724fcb9488d164a3936a6b4e (diff)
debug cfg from hg, source and target. cdec --source_cfg_output=-
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@507 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/cfg.cc')
-rwxr-xr-xdecoder/cfg.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc
index c43ff9d0..0dfd04d5 100755
--- a/decoder/cfg.cc
+++ b/decoder/cfg.cc
@@ -17,6 +17,13 @@ void CFG::Binarize(CFGBinarize const& b) {
//TODO.
}
+namespace {
+inline int nt_index(int nvar,Hypergraph::TailNodeVector const& t,bool target_side,int w) {
+ assert(w<0 || (target_side&&w==0));
+ return t[target_side?-w:nvar];
+}
+}
+
void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool push_weights) {
uninit=false;
hg_=&hg;
@@ -34,8 +41,6 @@ void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool pus
for (int i=0;i<ne;++i) {
Rule &cfgr=rules[i];
Hypergraph::Edge const& e=hg.edges_[i];
- TRule const& er=*e.rule_; vector<WordID> const& rule_rhs=target_side?er.e():er.f();
- RHS &rhs=cfgr.rhs;
prob_t &crp=cfgr.p;
crp=e.edge_prob_;
cfgr.lhs=e.head_node_;
@@ -44,18 +49,27 @@ void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool pus
#endif
if (copy_features) cfgr.f=e.feature_values_;
if (push_weights) crp /=np[e.head_node_];
+ TRule const& er=*e.rule_;
+ vector<WordID> const& rule_rhs=target_side?er.e():er.f();
int nr=rule_rhs.size();
- rhs.resize(nr);
+ RHS &rhs_out=cfgr.rhs;
+ rhs_out.resize(nr);
+ Hypergraph::TailNodeVector const& tails=e.tail_nodes_;
+ int nvar=0;
+ //split out into separate target_side, source_side loops?
for (int j=0;j<nr;++j) {
WordID w=rule_rhs[j];
if (w>0)
- rhs[j]=w;
+ rhs_out[j]=w;
else {
- int n=e.tail_nodes_[-w];
+ int n=nt_index(nvar,tails,target_side,w);
+ ++nvar;
if (push_weights) crp*=np[n];
- rhs[j]=n;
+ rhs_out[j]=n;
}
}
+ assert(nvar==er.Arity());
+ assert(nvar==tails.size());
}
}