diff options
author | Peng Wu <alexepico@gmail.com> | 2012-04-10 11:27:12 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-04-10 11:27:12 +0800 |
commit | 48af9209a46e7f03c189a25ece4ab3bfacf66fa3 (patch) | |
tree | f0d5bcb77f18e414303e95f3e06b49583a8eb7a0 | |
parent | 5fb692bdbe0dabfc59be5524f9c413e3a94d3e78 (diff) | |
download | libpinyin-48af9209a46e7f03c189a25ece4ab3bfacf66fa3.tar.gz libpinyin-48af9209a46e7f03c189a25ece4ab3bfacf66fa3.tar.xz libpinyin-48af9209a46e7f03c189a25ece4ab3bfacf66fa3.zip |
add DYNAMIC_ADJUST flag
-rw-r--r-- | src/pinyin.cpp | 57 | ||||
-rw-r--r-- | src/storage/pinyin_custom2.h | 3 |
2 files changed, 35 insertions, 25 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 2946385..dade3f1 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -632,6 +632,7 @@ bool pinyin_get_candidates(pinyin_instance_t * instance, TokenVector candidates) { pinyin_context_t * & context = instance->m_context; + pinyin_option_t options = context->m_options; ChewingKeyVector & pinyin_keys = instance->m_pinyin_keys; g_array_set_size(candidates, 0); @@ -642,20 +643,23 @@ bool pinyin_get_candidates(pinyin_instance_t * instance, /* lookup the previous token here. */ phrase_token_t prev_token = null_token; - if (0 == offset) { - prev_token = sentence_start; - } else { - assert (0 < offset); - - phrase_token_t cur_token = g_array_index - (instance->m_match_results, phrase_token_t, offset); - if (null_token != cur_token) { - for (i = offset - 1; i >= 0; --i) { - cur_token = g_array_index - (instance->m_match_results, phrase_token_t, i); - if (null_token != cur_token) { - prev_token = cur_token; - break; + + if (options & DYNAMIC_ADJUST) { + if (0 == offset) { + prev_token = sentence_start; + } else { + assert (0 < offset); + + phrase_token_t cur_token = g_array_index + (instance->m_match_results, phrase_token_t, offset); + if (null_token != cur_token) { + for (i = offset - 1; i >= 0; --i) { + cur_token = g_array_index + (instance->m_match_results, phrase_token_t, i); + if (null_token != cur_token) { + prev_token = cur_token; + break; + } } } } @@ -663,10 +667,13 @@ bool pinyin_get_candidates(pinyin_instance_t * instance, SingleGram merged_gram; SingleGram * system_gram = NULL, * user_gram = NULL; - if (null_token != prev_token) { - 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); + + if (options & DYNAMIC_ADJUST) { + if (null_token != prev_token) { + 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); + } } PhraseIndexRanges ranges; @@ -731,12 +738,14 @@ bool pinyin_get_candidates(pinyin_instance_t * instance, item.m_token = token; gfloat bigram_poss = 0; guint32 total_freq = 0; - if (null_token != prev_token) { - guint32 bigram_freq = 0; - merged_gram.get_total_freq(total_freq); - merged_gram.get_freq(token, bigram_freq); - if (0 != total_freq) - bigram_poss = bigram_freq / (gfloat)total_freq; + if (options & DYNAMIC_ADJUST) { + if (null_token != prev_token) { + guint32 bigram_freq = 0; + merged_gram.get_total_freq(total_freq); + merged_gram.get_freq(token, bigram_freq); + if (0 != total_freq) + bigram_poss = bigram_freq / (gfloat)total_freq; + } } /* compute the m_freq. */ diff --git a/src/storage/pinyin_custom2.h b/src/storage/pinyin_custom2.h index a848258..499a9d4 100644 --- a/src/storage/pinyin_custom2.h +++ b/src/storage/pinyin_custom2.h @@ -34,7 +34,8 @@ enum PinyinTableFlag{ CHEWING_INCOMPLETE = 1U << 4, USE_TONE = 1U << 5, USE_DIVIDED_TABLE = 1U << 6, - USE_RESPLIT_TABLE = 1U << 7 + USE_RESPLIT_TABLE = 1U << 7, + DYNAMIC_ADJUST = 1U << 8 }; /** |