summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-05-17 14:55:52 +0800
committerPeng Wu <alexepico@gmail.com>2012-05-17 14:55:52 +0800
commit41286716a6b90e78eb3abe3aa5f1620bc5f0f605 (patch)
treea1d70d8c70d65769bb4cc9ed9a893af5a5065e02
parent2c7b0915ced93c79938826e05922f4230c94d332 (diff)
downloadlibpinyin-41286716a6b90e78eb3abe3aa5f1620bc5f0f605.tar.gz
libpinyin-41286716a6b90e78eb3abe3aa5f1620bc5f0f605.tar.xz
libpinyin-41286716a6b90e78eb3abe3aa5f1620bc5f0f605.zip
update utils/storage
-rw-r--r--utils/storage/export_interpolation.cpp24
-rw-r--r--utils/storage/import_interpolation.cpp31
2 files changed, 31 insertions, 24 deletions
diff --git a/utils/storage/export_interpolation.cpp b/utils/storage/export_interpolation.cpp
index 93854b6..a049975 100644
--- a/utils/storage/export_interpolation.cpp
+++ b/utils/storage/export_interpolation.cpp
@@ -44,18 +44,26 @@ bool end_data(FILE * output){
int main(int argc, char * argv[]){
FILE * output = stdout;
const char * bigram_filename = "bigram.db";
+ MemoryChunk * chunk = NULL;
FacadePhraseIndex phrase_index;
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ const char * bin_file = pinyin_phrase_files[i];
+ if (NULL == bin_file)
+ continue;
- //gb_char binary file
- MemoryChunk * chunk = new MemoryChunk;
- chunk->load("gb_char.bin");
- phrase_index.load(1, chunk);
+ gchar * filename = g_build_filename("..", "..", "data",
+ bin_file, NULL);
+ chunk = new MemoryChunk;
+ bool retval = chunk->load(filename);
+ if (!retval) {
+ fprintf(stderr, "open %s failed!\n", bin_file);
+ exit(ENOENT);
+ }
- //gbk_char binary file
- chunk = new MemoryChunk;
- chunk->load("gbk_char.bin");
- phrase_index.load(2, chunk);
+ phrase_index.load(i, chunk);
+ g_free(filename);
+ }
Bigram bigram;
bigram.attach(bigram_filename, ATTACH_READONLY);
diff --git a/utils/storage/import_interpolation.cpp b/utils/storage/import_interpolation.cpp
index e005884..de67384 100644
--- a/utils/storage/import_interpolation.cpp
+++ b/utils/storage/import_interpolation.cpp
@@ -207,24 +207,23 @@ int main(int argc, char * argv[]){
phrases.load(chunk);
FacadePhraseIndex phrase_index;
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ const char * bin_file = pinyin_phrase_files[i];
+ if (NULL == bin_file)
+ continue;
+
+ gchar * filename = g_build_filename("..", "..", "data",
+ bin_file, NULL);
+ chunk = new MemoryChunk;
+ bool retval = chunk->load(filename);
+ if (!retval) {
+ fprintf(stderr, "open %s failed!\n", bin_file);
+ exit(ENOENT);
+ }
- //gb_char binary file
- chunk = new MemoryChunk;
- retval = chunk->load("gb_char.bin");
- if (!retval) {
- fprintf(stderr, "open gb_char.bin failed!\n");
- exit(ENOENT);
- }
- phrase_index.load(1, chunk);
-
- //gbk_char binary file
- chunk = new MemoryChunk;
- retval = chunk->load("gbk_char.bin");
- if (!retval) {
- fprintf(stderr, "open gbk_char.bin failed!\n");
- exit(ENOENT);
+ phrase_index.load(i, chunk);
+ g_free(filename);
}
- phrase_index.load(2, chunk);
Bigram bigram;
retval = bigram.attach(bigram_filename, ATTACH_CREATE|ATTACH_READWRITE);