diff options
| author | Peng Wu <alexepico@gmail.com> | 2016-05-11 15:50:01 +0800 |
|---|---|---|
| committer | Peng Wu <alexepico@gmail.com> | 2016-05-11 15:50:01 +0800 |
| commit | f76adc9bdd2235166819494f14d689dbcbc911ae (patch) | |
| tree | f87c7b05569e84483f30af05d9f1afb1234fe0e5 /src | |
| parent | 7c43d981edce11bdd17b7e6e43f50af4680554aa (diff) | |
write dump_phonetic_key_matrix function
Diffstat (limited to 'src')
| -rw-r--r-- | src/storage/phonetic_key_matrix.cpp | 35 | ||||
| -rw-r--r-- | src/storage/phonetic_key_matrix.h | 12 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp index 17671d7..1f5b8ea 100644 --- a/src/storage/phonetic_key_matrix.cpp +++ b/src/storage/phonetic_key_matrix.cpp @@ -21,6 +21,9 @@ #include "phonetic_key_matrix.h" #include <assert.h> +#include <stdio.h> + +namespace pinyin{ bool fill_phonetic_key_matrix_from_chewing_keys(PhoneticKeyMatrix * matrix, ChewingKeyVector keys, @@ -68,3 +71,35 @@ bool fill_phonetic_key_matrix_from_chewing_keys(PhoneticKeyMatrix * matrix, return true; } +bool dump_phonetic_key_matrix(PhoneticKeyMatrix * matrix) { + size_t length = matrix->size(); + + GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey)); + GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest)); + + for (size_t index = 0; index < length; ++index) { + matrix->get_items(index, keys, key_rests); + + printf("Column:%ld:\n", index); + + assert(keys->len == key_rests->len); + + for (size_t i = 0; i < keys->len; ++i) { + ChewingKey * key = &g_array_index(keys, ChewingKey, i); + ChewingKeyRest * key_rest = &g_array_index(key_rests, + ChewingKeyRest, i); + + gchar * pinyin = key->get_pinyin_string(); + printf("ChewingKey:%s\n", pinyin); + printf("ChewingKeyRest:%hd\t%hd\n", + key_rest->m_raw_begin, key_rest->m_raw_end); + g_free(pinyin); + } + } + + g_array_free(keys, TRUE); + g_array_free(key_rests, TRUE); + return true; +} + +}; diff --git a/src/storage/phonetic_key_matrix.h b/src/storage/phonetic_key_matrix.h index 7fc194c..8ad885b 100644 --- a/src/storage/phonetic_key_matrix.h +++ b/src/storage/phonetic_key_matrix.h @@ -22,6 +22,7 @@ #ifndef PHONETIC_KEY_MATRIX_H #define PHONETIC_KEY_MATRIX_H +#include <assert.h> #include "novel_types.h" #include "chewing_key.h" @@ -45,6 +46,10 @@ public: return true; } + bool size() { + return m_table_content->len; + } + /* when call this function, reserve one extra slot for the end slot. */ bool set_size(size_t size) { @@ -94,6 +99,11 @@ public: return m_keys.clear_all() && m_key_rests.clear_all(); } + bool size() { + assert(m_keys.size() == m_key_rests.size()); + return m_keys.size(); + } + /* reserve one extra slot, same as PhoneticTable. */ bool set_size(size_t size) { return m_keys.set_size(size) && m_key_rests.set_size(size); @@ -117,6 +127,8 @@ bool fill_phonetic_key_matrix_from_chewing_keys(PhoneticKeyMatrix * matrix, ChewingKeyVector keys, ChewingKeyRestVector key_rests); +bool dump_phonetic_key_matrix(PhoneticKeyMatrix * matrix); + }; #endif |
