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