summaryrefslogtreecommitdiff
path: root/decoder/cfg.cc
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 05:05:19 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 05:05:19 +0000
commitc142f3bde0fa673ddb3f6fc7ed3d08e71f8ff8eb (patch)
treef94444f0c7652955313135f4bdf120359324ef89 /decoder/cfg.cc
parentf930e4efe2c594ac87ea650841fcb751159e909c (diff)
fixed binarization. test
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@554 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/cfg.cc')
-rwxr-xr-xdecoder/cfg.cc30
1 files changed, 24 insertions, 6 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc
index c2d96b33..c0598f16 100755
--- a/decoder/cfg.cc
+++ b/decoder/cfg.cc
@@ -182,7 +182,7 @@ void CFG::Binarize(CFGBinarize const& b) {
NTs new_nts; // these will be appended at the end, so we don't have to worry about iterator invalidation
Rules new_rules;
//TODO: this could be factored easily into in-place (append to new_* like below) and functional (nondestructive copy) versions (copy orig to target and append to target)
- int newnt=nts.size();
+ int newnt=-nts.size();
int newruleid=rules.size();
BinRhs bin;
for (NTs::const_iterator n=nts.begin(),nn=nts.end();n!=nn;++n) {
@@ -192,21 +192,29 @@ void CFG::Binarize(CFGBinarize const& b) {
if (rhs.empty()) continue;
bin.second=rhs.back();
for (int r=rhs.size()-2;r>=rhsmin;--r) { // pairs from right to left (normally we leave the last pair alone)
- rhs.pop_back();
bin.first=rhs[r];
if (newnt==(bin.second=(get_default(bin2lhs,bin,newnt)))) {
- new_nts.push_back(NT());
- new_nts.back().ruleids.push_back(newruleid);
- new_rules.push_back(Rule(newnt,bin));
+ new_nts.push_back(NT(newruleid));
+ new_rules.push_back(Rule(-newnt,bin));
+ ++newruleid;
if (b.bin_name_nts)
new_nts.back().from.nt=BinName(bin,nts,new_nts);
- ++newnt;++newruleid;
+ --newnt;
}
}
+ if (rhsmin<rhs.size()) {
+ rhs[rhsmin]=bin.second;
+ rhs.resize(rhsmin+1);
+ }
}
}
+#if 0
batched_append_swap(nts,new_nts);
batched_append_swap(rules,new_rules);
+#else
+ batched_append(nts,new_nts);
+ batched_append(rules,new_rules);
+#endif
if (b.bin_topo) //TODO: more efficient (at least for l2r) maintenance of order
OrderNTsTopo();
}
@@ -302,3 +310,13 @@ void CFG::Print(std::ostream &o,CFGFormat const& f) const {
}
}
}
+
+void CFG::Print(std::ostream &o) const {
+ Print(o,CFGFormat());
+}
+
+
+std::ostream &operator<<(std::ostream &o,CFG const &x) {
+ x.Print(o);
+ return o;
+}