summaryrefslogtreecommitdiff
path: root/decoder/cfg.cc
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-13 03:30:49 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-13 03:30:49 +0000
commit6ca64b5cf2d4c0c2698d4298e88dde274f766ac4 (patch)
treec37af6ea1ae5159b8bea55a94b120359ba9188c3 /decoder/cfg.cc
parente1458e933f41a95bb5f98aeffbc15242ef7752f1 (diff)
named_enum, itoa, cdec replace --a-b=x with --a_b=x
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@536 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/cfg.cc')
-rwxr-xr-xdecoder/cfg.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc
index 81a17355..aa9e5f30 100755
--- a/decoder/cfg.cc
+++ b/decoder/cfg.cc
@@ -11,13 +11,21 @@ using namespace std;
namespace {
CFG::BinRhs nullrhs(std::numeric_limits<int>::min(),std::numeric_limits<int>::min());
-}
-
-WordID CFG::BinName(BinRhs const& b)
+// index i >= N.size()? then it's in M[i-N.size()]
+WordID BinName(CFG::BinRhs const& b,CFG::NTs const& N,CFG::NTs const& M)
{
+ int nn=N.size();
ostringstream o;
-#define BinNameOWORD(w) do { int n=w; if (n>0) o << TD::Convert(n); else { o << 'V' << -n; } } while(0)
+#define BinNameOWORD(w) \
+ do { \
+ int n=w; if (n>0) o << TD::Convert(n); \
+ else { \
+ int i=-n; \
+ CFG::NT const&nt = i<nn?N[i]:M[i-nn]; \
+ o << nt.from << i; } \
+ } while(0)
+
BinNameOWORD(b.first);
o<<'+';
BinNameOWORD(b.second);
@@ -25,6 +33,10 @@ WordID CFG::BinName(BinRhs const& b)
return TD::Convert(o.str());
}
+}
+
+
+
void CFG::Binarize(CFGBinarize const& b) {
if (!b.Binarizing()) return;
if (!b.bin_l2r) {
@@ -57,7 +69,7 @@ void CFG::Binarize(CFGBinarize const& b) {
new_nts.back().ruleids.push_back(newruleid);
new_rules.push_back(Rule(newnt,bin));
if (b.bin_name_nts)
- new_nts.back().from.nt=BinName(bin);
+ new_nts.back().from.nt=BinName(bin,nts,new_nts);
++newnt;++newruleid;
}
}