summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-02 11:01:43 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-02 11:02:42 +0800
commitb212470e2a74fce88202495c93940651d1769864 (patch)
tree51068778218abe855291ef2ede9d44f166e5a02e
parent81ca3def70f06419f90c8db0246fad614ec9d11a (diff)
downloadlibpinyin-b212470e2a74fce88202495c93940651d1769864.zip
libpinyin-b212470e2a74fce88202495c93940651d1769864.tar.gz
libpinyin-b212470e2a74fce88202495c93940651d1769864.tar.xz
fixes choose short candidate
-rw-r--r--src/lookup/pinyin_lookup.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lookup/pinyin_lookup.cpp b/src/lookup/pinyin_lookup.cpp
index c32e2bb..d6ba68c 100644
--- a/src/lookup/pinyin_lookup.cpp
+++ b/src/lookup/pinyin_lookup.cpp
@@ -108,18 +108,27 @@ bool PinyinLookup::destroy_pinyin_lookup(PhraseIndexRanges ranges){
}
size_t PinyinLookup::prepare_table_cache(int nstep, int total_pinyin){
- //free resources
+ /* free resources */
for ( size_t i = 0; i < m_table_cache->len; ++i){
PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, i);
destroy_pinyin_lookup(*ranges);
}
- //g_array_set_size(m_table_cache, 1);
+
PinyinKey * pinyin_keys = (PinyinKey *)m_keys->data;
pinyin_keys += nstep;
- //init resources
g_array_set_size(m_table_cache, MAX_PHRASE_LENGTH + 1);
- int len;
- for ( len = 1; len <= total_pinyin && len <= MAX_PHRASE_LENGTH; ++len){
+
+ int len, total_len = std::min(total_pinyin, MAX_PHRASE_LENGTH);
+
+ /* probe constraint */
+ for ( len = 1; len <= total_len; ++len) {
+ lookup_constraint_t * constraint = &g_array_index(m_constraints, lookup_constraint_t, nstep + len);
+ if (constraint->m_type == CONSTRAINT_ONESTEP)
+ break;
+ }
+ total_len = std::min(len, total_len);
+
+ for ( len = 1; len <= total_len; ++len){
PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, len);
prepare_pinyin_lookup(*ranges);
int result = m_pinyin_table->search(len, pinyin_keys, *ranges);