diff options
author | Peng Wu <alexepico@gmail.com> | 2022-09-26 11:41:02 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2022-09-26 11:41:02 +0800 |
commit | dc17f530f01b0376343beaea4513ae1855620d21 (patch) | |
tree | 54f24e7a3e0f56d7f258867dd0432ee296bc8fc0 | |
parent | c694fbb4ebbaf923658a2e2c0336c711ca70f34f (diff) | |
download | libpinyin-dc17f530f01b0376343beaea4513ae1855620d21.tar.gz libpinyin-dc17f530f01b0376343beaea4513ae1855620d21.tar.xz libpinyin-dc17f530f01b0376343beaea4513ae1855620d21.zip |
Improve pinyin_guess_predicted_candidates function
-rw-r--r-- | src/pinyin.cpp | 10 |
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; |