-
Notifications
You must be signed in to change notification settings - Fork 3
/
uconverter.cc
69 lines (62 loc) · 1.58 KB
/
uconverter.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
64
65
66
67
68
69
#include "uconverter.h"
using namespace stakk;
int main(int argc, char *argv[]) {
//parse option
int result;
string dictionary_ = "data/dictionary.txt";
string connection_ = "data/connection.txt";
string id_def = "data/id.def";
string output = "mecab";
bool reverse = false;
bool debug = false;
try { locale::global(locale("")); } catch (...) {}
while((result = getopt(argc, argv, "d:c:i:o:rb")) != -1) {
switch(result) {
case 'd':
dictionary_ = optarg;
break;
case 'c':
connection_ = optarg;
break;
case 'i':
id_def = optarg;
break;
case 'o':
output = optarg;
break;
case 'r':
reverse = true;
break;
case 'b':
debug = true;
break;
}
}
cout << "loading dictionary" << endl;
UTrie trie;
int field = reverse ? 4 : 0;
if (!trie.load(dictionary_, field, L'\t')) {
cout << dictionary_ << " is not found." << endl;
exit(0);
}
cout << "loading connection" << endl;
Connection connection;
if (!connection.load(connection_)) {
cout << connection_ << " is not found." << endl;
exit(0);
}
cout << "loading id definition" << endl;
Definition definition;
if (!definition.load(id_def)) {
cout << id_def << " is not found." << endl;
exit(0);
}
Converter converter(trie, connection, definition);
wstring line;
cout << "input query: " << endl;
while (getline(wcin, line)) {
vector<Converter::Node> nodes = converter.convert(line, debug);
cout << converter.format(nodes, output);
}
return 0;
}