summaryrefslogtreecommitdiff
path: root/decoder/cfg_test.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2013-11-26 11:11:17 +0100
committerPatrick Simianer <p@simianer.de>2013-11-26 11:11:17 +0100
commita5b4f06838585874f200c94028cd4d41d54c4f76 (patch)
treea9248cb9c17e5b44f1e6758580befb8ef8bef08a /decoder/cfg_test.cc
parent4fffd2e746a4d6b643d35ae3fc4b374c770727c0 (diff)
parentb6c44f82ffca74cc38cf6039ac9ab3c2c66fd5d6 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'decoder/cfg_test.cc')
-rw-r--r--decoder/cfg_test.cc98
1 files changed, 0 insertions, 98 deletions
diff --git a/decoder/cfg_test.cc b/decoder/cfg_test.cc
deleted file mode 100644
index cbe7d0be..00000000
--- a/decoder/cfg_test.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-#include <boost/tuple/tuple.hpp>
-#include <gtest/gtest.h>
-#include "cfg.h"
-#include "hg_test.h"
-#include "cfg_options.h"
-#include "show.h"
-
-/* 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;
-#else
-# define CSHOWDO(x)
-#endif
-#define CSHOW(x) CSHOWDO(cerr<<#x<<'='<<x<<endl;)
-
-typedef std::pair<string,string> HgW; // hg file,weights
-
-struct CFGTest : public TestWithParam<HgW> {
- string hgfile;
- Hypergraph hg;
- CFG cfg;
- CFGFormat form;
- SparseVector<double> weights;
-
- static void JsonFN(Hypergraph &hg,CFG &cfg,SparseVector<double> &featw,std::string file
- ,std::string const& wts="Model_0 1 EgivenF 1 f1 1")
- {
- istringstream ws(wts);
- EXPECT_TRUE(ws>>featw);
- CSHOW(featw)
- std::string path(boost::unit_test::framework::master_test_suite().argc == 2 ? boost::unit_test::framework::master_test_suite().argv[1] : TEST_DATA);
- HGSetup::JsonTestFile(&hg,path,file);
- 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_P(CFGTest,Binarize) {
- CFGBinarize 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);
- //TODO - check that 1best is still the same (that we removed only worse edges)
- }
-
- 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);
- cerr<<"Binarized "<<b<<" rules size "<<cfg.rules_size()<<" => "<<cc.rules_size()<<"\n";
- 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();
-}