summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2022-09-26 11:41:02 +0800
committerPeng Wu <alexepico@gmail.com>2022-09-26 11:41:02 +0800
commitdc17f530f01b0376343beaea4513ae1855620d21 (patch)
tree54f24e7a3e0f56d7f258867dd0432ee296bc8fc0
parentc694fbb4ebbaf923658a2e2c0336c711ca70f34f (diff)
downloadlibpinyin-dc17f530f01b0376343beaea4513ae1855620d21.tar.gz
Improve pinyin_guess_predicted_candidates function
-rw-r--r--src/pinyin.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 4cc357c..61cdb5f 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -2184,12 +2184,18 @@ bool pinyin_guess_predicted_candidates(pinyin_instance_t * instance,
int num = reduce_tokens(phrase_tokens, tokenarray, false);
phrase_index->destroy_tokens(phrase_tokens);
+ PhraseItem item;
for (size_t i = 0; i < tokenarray->len; ++i) {
- phrase_token_t candidate = g_array_index(tokenarray, phrase_token_t, i);
+ phrase_token_t token = g_array_index(tokenarray, phrase_token_t, i);
+
+ phrase_index->get_phrase_item(token, item);
+ /* skip the phrase longer than prefix_len * 2 + 1 */
+ if (item.get_phrase_length() > (instance->m_prefix_len * 2 + 1))
+ continue;
lookup_candidate_t template_item;
template_item.m_candidate_type = PREDICTED_PREFIX_CANDIDATE;
- template_item.m_token = candidate;
+ template_item.m_token = token;
template_item.m_begin = instance->m_prefix_len;
/* The prefix candidate only uses the m_begin variable. */
template_item.m_end = 0;