diff options
author | Peng Wu <alexepico@gmail.com> | 2017-05-25 15:23:33 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2017-05-25 15:23:33 +0800 |
commit | 0bd9779cfd4be55ec600355c31806279885ba754 (patch) | |
tree | ca89d07048c9bd07d1692b8c25a7a87c8a1143af /src | |
parent | 132a15bb1da8bc426cb4abf796814f4ec307bccd (diff) | |
download | libpinyin-0bd9779cfd4be55ec600355c31806279885ba754.tar.gz libpinyin-0bd9779cfd4be55ec600355c31806279885ba754.tar.xz libpinyin-0bd9779cfd4be55ec600355c31806279885ba754.zip |
handle zhuyin table file in src/storage
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/chewing_large_table.cpp | 21 | ||||
-rw-r--r-- | src/storage/chewing_large_table.h | 3 | ||||
-rw-r--r-- | src/storage/chewing_large_table2.cpp | 22 | ||||
-rw-r--r-- | src/storage/chewing_large_table2_bdb.h | 3 | ||||
-rw-r--r-- | src/storage/chewing_large_table2_kyotodb.h | 3 | ||||
-rw-r--r-- | src/storage/phrase_index.cpp | 23 | ||||
-rw-r--r-- | src/storage/phrase_index.h | 6 |
7 files changed, 63 insertions, 18 deletions
diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index 1bc5b1f..8521588 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -23,6 +23,7 @@ #include "pinyin_phrase2.h" #include "pinyin_phrase3.h" #include "pinyin_parser2.h" +#include "zhuyin_parser2.h" /* internal class definition */ @@ -661,7 +662,7 @@ int ChewingArrayIndexLevel<phrase_length>::remove_index /* load text method */ -bool ChewingLargeTable::load_text(FILE * infile) { +bool ChewingLargeTable::load_text(FILE * infile, TABLE_PHONETIC_TYPE type) { char pinyin[256]; char phrase[256]; phrase_token_t token; @@ -679,15 +680,27 @@ bool ChewingLargeTable::load_text(FILE * infile) { glong len = g_utf8_strlen(phrase, -1); - PinyinDirectParser2 parser; ChewingKeyVector keys; ChewingKeyRestVector key_rests; keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); - pinyin_option_t options = USE_TONE; - parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + switch (type) { + case PINYIN_TABLE: { + PinyinDirectParser2 parser; + pinyin_option_t options = USE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + break; + } + + case ZHUYIN_TABLE: { + ZhuyinDirectParser2 parser; + pinyin_option_t options = USE_TONE | FORCE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + break; + } + }; if (len != keys->len) { fprintf(stderr, "ChewingLargeTable::load_text:%s\t%s\t%u\t%ld\n", diff --git a/src/storage/chewing_large_table.h b/src/storage/chewing_large_table.h index fa1c642..d836769 100644 --- a/src/storage/chewing_large_table.h +++ b/src/storage/chewing_large_table.h @@ -26,6 +26,7 @@ #include "novel_types.h" #include "memory_chunk.h" #include "chewing_key.h" +#include "table_info.h" namespace pinyin{ @@ -123,7 +124,7 @@ public: return m_bitmap_table.store(new_chunk, 0, end); } - bool load_text(FILE * file); + bool load_text(FILE * file, TABLE_PHONETIC_TYPE type); /* search method */ int search(int phrase_length, /* in */ const ChewingKey keys[], diff --git a/src/storage/chewing_large_table2.cpp b/src/storage/chewing_large_table2.cpp index a100105..aa34399 100644 --- a/src/storage/chewing_large_table2.cpp +++ b/src/storage/chewing_large_table2.cpp @@ -20,7 +20,7 @@ #include "chewing_large_table2.h" #include "pinyin_parser2.h" - +#include "zhuyin_parser2.h" void ChewingLargeTable2::init_entries() { assert(NULL == m_entries); @@ -108,7 +108,7 @@ void ChewingLargeTable2::fini_entries() { } /* load text method */ -bool ChewingLargeTable2::load_text(FILE * infile) { +bool ChewingLargeTable2::load_text(FILE * infile, TABLE_PHONETIC_TYPE type) { char pinyin[256]; char phrase[256]; phrase_token_t token; @@ -126,15 +126,27 @@ bool ChewingLargeTable2::load_text(FILE * infile) { glong len = g_utf8_strlen(phrase, -1); - PinyinDirectParser2 parser; ChewingKeyVector keys; ChewingKeyRestVector key_rests; keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); - pinyin_option_t options = USE_TONE; - parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + switch (type) { + case PINYIN_TABLE: { + PinyinDirectParser2 parser; + pinyin_option_t options = USE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + break; + } + + case ZHUYIN_TABLE: { + ZhuyinDirectParser2 parser; + pinyin_option_t options = USE_TONE | FORCE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + break; + } + }; if (len != keys->len) { fprintf(stderr, "ChewingLargeTable::load_text:%s\t%s\t%u\t%ld\n", diff --git a/src/storage/chewing_large_table2_bdb.h b/src/storage/chewing_large_table2_bdb.h index c604656..e12855e 100644 --- a/src/storage/chewing_large_table2_bdb.h +++ b/src/storage/chewing_large_table2_bdb.h @@ -24,6 +24,7 @@ #include <stdio.h> #include <db.h> #include <glib.h> +#include "table_info.h" namespace pinyin{ @@ -94,7 +95,7 @@ public: bool store_db(const char * new_filename); - bool load_text(FILE * infile); + bool load_text(FILE * infile, TABLE_PHONETIC_TYPE type); /* search method */ int search(int phrase_length, /* in */ const ChewingKey keys[], diff --git a/src/storage/chewing_large_table2_kyotodb.h b/src/storage/chewing_large_table2_kyotodb.h index 8d0dda5..92f317b 100644 --- a/src/storage/chewing_large_table2_kyotodb.h +++ b/src/storage/chewing_large_table2_kyotodb.h @@ -25,6 +25,7 @@ #include "memory_chunk.h" #include <stdio.h> #include <kcdb.h> +#include "table_info.h" namespace pinyin{ @@ -93,7 +94,7 @@ public: bool store_db(const char * new_filename); - bool load_text(FILE * infile); + bool load_text(FILE * infile, TABLE_PHONETIC_TYPE type); /* search method */ int search(int phrase_length, /* in */ const ChewingKey keys[], diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp index f1b1a75..c4a7286 100644 --- a/src/storage/phrase_index.cpp +++ b/src/storage/phrase_index.cpp @@ -511,7 +511,8 @@ bool SubPhraseIndex::merge(PhraseIndexLogger * logger){ return true; } -bool FacadePhraseIndex::load_text(guint8 phrase_index, FILE * infile){ +bool FacadePhraseIndex::load_text(guint8 phrase_index, FILE * infile, + TABLE_PHONETIC_TYPE type){ SubPhraseIndex * & sub_phrases = m_sub_phrase_indices[phrase_index]; if ( !sub_phrases ){ sub_phrases = new SubPhraseIndex; @@ -554,14 +555,26 @@ bool FacadePhraseIndex::load_text(guint8 phrase_index, FILE * infile){ item_ptr->set_phrase_string(written, phrase_ucs4); } - pinyin_option_t options = USE_TONE; - PinyinDirectParser2 parser; ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); ChewingKeyRestVector key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); - parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); - + switch (type) { + case PINYIN_TABLE: { + PinyinDirectParser2 parser; + pinyin_option_t options = USE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + break; + } + + case ZHUYIN_TABLE: { + ZhuyinDirectParser2 parser; + pinyin_option_t options = USE_TONE | FORCE_TONE; + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + break; + } + }; + if (item_ptr->get_phrase_length() == keys->len) { item_ptr->add_pronunciation((ChewingKey *)keys->data, freq); } else { diff --git a/src/storage/phrase_index.h b/src/storage/phrase_index.h index 3c398a2..83dfb51 100644 --- a/src/storage/phrase_index.h +++ b/src/storage/phrase_index.h @@ -26,9 +26,11 @@ #include "novel_types.h" #include "chewing_key.h" #include "pinyin_parser2.h" +#include "zhuyin_parser2.h" #include "pinyin_phrase3.h" #include "memory_chunk.h" #include "phrase_index_logger.h" +#include "table_info.h" /** * Phrase Index File Format @@ -467,13 +469,15 @@ public: * FacadePhraseIndex::load_text: * @phrase_index: the index of sub phrase index to be loaded. * @infile: the textual format file of the phrase table. + * @type: the type of phonetic table. * @returns: whether the load operation is successful. * * Load one sub phrase index from the textual format file. * Note: load sub phrase index according to the config in future. * */ - bool load_text(guint8 phrase_index, FILE * infile); + bool load_text(guint8 phrase_index, FILE * infile, + TABLE_PHONETIC_TYPE type); /** * FacadePhraseIndex::load: |