update pinyin_guess_sentence_with_prefix
authorPeng Wu <alexepico@gmail.com>
Fri, 19 Oct 2012 07:16:10 +0000 (15:16 +0800)
committerPeng Wu <alexepico@gmail.com>
Fri, 19 Oct 2012 07:16:10 +0000 (15:16 +0800)
src/pinyin.cpp
src/storage/phrase_large_table2.h

index b291c57..d032f6d 100644 (file)
@@ -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);
index 36ef53c..03dc185 100644 (file)
@@ -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];