summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-10-08 19:47:43 +0800
committerPeng Wu <alexepico@gmail.com>2011-10-08 19:56:30 +0800
commit2dee9aa54537a77bf463799d864dc68a515201e5 (patch)
treee9e758a1b364b05e798acd868379b83fc16ed257
parentd9a4f1249a803408adb00e11306ea17644acd109 (diff)
downloadlibpinyin-2dee9aa54537a77bf463799d864dc68a515201e5.tar.gz
libpinyin-2dee9aa54537a77bf463799d864dc68a515201e5.tar.xz
libpinyin-2dee9aa54537a77bf463799d864dc68a515201e5.zip
fixes get candidates
-rw-r--r--src/pinyin.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 71e2b17..d036cd9 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -364,7 +364,8 @@ static gint compare_token_with_unigram_freq(gconstpointer lhs,
guint32 freq_lhs = item.get_unigram_frequency();
phrase_index->get_phrase_item(token_rhs, item);
guint32 freq_rhs = item.get_unigram_frequency();
- return freq_lhs - freq_rhs;
+
+ return -(freq_lhs - freq_rhs); /* in descendant order */
}
bool pinyin_get_candidates(pinyin_instance_t * instance,
@@ -389,7 +390,7 @@ bool pinyin_get_candidates(pinyin_instance_t * instance,
ranges[m] = g_array_new(FALSE, FALSE, sizeof(PhraseIndexRange));
}
- GArray * tokens = g_array_new(FALSE, FALSE, sizeof(PhraseIndexRange));
+ GArray * tokens = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
for (ssize_t i = pinyin_len; i >= 1; --i) {
g_array_set_size(tokens, 0);
@@ -408,7 +409,14 @@ bool pinyin_get_candidates(pinyin_instance_t * instance,
/* reduce to a single GArray. */
for (size_t m = min_index; m <= max_index; ++m) {
- g_array_append_vals(tokens, ranges[m]->data, ranges[m]->len);
+ for (size_t n = 0; n < ranges[m]->len; ++n) {
+ PhraseIndexRange * range =
+ &g_array_index(ranges[m], PhraseIndexRange, n);
+ for (size_t k = range->m_range_begin;
+ k < range->m_range_end; ++k) {
+ g_array_append_val(tokens, k);
+ }
+ }
}
g_array_sort(tokens, compare_token);
@@ -418,6 +426,7 @@ bool pinyin_get_candidates(pinyin_instance_t * instance,
phrase_token_t token = g_array_index(tokens, phrase_token_t, n);
if ( last_token == token ){
g_array_remove_index(tokens, n);
+ n--;
}
last_token = token;
}