summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2018-11-15 09:56:14 +0800
committerPeng Wu <alexepico@gmail.com>2018-11-15 10:45:08 +0800
commit5643eb4c61a7c7425311471057c6346668145612 (patch)
treefc8fb9381efdb7c54c29bfeb86717f540751ca71
parent43dc88ed102142ceeeb89349a1455d0370733073 (diff)
downloadlibpinyin-5643eb4c61a7c7425311471057c6346668145612.zip
libpinyin-5643eb4c61a7c7425311471057c6346668145612.tar.gz
libpinyin-5643eb4c61a7c7425311471057c6346668145612.tar.xz
improve pinyin_guess_predicted_candidates method
-rw-r--r--src/pinyin.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 2bfc0b8..06903b8 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -1822,10 +1822,6 @@ bool pinyin_guess_candidates(pinyin_instance_t * instance,
}
context->m_phrase_index->destroy_ranges(ranges);
- if (system_gram)
- delete system_gram;
- if (user_gram)
- delete user_gram;
/* post process to sort the candidates */
@@ -1853,6 +1849,11 @@ bool pinyin_guess_candidates(pinyin_instance_t * instance,
_remove_duplicated_items_by_phrase_string(instance, instance->m_candidates);
+ if (system_gram)
+ delete system_gram;
+ if (user_gram)
+ delete user_gram;
+
return true;
}
@@ -1877,13 +1878,12 @@ bool pinyin_guess_predicted_candidates(pinyin_instance_t * instance,
/* merge single gram. */
SingleGram merged_gram;
- SingleGram * system_gram = NULL, * user_gram = NULL;
+ SingleGram * user_gram = NULL;
for (gint i = prefixes->len - 1; i >= 0; --i) {
prev_token = g_array_index(prefixes, phrase_token_t, i);
- context->m_system_bigram->load(prev_token, system_gram);
context->m_user_bigram->load(prev_token, user_gram);
- merge_single_gram(&merged_gram, system_gram, user_gram);
+ merge_single_gram(&merged_gram, NULL, user_gram);
if (merged_gram.get_length())
break;
@@ -1924,11 +1924,6 @@ bool pinyin_guess_predicted_candidates(pinyin_instance_t * instance,
}
- if (system_gram)
- delete system_gram;
- if (user_gram)
- delete user_gram;
-
/* post process to sort the candidates */
_compute_phrase_length(context, candidates);
@@ -1944,6 +1939,9 @@ bool pinyin_guess_predicted_candidates(pinyin_instance_t * instance,
_remove_duplicated_items_by_phrase_string(instance, instance->m_candidates);
+ if (user_gram)
+ delete user_gram;
+
return true;
}