summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-10-19 15:16:10 +0800
committerPeng Wu <alexepico@gmail.com>2012-10-19 15:16:10 +0800
commit1256e3c800f7d9136bcaf33627971b27e598bb83 (patch)
treeb1cd9deebe7836dcd65761194df6531b4c2e6853 /src
parent1a663eac6e9dcd16375690d9ab54f51bf02c83b7 (diff)
downloadlibpinyin-1256e3c800f7d9136bcaf33627971b27e598bb83.tar.gz
libpinyin-1256e3c800f7d9136bcaf33627971b27e598bb83.tar.xz
libpinyin-1256e3c800f7d9136bcaf33627971b27e598bb83.zip
update pinyin_guess_sentence_with_prefix
Diffstat (limited to 'src')
-rw-r--r--src/pinyin.cpp8
-rw-r--r--src/storage/phrase_large_table2.h1
2 files changed, 7 insertions, 2 deletions
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];