diff options
author | Peng Wu <alexepico@gmail.com> | 2013-08-13 14:12:29 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-08-13 14:12:34 +0800 |
commit | cc03404121c974fff7c718041afc25713687d70c (patch) | |
tree | 584be7289aefa7a7ef0859f31f2529e6bef9b2f7 | |
parent | c3d0a2d6e4283b6ce18eb37557c8220df29caaad (diff) | |
download | libzhuyin-cc03404121c974fff7c718041afc25713687d70c.tar.gz libzhuyin-cc03404121c974fff7c718041afc25713687d70c.tar.xz libzhuyin-cc03404121c974fff7c718041afc25713687d70c.zip |
support luoma pinyin and secondary bopomofo pinyin
-rw-r--r-- | scripts/genpinyintable.py | 55 | ||||
-rw-r--r-- | scripts/pinyintable.py | 6 |
2 files changed, 46 insertions, 15 deletions
diff --git a/scripts/genpinyintable.py b/scripts/genpinyintable.py index 777e161..d93b81c 100644 --- a/scripts/genpinyintable.py +++ b/scripts/genpinyintable.py @@ -27,46 +27,62 @@ from chewingkey import gen_table_index content_table = [] hanyu_pinyin_index = [] +luoma_pinyin_index = [] bopomofo_index = [] +second_bopomofo_index = [] + #pinyin table def filter_pinyin_list(): for (pinyin, bopomofo, flags, chewing) in gen_pinyin_list(): - flags = '|'.join(flags) - chewing = "ChewingKey({0})".format(', '.join(chewing)) - #correct = correct.replace("v", "ü") - (luoma, second) = ("" , "") if bopomofo in BOPOMOFO_LUOMA_PINYIN_MAP: luoma = BOPOMOFO_LUOMA_PINYIN_MAP[bopomofo] + flags.append("IS_LUOMA_PINYIN") if bopomofo in BOPOMOFO_SECOND_BOPOMOFO_MAP: second = BOPOMOFO_SECOND_BOPOMOFO_MAP[bopomofo] + flags.append("IS_SECOND_BOPOMOFO") - content_table.append((pinyin, bopomofo, chewing)) + flags = '|'.join(flags) + chewing = "ChewingKey({0})".format(', '.join(chewing)) + #correct = correct.replace("v", "ü") - if "IS_PINYIN" in flags: + content_table.append((pinyin, bopomofo, luoma, second, chewing)) + + if "IS_HANYU_PINYIN" in flags: hanyu_pinyin_index.append((pinyin, flags)) - if "IS_CHEWING" in flags: + if "IS_LUOMA_PINYIN" in flags: + luoma_pinyin_index.append((luoma, flags)) + if "IS_BOPOMOFO" in flags: bopomofo_index.append((bopomofo, flags)) + if "IS_SECOND_BOPOMOFO" in flags: + second_bopomofo_index.append((second, flags)) def sort_all(): - global content_table, hanyu_pinyin_index, bopomofo_index + global content_table, hanyu_pinyin_index, luoma_pinyin_index + global bopomofo_index, second_bopomofo_index + #remove duplicates content_table = list(set(content_table)) hanyu_pinyin_index = list(set(hanyu_pinyin_index)) + luoma_pinyin_index = list(set(luoma_pinyin_index)) bopomofo_index = list(set(bopomofo_index)) + second_bopomofo_index = list(set(second_bopomofo_index)) + #define sort function sortfunc = operator.itemgetter(0) #begin sort content_table = sorted(content_table, key=sortfunc) #prepend zero item to reserve the invalid item - content_table.insert(0, ("", "", "ChewingKey()")) + content_table.insert(0, ("", "", "", "", "ChewingKey()")) #sort index hanyu_pinyin_index = sorted(hanyu_pinyin_index, key=sortfunc) + luoma_pinyin_index = sorted(luoma_pinyin_index, key=sortfunc) bopomofo_index = sorted(bopomofo_index, key=sortfunc) + second_bopomofo_index = sorted(second_bopomofo_index, key=sortfunc) ''' def get_sheng_yun(pinyin): @@ -85,8 +101,8 @@ def get_sheng_yun(pinyin): def gen_content_table(): entries = [] - for ((pinyin, bopomofo, chewing)) in content_table: - entry = '{{"{0}", "{1}", {2}}}'.format(pinyin, bopomofo, chewing) + for ((pinyin, bopomofo, luoma, second, chewing)) in content_table: + entry = '{{"{0}", "{1}", "{2}", "{3}" ,{4}}}'.format(pinyin, bopomofo, luoma, second, chewing) entries.append(entry) return ',\n'.join(entries) @@ -99,6 +115,13 @@ def gen_hanyu_pinyin_index(): entries.append(entry) return ',\n'.join(entries) +def gen_luoma_pinyin_index(): + entries = [] + for (pinyin, flags) in luoma_pinyin_index: + index = [x[2] for x in content_table].index(pinyin) + entry = '{{"{0}", {1}, {2}}}'.format(pinyin, flags, index) + entries.append(entry) + return ',\n'.join(entries) def gen_bopomofo_index(): entries = [] @@ -109,6 +132,13 @@ def gen_bopomofo_index(): entries.append(entry) return ',\n'.join(entries) +def gen_second_bopomofo_index(): + entries = [] + for (bopomofo, flags) in second_bopomofo_index: + index = [x[3] for x in content_table].index(bopomofo) + entry = '{{"{0}", {1}, {2}}}'.format(bopomofo, flags, index) + entries.append(entry) + return ',\n'.join(entries) def gen_chewing_key_table(): return gen_table_index(content_table) @@ -122,5 +152,6 @@ sort_all() ### main function ### if __name__ == "__main__": #s = gen_content_table() + gen_hanyu_pinyin_index() + gen_bopomofo_index() - s = gen_chewing_key_table() + s = gen_content_table() + gen_luoma_pinyin_index() + gen_second_bopomofo_index() + #s = gen_chewing_key_table() print(s) diff --git a/scripts/pinyintable.py b/scripts/pinyintable.py index 081cd2d..cf74950 100644 --- a/scripts/pinyintable.py +++ b/scripts/pinyintable.py @@ -95,10 +95,10 @@ def gen_pinyins(): for pinyin_key in pinyin_list: flags = [] if pinyin_key in bopomofo.HANYU_PINYIN_BOPOMOFO_MAP.keys(): - flags.append("IS_CHEWING") + flags.append("IS_BOPOMOFO") if pinyin_key in pinyin.HANYU_PINYIN_LIST or \ pinyin_key in pinyin.SHENGMU_LIST: - flags.append("IS_PINYIN") + flags.append("IS_HANYU_PINYIN") if pinyin_key in shengmu_list: flags.append("PINYIN_INCOMPLETE") chewing_key = bopomofo.HANYU_PINYIN_BOPOMOFO_MAP[pinyin_key] @@ -123,7 +123,7 @@ def gen_shengmu(): for shengmu in shengmu_list: if shengmu in pinyin_list: continue - flags = ["IS_PINYIN", "PINYIN_INCOMPLETE"] + flags = ["IS_HANYU_PINYIN", "PINYIN_INCOMPLETE"] chewing_key = get_shengmu_chewing(shengmu) chewing_initial = chewing_key[0] if chewing_initial in chewing.ASCII_CHEWING_INITIAL_MAP: |