diff options
author | Peng Wu <alexepico@gmail.com> | 2015-05-28 14:18:21 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2015-05-28 14:18:21 +0800 |
commit | 90fe6a15c295811daa2c840bff5ec19b070cd561 (patch) | |
tree | 764219911e2a55b3d4b881466a5d6298fb962f43 /src/pinyin.cpp | |
parent | cde9cb6b85773069e706ae374396d4b9d2085298 (diff) | |
download | libpinyin-90fe6a15c295811daa2c840bff5ec19b070cd561.tar.gz libpinyin-90fe6a15c295811daa2c840bff5ec19b070cd561.tar.xz libpinyin-90fe6a15c295811daa2c840bff5ec19b070cd561.zip |
update pinyin_choose_candidate function
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r-- | src/pinyin.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 5c4c8b3..2466979 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -2205,6 +2205,37 @@ int pinyin_choose_candidate(pinyin_instance_t * instance, if (BEST_MATCH_CANDIDATE == candidate->m_candidate_type) return instance->m_pinyin_keys->len; + if (ADDON_CANDIDATE == candidate->m_candidate_type) { + PhraseItem item; + context->m_addon_phrase_index->get_phrase_item + (candidate->m_token, item); + + guint8 len = item.get_phrase_length(); + guint8 npron = item.get_n_pronunciation(); + + PhraseIndexRange range; + context->m_phrase_index->get_range(ADDON_DICTIONARY, range); + /* assume not over flow here. */ + phrase_token_t token = range.m_range_end; + + /* add pinyin index. */ + for (size_t i = 0; i < npron; ++i) { + ChewingKey keys[MAX_PHRASE_LENGTH]; + guint32 freq = 0; + item.get_nth_pronunciation(i, keys, freq); + context->m_pinyin_table->add_index(len, keys, token); + } + /* add phrase index. */ + ucs4_t phrase[MAX_PHRASE_LENGTH]; + item.get_phrase_string(phrase); + context->m_phrase_table->add_index(len, phrase, token); + context->m_phrase_index->add_phrase_item(token, item); + + /* update the candidate. */ + candidate->m_candidate_type = NORMAL_CANDIDATE; + candidate->m_token = token; + } + if (DIVIDED_CANDIDATE == candidate->m_candidate_type || RESPLIT_CANDIDATE == candidate->m_candidate_type) { /* update full pinyin. */ |