-
Notifications
You must be signed in to change notification settings - Fork 3
/
stakk.cc
63 lines (57 loc) · 1.47 KB
/
stakk.cc
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
#include "stakk.h"
using namespace stakk;
int main(int argc, char *argv[]) {
//parse option
int result, threshold = 1;
string dictionary_ = "data/dictionary.txt";
string connection_ = "data/connection.txt";
string mode = "spell";
bool reverse = false;
try { locale::global(locale("")); } catch (...) {}
while((result = getopt(argc, argv, "d:c:t:m:r")) != -1) {
switch(result) {
case 'd':
dictionary_ = optarg;
break;
case 'c':
connection_ = optarg;
break;
case 't':
threshold = atoi(optarg);
break;
case 'm':
mode = optarg;
break;
case 'r':
reverse = true;
break;
}
}
wcout << "loading dictionary" << endl;
WideTrie trie;
int field = reverse ? 4 : 0;
if (!trie.load(dictionary_, field, L'\t')) {
cout << dictionary_ << " is not found." << endl;
exit(0);
}
wcout << "loading connection" << endl;
Connection connection;
if (!connection.load(connection_)) {
cout << connection_ << " is not found." << endl;
exit(0);
}
Stakk stakk(trie, connection);
wstring line;
wcout << "input query: " << endl;
while (getline(wcin, line)) {
vector<Stakk::Entry> result;
if (mode == "spell")
stakk.correct(line, threshold, result);
if (mode == "predict")
stakk.predict(line, result);
for (int i = 0; i < min(50, (int)result.size()); i++) {
wcout << result[i].format() << endl;
}
}
return 0;
}