From c7f1a4e30a42ad0c03ac6c439e04e6aa7efafefe Mon Sep 17 00:00:00 2001 From: "graehl@gmail.com" Date: Sun, 15 Aug 2010 08:50:14 +0000 Subject: files required for test git-svn-id: https://ws10smt.googlecode.com/svn/trunk@556 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/cfg.cc | 59 +++++++++++++++++++++++++--------------- decoder/cfg.h | 16 +++++++++-- decoder/cfg_test.cc | 7 ++++- decoder/test_data/perro.json.gz | Bin 0 -> 608 bytes decoder/test_data/urdu.json.gz | Bin 0 -> 253497 bytes utils/show.h | 41 ++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 decoder/test_data/perro.json.gz create mode 100644 decoder/test_data/urdu.json.gz create mode 100755 utils/show.h diff --git a/decoder/cfg.cc b/decoder/cfg.cc index be07c2c5..3076c75e 100755 --- a/decoder/cfg.cc +++ b/decoder/cfg.cc @@ -7,12 +7,12 @@ #include #include "fast_lexical_cast.hpp" //#include "indices_after.h" +#include "show.h" + +#define DUNIQ(x) x +#define DBIN(x) +#define DCFG(x) IF_CFG_DEBUG(x) -#define CFGPRINT(x) IF_CFG_DEBUG(std::cerr< Seen; // 0 = unseen, 1 = seen+finished, 2 = open (for cycle detection; seen but not finished) enum { UNSEEN=0,SEEN,OPEN }; - // bottom -> top topo order (rev head->tails topo) template struct CFGTopo { @@ -120,22 +119,28 @@ int CFG::UniqRules(NTHandle ni) { HASH_MAP_EMPTY(bestp,null_rhs); Ruleids &adj=nts[ni].ruleids; Ruleids oldadj=adj; - int oi=0; + int newpos=0; for (int i=0,e=oldadj.size();i!=e;++i) { // this beautiful complexity is to ensure that adj' is a subsequence of adj (without duplicates) int ri=oldadj[i]; Rule const& r=rules[ri]; - prob_pos pi(r.p,oi); + prob_pos pi(r.p,newpos); prob_pos &oldpi=get_default(bestp,r.rhs,pi); - if (oldpi.pos==oi) {// newly inserted - adj[oi++]=ri; - } else if (oldpi.prob=0 also @@ -214,7 +220,7 @@ void CFG::Binarize(CFGBinarize const& b) { bin.first=rhs[r]; bin_to=get_default(bin2lhs,bin,newnt); - CFGSHOWS(r) CFGSHOWS(newnt) CFGPRINT("bin="<") CFGSHOW(bin_to); + SHOW(DBIN,r) SHOW(DBIN,newnt) SHOWP(DBIN,"bin="<") SHOW(DBIN,bin_to); if (newnt==bin_to) { // it's new! new_nts.push_back(NT(newruleid++)); //now -newnt is the index of the last (after new_nts is appended) nt. bin is its rhs. bin_to is its lhs @@ -232,7 +238,7 @@ void CFG::Binarize(CFGBinarize const& b) { } } } -#if 0 +#if 1 batched_append_swap(nts,new_nts); batched_append_swap(rules,new_rules); #else @@ -304,6 +310,10 @@ void CFG::Clear() { hg_=0; } +namespace { +CFGFormat form; +} + void CFG::PrintRule(std::ostream &o,RuleHandle rulei,CFGFormat const& f) const { Rule const& r=rules[rulei]; f.print_lhs(o,*this,r.lhs); @@ -311,6 +321,12 @@ void CFG::PrintRule(std::ostream &o,RuleHandle rulei,CFGFormat const& f) const { f.print_features(o,r.p,r.f); IF_CFG_TRULE(if (r.rule) o<=0) { @@ -75,6 +79,7 @@ TEST_P(CFGTest,Binarize) { CFG cc=uniq?cfgu:cfg; CSHOW("\nBinarizing "<<(uniq?"uniqued ":"")<<": "< "< +#endif +/* usage: +#if DEBUG +# define IFD(x) x +#else +# define IFD(x) +#endif + +SHOWS(IFD,x) SHOWS(IFD,y) SHOW(IFD,nl_after) + +will print x=X y=Y nl_after=NL_AFTER\n if DEBUG. + +SHOW3(IFD,x,y,nl_after) is short for the same + +SHOWP("a") will just print "a" + +careful: none of this is wrapped in a block. so you can't use one of these macros as a single-line block. + + */ + +#ifndef SHOWS +#define SHOWS std::cerr +#endif + +#define SHOWP(IF,x) IF(SHOWS<