diff options
author | Peng Wu <alexepico@gmail.com> | 2012-04-18 16:06:05 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-04-18 16:07:35 +0800 |
commit | a586f8da45e11c0cd84d5b1ff0582369fb5333c1 (patch) | |
tree | d79aa0b8ed0b50f145737bc454a65e222851ef7b /src/storage | |
parent | 1ca1f3a99d1c4fc342bc9f19da93ff822de37018 (diff) | |
download | libpinyin-a586f8da45e11c0cd84d5b1ff0582369fb5333c1.tar.gz libpinyin-a586f8da45e11c0cd84d5b1ff0582369fb5333c1.tar.xz libpinyin-a586f8da45e11c0cd84d5b1ff0582369fb5333c1.zip |
write pinyin_get_full_pinyin_candidates in progress
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/pinyin_parser2.cpp | 47 | ||||
-rw-r--r-- | src/storage/pinyin_parser2.h | 5 |
2 files changed, 50 insertions, 2 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp index 662ee1b..b4175b1 100644 --- a/src/storage/pinyin_parser2.cpp +++ b/src/storage/pinyin_parser2.cpp @@ -484,7 +484,7 @@ bool FullPinyinParser2::post_process2(pinyin_option_t options, int len) const { int i; assert(keys->len == key_rests->len); - gint16 num_keys = keys->len; + gint num_keys = keys->len; ChewingKey * cur_key = NULL, * next_key = NULL; ChewingKeyRest * cur_rest = NULL, * next_rest = NULL; @@ -561,7 +561,7 @@ bool FullPinyinParser2::post_process2(pinyin_option_t options, assert(parse_one_key(options, *next_key, onepinyin, len)); } - /* save back tones */ + /* restore tones */ if (options & USE_TONE) { if (CHEWING_ZERO_TONE != next_tone) { next_key->m_tone = next_tone; @@ -573,6 +573,49 @@ bool FullPinyinParser2::post_process2(pinyin_option_t options, return true; } +const divided_table_item_t * FullPinyinParser2::retrieve_divided_item +(pinyin_option_t options, size_t offset, + ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, + const char * str, int len) const { + assert(keys->len == key_rests->len); + + gint num_keys = keys->len; + assert(offset < num_keys); + + ChewingKey * key = &g_array_index(keys, ChewingKey, offset); + ChewingKeyRest * rest = &g_array_index(key_rests, + ChewingKeyRest, offset); + guint16 tone = CHEWING_ZERO_TONE; + + /* lookup divided table */ + size_t k; + const divided_table_item_t * item = NULL; + for (k = 0; k < G_N_ELEMENTS(divided_table); ++k) { + item = divided_table + k; + + /* no ops */ + assert(item->m_new_freq > 0); + + const char * onepinyin = str + rest->m_raw_begin; + size_t len = strlen(item->m_orig_key); + + if (rest->length() != len) + continue; + + if (0 == strncmp(onepinyin, item->m_orig_key, len)) + break; + } + + /* found the match */ + if (k < G_N_ELEMENTS(divided_table)) { + /* do divided */ + item = divided_table + k; + return item; + } + + return NULL; +} + #define IS_KEY(x) (('a' <= x && x <= 'z') || x == ';') bool DoublePinyinParser2::parse_one_key(pinyin_option_t options, diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h index 09469e7..77ed3d4 100644 --- a/src/storage/pinyin_parser2.h +++ b/src/storage/pinyin_parser2.h @@ -152,6 +152,11 @@ protected: const char * str, int len) const; public: + const divided_table_item_t * retrieve_divided_item + (pinyin_option_t options, size_t offset, + ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, + const char * str, int len) const; +public: FullPinyinParser2(); virtual ~FullPinyinParser2() { g_array_free(m_parse_steps, TRUE); |