diff options
author | Peng Wu <alexepico@gmail.com> | 2016-05-13 15:05:54 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-05-13 15:05:54 +0800 |
commit | 5bfc05a8e0223a95c10f688043dbecc444ae7cfa (patch) | |
tree | f48e21fb092ecf771b40aee62b1f16dec068a8cd | |
parent | ed191f413f2739982fc737022713cb5226f721de (diff) | |
download | libpinyin-5bfc05a8e0223a95c10f688043dbecc444ae7cfa.tar.gz libpinyin-5bfc05a8e0223a95c10f688043dbecc444ae7cfa.tar.xz libpinyin-5bfc05a8e0223a95c10f688043dbecc444ae7cfa.zip |
update test_matrix.cpp
-rw-r--r-- | src/storage/phonetic_key_matrix.cpp | 46 | ||||
-rw-r--r-- | tests/storage/test_matrix.cpp | 3 |
2 files changed, 27 insertions, 22 deletions
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp index 693753e..af5b1a0 100644 --- a/src/storage/phonetic_key_matrix.cpp +++ b/src/storage/phonetic_key_matrix.cpp @@ -88,17 +88,18 @@ bool fuzzy_syllable_step(pinyin_option_t options, size_t i = 0; for (i = 0; i < keys->len; ++i) { - ChewingKey key = g_array_index(keys, ChewingKey, i); - ChewingKeyRest key_rest = g_array_index(key_rests, - ChewingKeyRest, i); - -#define MATCH(AMBIGUITY, ORIGIN, ANOTHER) do { \ - if (options & AMBIGUITY) { \ - if (ORIGIN == key.m_initial) { \ - key.m_initial = ANOTHER; \ - matrix->append(index, key, key_rest); \ - } \ - } \ + const ChewingKey key = g_array_index(keys, ChewingKey, i); + const ChewingKeyRest key_rest = g_array_index(key_rests, + ChewingKeyRest, i); + +#define MATCH(AMBIGUITY, ORIGIN, ANOTHER) do { \ + if (options & AMBIGUITY) { \ + if (ORIGIN == key.m_initial) { \ + ChewingKey newkey = key; \ + newkey.m_initial = ANOTHER; \ + matrix->append(index, newkey, key_rest); \ + } \ + } \ } while (0) @@ -127,17 +128,18 @@ bool fuzzy_syllable_step(pinyin_option_t options, assert(0 != keys->len); for (i = 0; i < keys->len; ++i) { - ChewingKey key = g_array_index(keys, ChewingKey, i); - ChewingKeyRest key_rest = g_array_index(key_rests, - ChewingKeyRest, i); - -#define MATCH(AMBIGUITY, ORIGIN, ANOTHER) do { \ - if (options & AMBIGUITY) { \ - if (ORIGIN == key.m_final) { \ - key.m_final = ANOTHER; \ - matrix->append(index, key, key_rest); \ - } \ - } \ + const ChewingKey key = g_array_index(keys, ChewingKey, i); + const ChewingKeyRest key_rest = g_array_index(key_rests, + ChewingKeyRest, i); + +#define MATCH(AMBIGUITY, ORIGIN, ANOTHER) do { \ + if (options & AMBIGUITY) { \ + if (ORIGIN == key.m_final) { \ + ChewingKey newkey = key; \ + newkey.m_final = ANOTHER; \ + matrix->append(index, newkey, key_rest); \ + } \ + } \ } while (0) diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp index fd965b8..3bf787d 100644 --- a/tests/storage/test_matrix.cpp +++ b/tests/storage/test_matrix.cpp @@ -29,6 +29,7 @@ using namespace pinyin; int main(int argc, char * argv[]) { pinyin_option_t options = PINYIN_CORRECT_ALL; + options |= PINYIN_AMB_ALL; options |= PINYIN_INCOMPLETE; PhoneticParser2 * parser = new FullPinyinParser2(); @@ -57,6 +58,8 @@ int main(int argc, char * argv[]) { fill_phonetic_key_matrix_from_chewing_keys (&matrix, keys, key_rests); + + fuzzy_syllable_step(options, &matrix); } print_time(start_time, bench_times); |