From 4d43f63b30bcb97b7e0f3761df5c7902d4575bc5 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 13 Dec 2011 17:13:10 +0800 Subject: gen chewing key to table index map --- scripts/chewingkey.py | 20 ++++++++++++++++++++ scripts/genpinyinheader.py | 5 ++++- scripts/genpinyintable.py | 8 +++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/scripts/chewingkey.py b/scripts/chewingkey.py index dc0f2a2..c0d2f05 100644 --- a/scripts/chewingkey.py +++ b/scripts/chewingkey.py @@ -125,6 +125,26 @@ def gen_tones(): 'CHEWING_NUMBER_OF_TONES = CHEWING_LAST_TONE + 1') +def gen_table_index(content_table): + entries = [] + for i in range(0, len(CHEWING_INITIAL_LIST)): + initial = CHEWING_INITIAL_LIST[i] + for m in range(0, len(CHEWING_MIDDLE_LIST)): + middle = CHEWING_MIDDLE_LIST[m] + for f in range(0, len(CHEWING_FINAL_LIST)): + final = CHEWING_FINAL_LIST[f] + chewingkey = 'ChewingKey({0}, {1}, {2})'.format(initial, middle, final) + index = -1 + try: + index = [x[2] for x in content_table].index(chewingkey) + except ValueError: + pass + + entry = '{0} /* {1} */'.format(index, chewingkey) + entries.append(entry) + return ",\n".join(entries) + + if __name__ == "__main__": print(gen_initials()) print(gen_middles()) diff --git a/scripts/genpinyinheader.py b/scripts/genpinyinheader.py index 6c81726..defe018 100644 --- a/scripts/genpinyinheader.py +++ b/scripts/genpinyinheader.py @@ -22,7 +22,8 @@ import os from genpinyintable import gen_content_table, \ - gen_pinyin_index, gen_bopomofo_index + gen_pinyin_index, gen_bopomofo_index, \ + gen_chewing_key_to_table_index from genspecialtable import gen_divided_table, gen_resplit_table def get_table_content(tablename): @@ -36,6 +37,8 @@ def get_table_content(tablename): return gen_divided_table() if tablename == 'RESPLIT_TABLE': return gen_resplit_table() + if tablename == 'TABLE_INDEX': + return gen_chewing_key_to_table_index() def expand_file(filename): diff --git a/scripts/genpinyintable.py b/scripts/genpinyintable.py index 5af4e91..4f4e64f 100644 --- a/scripts/genpinyintable.py +++ b/scripts/genpinyintable.py @@ -21,6 +21,7 @@ import operator from pinyintable import * +from chewingkey import gen_table_index content_table = [] @@ -83,6 +84,10 @@ def gen_bopomofo_index(): return ',\n'.join(entries) +def gen_chewing_key_table_index_map(): + return gen_table_index(content_table) + + #init code filter_pinyin_list() sort_all() @@ -90,5 +95,6 @@ sort_all() ### main function ### if __name__ == "__main__": - s = gen_content_table() + gen_pinyin_index() + gen_bopomofo_index() + #s = gen_content_table() + gen_pinyin_index() + gen_bopomofo_index() + s = gen_chewing_key_table_index_map() print(s) -- cgit