summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pinyin.cpp1
-rw-r--r--tests/lookup/test_simple_lookup.cpp4
-rw-r--r--tests/test_pinyin.cpp28
3 files changed, 31 insertions, 2 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 5ac5a07..4bc000a 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -355,6 +355,7 @@ bool pinyin_save(pinyin_context_t * context){
oldchunk = new MemoryChunk; newlog = new MemoryChunk;
filename = g_build_filename(context->m_system_dir,
"gbk_char.bin", NULL);
+ oldchunk->load(filename);
context->m_phrase_index->diff(2, oldchunk, newlog);
filename = g_build_filename(context->m_user_dir,
"gbk_char.dbin", NULL);
diff --git a/tests/lookup/test_simple_lookup.cpp b/tests/lookup/test_simple_lookup.cpp
index 96c512a..6a2ebcf 100644
--- a/tests/lookup/test_simple_lookup.cpp
+++ b/tests/lookup/test_simple_lookup.cpp
@@ -52,8 +52,8 @@ int main( int argc, char * argv[]){
PinyinLookup pinyin_lookup(&custom, &largetable, &phrase_index,
&system_bigram, &user_bigram);
- char* linebuf = (char *)malloc ( 1024 * sizeof (char) );
- size_t size = 1024;
+ char* linebuf = NULL;
+ size_t size = 0;
while( getline(&linebuf, &size, stdin) ){
linebuf[strlen(linebuf)-1] = '\0';
if ( strcmp ( linebuf, "quit" ) == 0)
diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp
index 2212534..ee8f9d2 100644
--- a/tests/test_pinyin.cpp
+++ b/tests/test_pinyin.cpp
@@ -23,5 +23,33 @@
#include "pinyin.h"
int main(int argc, char * argv[]){
+ pinyin_context_t * context =
+ pinyin_init("../data", "../data");
+
+ PinyinKeyVector pinyin_keys =
+ g_array_new(FALSE, FALSE, sizeof(PinyinKey));
+
+ char* linebuf = NULL;
+ size_t size = 0;
+ while( getline(&linebuf, &size, stdin) ){
+ linebuf[strlen(linebuf)-1] = '\0';
+ if ( strcmp ( linebuf, "quit" ) == 0)
+ break;
+
+ pinyin_parse_more_fulls(context, linebuf, pinyin_keys);
+ pinyin_set_pinyin_keys(context, pinyin_keys);
+ char * sentence = NULL;
+ pinyin_get_guessed_sentence(context, &sentence);
+ printf("%s\n", sentence);
+ g_free(sentence);
+
+ pinyin_train(context);
+ pinyin_reset(context);
+ pinyin_save(context);
+ }
+
+ pinyin_fini(context);
+ g_array_free(pinyin_keys, TRUE);
+ free(linebuf);
return 0;
}