1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#ifndef HG_TEST_H
#define HG_TEST_H
#include "filelib.h"
#include "hg.h"
#include "hg_io.h"
#include <sstream>
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace {
typedef char const* Name;
Name urdu_json="urdu.bin.gz";
Name urdu_wts="Arity_0 1.70741473606976 Arity_1 1.12426238048012 Arity_2 1.14986187839554 Glue -0.04589037041388 LanguageModel 1.09051 PassThrough -3.66226367902928 PhraseModel_0 -1.94633451863252 PhraseModel_1 -0.1475347695476 PhraseModel_2 -1.614818994946 WordPenalty -3.0 WordPenaltyFsa -0.56028442964748 ShorterThanPrev -10 LongerThanPrev -10";
Name small_json="small.bin.gz";
Name small_wts="Model_0 -2 Model_1 -.5 Model_2 -1.1 Model_3 -1 Model_4 -1 Model_5 .5 Model_6 .2 Model_7 -.3";
Name perro_json="perro.bin.gz";
Name perro_wts="SameFirstLetter 1 LongerThanPrev 1 ShorterThanPrev 1 GlueTop 0.0 Glue -1.0 EgivenF -0.5 FgivenE -0.5 LexEgivenF -0.5 LexFgivenE -0.5 LM 1";
}
// you can inherit from this or just use the static methods
struct HGSetup {
static void CreateHG(const std::string& path,Hypergraph* hg);
static void CreateHG_int(const std::string& path,Hypergraph* hg);
static void CreateHG_tiny(const std::string& path, Hypergraph* hg);
static void CreateHGBalanced(const std::string& path,Hypergraph* hg);
static void CreateLatticeHG(const std::string& path,Hypergraph* hg);
static void CreateTinyLatticeHG(const std::string& path,Hypergraph* hg);
static void JsonFile(Hypergraph *hg,std::string f) {
ReadFile rf(f);
HypergraphIO::ReadFromBinary(rf.stream(), hg);
}
static void JsonTestFile(Hypergraph *hg,std::string path,std::string n) {
JsonFile(hg,path + "/"+n);
}
static void CreateSmallHG(Hypergraph *hg, std::string path) { JsonTestFile(hg,path,small_json); }
};
void AddNullEdge(Hypergraph* hg) {
TRule x;
x.arity_ = 0;
hg->nodes_[0].in_edges_.push_back(hg->AddEdge(TRulePtr(new TRule(x)), Hypergraph::TailNodeVector())->id_);
hg->edges_.back().head_node_ = 0;
}
void HGSetup::CreateTinyLatticeHG(const std::string& path,Hypergraph* hg) {
ReadFile rf(path + "/hg_test.tiny_lattice.bin.gz");
HypergraphIO::ReadFromBinary(rf.stream(), hg);
AddNullEdge(hg);
}
void HGSetup::CreateLatticeHG(const std::string& path,Hypergraph* hg) {
ReadFile rf(path + "/hg_test.lattice.bin.gz");
HypergraphIO::ReadFromBinary(rf.stream(), hg);
AddNullEdge(hg);
}
void HGSetup::CreateHG_tiny(const std::string& path, Hypergraph* hg) {
ReadFile rf(path + "/hg_test.tiny.bin.gz");
HypergraphIO::ReadFromBinary(rf.stream(), hg);
}
void HGSetup::CreateHG_int(const std::string& path,Hypergraph* hg) {
ReadFile rf(path + "/hg_test.hg_int.bin.gz");
HypergraphIO::ReadFromBinary(rf.stream(), hg);
}
void HGSetup::CreateHG(const std::string& path,Hypergraph* hg) {
ReadFile rf(path + "/hg_test.hg.bin.gz");
HypergraphIO::ReadFromBinary(rf.stream(), hg);
}
void HGSetup::CreateHGBalanced(const std::string& path,Hypergraph* hg) {
ReadFile rf(path + "/hg_test.hg_balanced.bin.gz");
HypergraphIO::ReadFromBinary(rf.stream(), hg);
}
#endif
|