summaryrefslogtreecommitdiff
path: root/decoder/cfg_test.cc
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 07:39:01 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 07:39:01 +0000
commit6d3cf2f3aeaa5d008f5031f70da8d728181486bc (patch)
tree69b0d6e35b65075ddfeb97a7fbf85f87ec513dfe /decoder/cfg_test.cc
parentc142f3bde0fa673ddb3f6fc7ed3d08e71f8ff8eb (diff)
really fixed binarization. test
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@555 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/cfg_test.cc')
-rwxr-xr-xdecoder/cfg_test.cc80
1 files changed, 56 insertions, 24 deletions
diff --git a/decoder/cfg_test.cc b/decoder/cfg_test.cc
index 81efa768..cde4706c 100755
--- a/decoder/cfg_test.cc
+++ b/decoder/cfg_test.cc
@@ -1,23 +1,34 @@
+#include <boost/tuple/tuple.hpp>
#include <gtest/gtest.h>
#include "cfg.h"
#include "hg_test.h"
#include "cfg_options.h"
-#define CSHOW_V 1
+/* TODO: easiest way to get meaningful confirmations that things work: implement conversion back to hg, and compare viterbi/inside etc. stats for equality to original hg. or you can define CSHOW_V and see lots of output */
+
+using namespace boost;
+
+#define CSHOW_V 0
+
#if CSHOW_V
-# define CSHOWDO(x) x
+# define CSHOWDO(x) x;
#else
# define CSHOWDO(x)
#endif
#define CSHOW(x) CSHOWDO(cerr<<#x<<'='<<x<<endl;)
-struct CFGTest : public HGSetup {
- CFGTest() { }
- ~CFGTest() { }
- static void JsonFN(Hypergraph hg,CFG &cfg,std::string file
+typedef std::pair<string,string> HgW; // hg file,weights
+
+struct CFGTest : public TestWithParam<HgW> {
+ string hgfile;
+ Hypergraph hg;
+ CFG cfg;
+ CFGFormat form;
+ FeatureVector weights;
+
+ static void JsonFN(Hypergraph &hg,CFG &cfg,FeatureVector &featw,std::string file
,std::string const& wts="Model_0 1 EgivenF 1 f1 1")
{
- FeatureVector featw;
istringstream ws(wts);
EXPECT_TRUE(ws>>featw);
CSHOW(featw)
@@ -25,35 +36,56 @@ struct CFGTest : public HGSetup {
hg.Reweight(featw);
cfg.Init(hg,true,true,false);
}
-
static void SetUpTestCase() {
}
static void TearDownTestCase() {
}
+ CFGTest() {
+ hgfile=GetParam().first;
+ JsonFN(hg,cfg,weights,hgfile,GetParam().second);
+ CSHOWDO(cerr<<"\nCFG Test: ")
+ CSHOW(hgfile);
+ form.nt_span=true;
+ form.comma_nt=false;
+ }
+ ~CFGTest() { }
};
-TEST_F(CFGTest,Binarize) {
- Hypergraph hg;
- CFG cfg;
- JsonFN(hg,cfg,perro_json,perro_wts);
- CSHOW("\nCFG Test.\n");
+TEST_P(CFGTest,Binarize) {
CFGBinarize b;
- CFGFormat form;
- form.nt_span=true;
- for (int i=-1;i<16;++i) {
- b.bin_l2r=i>=0;
- b.bin_unary=i&1;
- b.bin_name_nts=i&2;
- b.bin_uniq=i&4;
- b.bin_topo=i&8;
- CFG cc=cfg;
- EXPECT_EQ(cc,cfg);
- CSHOW("\nBinarizing: "<<b);
+ b.bin_name_nts=1;
+ CFG cfgu=cfg;
+ EXPECT_EQ(cfgu,cfg);
+ int nrules=cfg.rules.size();
+ CSHOWDO(cerr<<"\nUniqing: "<<nrules<<"\n");
+ int nrem=cfgu.UniqRules();
+ cerr<<"\nCFG "<<hgfile<<" Uniqed - remaining: "<<nrem<<" of "<<nrules<<"\n";
+ if (nrem==nrules)
+ EXPECT_EQ(cfgu,cfg);
+ for (int i=-1;i<8;++i) {
+ bool uniq;
+ if (i>=0) {
+ int f=i<<1;
+ b.bin_l2r=1;
+ b.bin_unary=(f>>=1)&1;
+ b.bin_topo=(f>>=1)&1;
+ uniq=(f>>=1)&1;
+ } else
+ b.bin_l2r=0;
+ CFG cc=uniq?cfgu:cfg;
+ CSHOW("\nBinarizing "<<(uniq?"uniqued ":"")<<": "<<i<<" "<<b);
cc.Binarize(b);
CSHOWDO(cc.Print(cerr,form);cerr<<"\n\n";);
}
}
+INSTANTIATE_TEST_CASE_P(HypergraphsWeights,CFGTest,
+ Values(
+ HgW(perro_json,perro_wts)
+ , HgW(small_json,small_wts)
+ ,HgW(urdu_json,urdu_wts)
+ ));
+
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();