blob: 1f59afaf57ecab4b875df1eb7bed89ff5d24a076 (
plain)
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
|
#include "config.h"
#ifndef HAVE_CMPH
int main() {
return 0;
}
#else
#include <iostream>
#include "weights.h"
#include "fdict.h"
using namespace std;
int main(int argc, char** argv) {
if (argc != 2) { cerr << "Usage: " << argv[0] << " file.mphf\n"; return 1; }
FD::EnableHash(argv[1]);
cerr << "Number of keys: " << FD::NumFeats() << endl;
cerr << "LexFE = " << FD::Convert("LexFE") << endl;
cerr << "LexEF = " << FD::Convert("LexEF") << endl;
{
Weights w;
vector<weight_t> v(FD::NumFeats());
v[FD::Convert("LexFE")] = 1.0;
v[FD::Convert("LexEF")] = 0.5;
w.InitFromVector(v);
cerr << "Writing...\n";
w.WriteToFile("weights.bin");
cerr << "Done.\n";
}
{
Weights w;
vector<weight_t> v(FD::NumFeats());
cerr << "Reading...\n";
w.InitFromFile("weights.bin");
cerr << "Done.\n";
w.InitVector(&v);
assert(v[FD::Convert("LexFE")] == 1.0);
assert(v[FD::Convert("LexEF")] == 0.5);
}
}
#endif
|