From: Peng Wu Date: Fri, 19 Oct 2012 07:16:10 +0000 (+0800) Subject: update pinyin_guess_sentence_with_prefix X-Git-Tag: 0.8.91~85 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1256e3c800f7d9136bcaf33627971b27e598bb83;p=platform%2Fupstream%2Flibpinyin.git update pinyin_guess_sentence_with_prefix --- diff --git a/src/pinyin.cpp b/src/pinyin.cpp index b291c57..d032f6d 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -625,6 +625,7 @@ bool pinyin_guess_sentence_with_prefix(pinyin_instance_t * instance, glong len_str = 0; ucs4_t * ucs4_str = g_utf8_to_ucs4(prefix, -1, NULL, &len_str, NULL); + GArray * tokenarray = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); if (ucs4_str && len_str) { /* add prefixes. */ @@ -639,12 +640,15 @@ bool pinyin_guess_sentence_with_prefix(pinyin_instance_t * instance, memset(tokens, 0, sizeof(tokens)); phrase_index->prepare_tokens(tokens); int result = context->m_phrase_table->search(i, start, tokens); - int num = get_first_token(tokens, token); + int num = reduce_tokens(tokens, tokenarray); phrase_index->destroy_tokens(tokens); + if (result & SEARCH_OK) - g_array_append_val(instance->m_prefixes, token); + g_array_append_vals(instance->m_prefixes, + tokenarray->data, tokenarray->len); } } + g_array_free(tokenarray, TRUE); g_free(ucs4_str); pinyin_update_constraints(instance); diff --git a/src/storage/phrase_large_table2.h b/src/storage/phrase_large_table2.h index 36ef53c..03dc185 100644 --- a/src/storage/phrase_large_table2.h +++ b/src/storage/phrase_large_table2.h @@ -112,6 +112,7 @@ public: static inline int reduce_tokens(PhraseTokens tokens, GArray * tokenarray) { int num = 0; + g_array_set_size(tokenarray, 0); for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { GArray * array = tokens[i];