From 41286716a6b90e78eb3abe3aa5f1620bc5f0f605 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 17 May 2012 14:55:52 +0800 Subject: update utils/storage --- utils/storage/export_interpolation.cpp | 24 ++++++++++++++++-------- utils/storage/import_interpolation.cpp | 31 +++++++++++++++---------------- 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); -- cgit