From 1b975d9f86c1ccbace5e2a06080325fe5f42879b Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 2 Dec 2011 17:38:46 +0800 Subject: write load text method for chewing large table --- src/storage/chewing_large_table.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/storage/pinyin_large_table.cpp | 4 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'src/storage') diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index 4d35996..428a1f6 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -22,6 +22,7 @@ #include "chewing_large_table.h" #include #include "pinyin_phrase2.h" +#include "pinyin_parser2.h" /* internal class definition */ @@ -618,3 +619,39 @@ int ChewingArrayIndexLevel::remove_index m_chunk.remove_content(offset, sizeof(IndexItem)); return REMOVE_OK; } + + +/* load text method */ +bool ChewingLargeTable::load_text(FILE * infile) { + char pinyin[256]; + char phrase[256]; + phrase_token_t token; + size_t freq; + + while (!feof(infile)) { + fscanf(infile, "%s", pinyin); + fscanf(infile, "%s", phrase); + fscanf(infile, "%u", &token); + fscanf(infile, "%ld", &freq); + + if(feof(infile)) + break; + + FullPinyinParser2 parser; + ChewingKeyVector keys; + ChewingKeyRestVector key_rests; + + keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); + key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); + + pinyin_option_t options = USE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + + add_index(keys->len, (ChewingKey *)keys->data, token); + + g_array_free(keys, TRUE); + g_array_free(key_rests, TRUE); + } + + return true; +} diff --git a/src/storage/pinyin_large_table.cpp b/src/storage/pinyin_large_table.cpp index 952287a..6f3ccb8 100644 --- a/src/storage/pinyin_large_table.cpp +++ b/src/storage/pinyin_large_table.cpp @@ -557,8 +557,8 @@ bool PinyinLargeTable::load_text(FILE * infile){ add_index( keys->len, (PinyinKey *)keys->data, token); - g_array_free(keys, true); - g_array_free(poses, true); + g_array_free(keys, TRUE); + g_array_free(poses, TRUE); } return true; } -- cgit