summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-04-19 14:13:34 +0800
committerPeng Wu <alexepico@gmail.com>2012-04-19 14:13:34 +0800
commit5de9071bd724c90ec26cffbb0cb763412795be54 (patch)
treeb12f0abd6ed3c2ac9339635c28c40324abeccaca
parentd87e71b496dcc2bd5f8f3bb8637111d0f4059f7d (diff)
downloadlibpinyin-5de9071bd724c90ec26cffbb0cb763412795be54.tar.gz
libpinyin-5de9071bd724c90ec26cffbb0cb763412795be54.tar.xz
libpinyin-5de9071bd724c90ec26cffbb0cb763412795be54.zip
write pinyin_get_full_pinyin_candidates in progress
-rw-r--r--src/pinyin.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 23ecc09..99d26df 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -765,16 +765,16 @@ bool pinyin_get_full_pinyin_candidates(pinyin_instance_t * instance,
GArray * items = g_array_new(FALSE, FALSE, sizeof(lookup_candidate_t));
if (pinyin_len == 1) {
+ /* because there is only one pinyin left,
+ * the following for-loop will not produce 2 character candidates.
+ * the if-branch will fill the candidate list with
+ * 2 character candidates.
+ */
+
if (options & USE_DIVIDED_TABLE) {
g_array_set_size(items, 0);
/* handle "^xian$" -> "xi'an" here */
- /* because there is only one pinyin left,
- * the following for-loop will not produce 2 character candidates.
- * the if-branch will fill the candidate list with
- * 2 character candidates.
- */
-
ChewingKey * key = &g_array_index(pinyin_keys, ChewingKey, offset);
ChewingKeyRest * rest = &g_array_index(pinyin_key_rests,
ChewingKeyRest, offset);
@@ -880,6 +880,35 @@ bool pinyin_get_full_pinyin_candidates(pinyin_instance_t * instance,
}
}
+ ChewingKey * keys = &g_array_index
+ (pinyin_keys, ChewingKey, offset);
+
+ /* do pinyin search. */
+ int retval = context->m_pinyin_table->search
+ (i, keys, ranges);
+
+ if ( !(retval & SEARCH_OK) )
+ continue;
+
+ lookup_candidate_t template_item;
+ _append_items(context, ranges, &template_item, items);
+
+ g_array_sort(items, compare_item_with_token);
+
+ _remove_duplicated_items(items);
+
+ _compute_frequency_of_items(context, prev_token, &merged_gram, items);
+
+ g_array_sort(items, compare_item_with_frequency);
+
+ for (i = 0; i < items->len; ++i) {
+ lookup_candidate_t * item = &g_array_index
+ (items, lookup_candidate_t, i);
+ g_array_append_val(candidates, *item);
+ }
+
+ if (!(retval & SEARCH_CONTINUED))
+ break;
}
g_array_free(items, TRUE);