Skip to content

Commit fde1c09

Browse files
author
nokuno
committedSep 9, 2012
add option to specify trie number in marisa-trie
1 parent 1f7c9d5 commit fde1c09

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ You can provide queries through standard input line by line.
4949
options:
5050
-d directory: specify data directory or prefix (default: ./)
5151
-m model: specify model file name (default: ngram)
52+
-t trie_num: specify trie number in marisa-trie (default: 3)
5253
-r: build reverse model
5354

5455
### jsc-server

‎src/builder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace jsc {
44

5-
bool Builder::Build(const char *filename, const char *prefix, bool reverse) {
5+
bool Builder::Build(const char *filename, const char *prefix, bool reverse, int trie_num) {
66

77
// open text file
88
fstream fs(filename);
@@ -96,7 +96,7 @@ bool Builder::Build(const char *filename, const char *prefix, bool reverse) {
9696
}
9797
// build and save source trie
9898
marisa::Trie source_trie;
99-
source_trie.build(source_keyset);
99+
source_trie.build(source_keyset, trie_num);
100100
{
101101
string file(prefix);
102102
file.append(SOURCE_TRIE);
@@ -106,7 +106,7 @@ bool Builder::Build(const char *filename, const char *prefix, bool reverse) {
106106
// build and save ngram trie
107107
// Notice: ngram trie is used later for building entry array.
108108
marisa::Trie ngram_trie;
109-
ngram_trie.build(ngram_keyset);
109+
ngram_trie.build(ngram_keyset, trie_num);
110110
{
111111
string file(prefix);
112112
file.append(NGRAM_TRIE);

‎src/builder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Builder {
1818
// 5) Sort source array by source_id
1919
// 6) Extract offset of source_id
2020
// 7) Save offset and entry array as binary
21-
bool Build(const char *filename, const char *prefix, bool reverse=false);
21+
bool Build(const char *filename, const char *prefix, bool reverse=false, int trie_num=3);
2222
};
2323

2424
}

‎tools/jsc-build.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ int main(int argc, char **argv) {
66
string model = "ngram";
77

88
bool reverse = false;
9+
int trie_num = 3;
910
int c;
10-
while ((c = getopt (argc, argv, "d:m:r")) != -1) {
11+
while ((c = getopt (argc, argv, "d:m:t:r")) != -1) {
1112
switch (c) {
1213
case 'd':
1314
prefix = optarg;
@@ -18,6 +19,9 @@ int main(int argc, char **argv) {
1819
case 'r':
1920
reverse = true;
2021
break;
22+
case 't':
23+
trie_num = atoi(optarg);
24+
break;
2125
case '?':
2226
cerr << "Unknown option -" << optopt << endl;
2327
return 1;
@@ -28,7 +32,7 @@ int main(int argc, char **argv) {
2832
{
2933
Builder builder;
3034
cerr << "Building model..." << endl;
31-
bool result = builder.Build(model.c_str(), prefix.c_str(), reverse);
35+
bool result = builder.Build(model.c_str(), prefix.c_str(), reverse, trie_num);
3236
if (result) {
3337
cerr << "Succeeded to build model." << endl;
3438
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.