diff options
Diffstat (limited to 'decoder/cfg.h')
-rwxr-xr-x | decoder/cfg.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/decoder/cfg.h b/decoder/cfg.h index a390ece9..19d30f8b 100755 --- a/decoder/cfg.h +++ b/decoder/cfg.h @@ -27,6 +27,7 @@ //#include "int_or_pointer.h" #include "small_vector.h" #include "nt_span.h" +#include <algorithm> class Hypergraph; class CFGFormat; // #include "cfg_format.h" @@ -42,7 +43,16 @@ struct CFG { o << nts[n].from; } + typedef std::pair<int,int> BinRhs; + WordID BinName(BinRhs const& b); + struct Rule { + // for binarizing - no costs/probs + Rule(int lhs,BinRhs const& binrhs) : lhs(lhs),rhs(2),p(1) { + rhs[0]=binrhs.first; + rhs[1]=binrhs.second; + } + int lhs; // index into nts RHS rhs; prob_t p; // h unused for now (there's nothing admissable, and p is already using 1st pass inside as pushed toward top) @@ -50,11 +60,26 @@ struct CFG { #if CFG_DEBUG TRulePtr rule; // normally no use for this (waste of space) #endif + void Swap(Rule &o) { + using namespace std; + swap(lhs,o.lhs); + swap(rhs,o.rhs); + swap(p,o.p); + swap(f,o.f); +#if CFG_DEBUG + swap(rule,o.rule); +#endif + } }; struct NT { Ruleids ruleids; // index into CFG rules with lhs = this NT. aka in_edges_ NTSpan from; // optional name - still needs id to disambiguate + void Swap(NT &o) { + using namespace std; + swap(ruleids,o.ruleids); + swap(from,o.from); + } }; CFG() : hg_() { uninit=true; } @@ -92,5 +117,9 @@ protected: int goal_nt; }; +inline void swap(CFG &a,CFG &b) { + a.Swap(b); +} + #endif |