diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-13 03:51:20 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-13 03:51:20 +0000 |
commit | 84009c98d9a0a2e3ecd801ebb92ed47ee3f3328b (patch) | |
tree | 9fa1f2467d4c7b82444652498d31622c99d69ebd /decoder | |
parent | 46349d90291dc755225863552eb19beb1038c505 (diff) |
binarized cfg names improved
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@538 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder')
-rwxr-xr-x | decoder/cfg.cc | 4 | ||||
-rwxr-xr-x | decoder/cfg_format.h | 3 | ||||
-rwxr-xr-x | decoder/nt_span.h | 22 |
3 files changed, 20 insertions, 9 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc index aa9e5f30..8fc5b10f 100755 --- a/decoder/cfg.cc +++ b/decoder/cfg.cc @@ -22,8 +22,8 @@ WordID BinName(CFG::BinRhs const& b,CFG::NTs const& N,CFG::NTs const& M) 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; } \ + if (i<nn) o<<N[i].from<<i; else o<<M[i-nn].from; \ + } \ } while(0) BinNameOWORD(b.first); diff --git a/decoder/cfg_format.h b/decoder/cfg_format.h index ccf6e3fa..d56d42f2 100755 --- a/decoder/cfg_format.h +++ b/decoder/cfg_format.h @@ -67,7 +67,8 @@ struct CFGFormat { o<<nt_prefix; if (nt_span) cfg.print_nt_name(o,id); - o<<id; + else + o<<id; } template <class CFG> diff --git a/decoder/nt_span.h b/decoder/nt_span.h index 46234b07..a918f301 100755 --- a/decoder/nt_span.h +++ b/decoder/nt_span.h @@ -8,10 +8,15 @@ struct Span { int l,r; Span() : l(-1) { } + bool is_null() const { return l<0; } + void print(std::ostream &o,char const* for_null="") const { + if (is_null()) + o<<for_null; + else + o<<'<'<<l<<','<<r<<'>'; + } friend inline std::ostream &operator<<(std::ostream &o,Span const& s) { - if (s.l<0) - return o; - return o<<'<'<<s.l<<','<<s.r<<'>'; + s.print(o);return o; } }; @@ -20,10 +25,15 @@ struct NTSpan { WordID nt; // awkward: this is a positive index, used in TD. but represented as negative in mixed terminal/NT space in rules/hgs. NTSpan() : nt(0) { } // prints as possibly empty name (whatever you set of nt,s will show) + void print(std::ostream &o,char const* for_span_null="_",char const* for_null="") const { + if (nt>0) { + o<<TD::Convert(nt); + s.print(o,for_span_null); + } else + s.print(o,for_null); + } friend inline std::ostream &operator<<(std::ostream &o,NTSpan const& t) { - if (t.nt>0) - o<<TD::Convert(t.nt); - return o << t.s; + t.print(o);return o; } }; |