diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lookup/test_simple_lookup.cpp | 4 | ||||
-rw-r--r-- | tests/test_pinyin.cpp | 28 |
2 files changed, 30 insertions, 2 deletions
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; } |