diff options
author | Peng Wu <alexepico@gmail.com> | 2015-09-08 13:42:55 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2015-09-08 13:42:55 +0800 |
commit | c2042c858732363b1be6848003d9335e41a67e07 (patch) | |
tree | b1e96ffafe4925777ab80ff6b4f541ba3c5055fe /scripts2/doublepinyintable.py | |
parent | 9f39cd0266ae44167fe9fb71c9be428d07aff637 (diff) | |
download | libpinyin-c2042c858732363b1be6848003d9335e41a67e07.tar.gz libpinyin-c2042c858732363b1be6848003d9335e41a67e07.tar.xz libpinyin-c2042c858732363b1be6848003d9335e41a67e07.zip |
update doublepinyintable.py
Diffstat (limited to 'scripts2/doublepinyintable.py')
-rw-r--r-- | scripts2/doublepinyintable.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/scripts2/doublepinyintable.py b/scripts2/doublepinyintable.py index 6b1a788..710c6f1 100644 --- a/scripts2/doublepinyintable.py +++ b/scripts2/doublepinyintable.py @@ -20,8 +20,9 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import os from doublepinyin import SHUANGPIN_SCHEMAS -from fullpinyin import YUNMU_LIST +from fullpinyin import PINYIN_LIST, YUNMU_LIST def gen_shengmu_table(scheme): @@ -63,6 +64,10 @@ def gen_fallback_table2(scheme): #select yunmu mapping yun = SHUANGPIN_SCHEMAS[scheme][1] for yunmu in sorted(YUNMU_LIST): + #skip invalid yunmu + if not yunmu in PINYIN_LIST: + continue + char1 = yunmu[0] char2 = None for k, v in yun.items(): @@ -73,8 +78,7 @@ def gen_fallback_table2(scheme): if yunmu == v[0] or yunmu == v[1]: char2 = k - if char2 == None: - continue + assert char2 != None index = char1 + char2 entry = '{{"{0}", "{1}"}}'.format(index, yunmu) entries.append(entry) @@ -86,6 +90,10 @@ def gen_fallback_table3(scheme): #select yunmu mapping yun = SHUANGPIN_SCHEMAS[scheme][1] for yunmu in sorted(YUNMU_LIST): + #skip invalid yunmu + if not yunmu in PINYIN_LIST: + continue + #special case for double character yunmu if len(yunmu) == 2: entry = '{{"{0}", "{1}"}}'.format(yunmu, yunmu) @@ -103,8 +111,7 @@ def gen_fallback_table3(scheme): if yunmu == v[0] or yunmu == v[1]: char2 = k - if char2 == None: - continue + assert char2 != None index = char1 + char2 entry = '{{"{0}", "{1}"}}'.format(index, yunmu) entries.append(entry) @@ -124,6 +131,8 @@ def get_table_content(tablename): ### main function ### if __name__ == "__main__": - print(gen_fallback_table2("PYJJ")) - print(gen_fallback_table3("ZRM")) - print(gen_fallback_table3("XHE")) + print(gen_fallback_table2("PYJJ"), os.linesep) + + print(gen_fallback_table3("ZRM"), os.linesep) + + print(gen_fallback_table3("XHE"), os.linesep) |