summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-12-02 17:38:46 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-02 17:38:46 +0800
commit1b975d9f86c1ccbace5e2a06080325fe5f42879b (patch)
treec17076d97c65ee6fcc1d52feaa484e906281da3b
parent23d9cb43b3880a8ce5daf896d7b1df931e3cdbba (diff)
downloadlibpinyin-1b975d9f86c1ccbace5e2a06080325fe5f42879b.tar.gz
libpinyin-1b975d9f86c1ccbace5e2a06080325fe5f42879b.tar.xz
libpinyin-1b975d9f86c1ccbace5e2a06080325fe5f42879b.zip
write load text method for chewing large table
-rw-r--r--src/storage/chewing_large_table.cpp37
-rw-r--r--src/storage/pinyin_large_table.cpp4
2 files changed, 39 insertions, 2 deletions
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 <assert.h>
#include "pinyin_phrase2.h"
+#include "pinyin_parser2.h"
/* internal class definition */
@@ -618,3 +619,39 @@ int ChewingArrayIndexLevel<phrase_length>::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;
}