diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/chewing.py | 8 | ||||
-rw-r--r-- | scripts/genpytable.py | 19 |
2 files changed, 23 insertions, 4 deletions
diff --git a/scripts/chewing.py b/scripts/chewing.py index 716f874..856cf4a 100644 --- a/scripts/chewing.py +++ b/scripts/chewing.py @@ -20,7 +20,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -ASCII_CHEWING_SHENGMU_MAP = { +ASCII_CHEWING_INITIAL_MAP = { "CHEWING_B" : "ㄅ", "CHEWING_C" : "ㄘ", "CHEWING_CH" : "ㄔ", @@ -44,7 +44,7 @@ ASCII_CHEWING_SHENGMU_MAP = { "CHEWING_ZH" : "ㄓ", } -CHEWING_ASCII_SHENGMU_MAP = dict([(v, k) for k, v in ASCII_CHEWING_SHENGMU_MAP.items()]) +CHEWING_ASCII_INITIAL_MAP = dict([(v, k) for k, v in ASCII_CHEWING_INITIAL_MAP.items()]) ASCII_CHEWING_MIDDLE_MAP = { "CHEWING_I" : "ㄧ", @@ -54,7 +54,7 @@ ASCII_CHEWING_MIDDLE_MAP = { CHEWING_ASCII_MIDDLE_MAP = dict([(v, k) for k, v in ASCII_CHEWING_MIDDLE_MAP.items()]) -ASCII_CHEWING_YUNMU_MAP = { +ASCII_CHEWING_FINAL_MAP = { "CHEWING_A" : "ㄚ", "CHEWING_AI" : "ㄞ", "CHEWING_AN" : "ㄢ", @@ -70,4 +70,4 @@ ASCII_CHEWING_YUNMU_MAP = { "CHEWING_OU" : "ㄡ", } -CHEWING_ASCII_YUNMU_MAP = dict([(v, k) for k, v in ASCII_CHEWING_YUNMU_MAP.items()]) +CHEWING_ASCII_FINAL_MAP = dict([(v, k) for k, v in ASCII_CHEWING_FINAL_MAP.items()]) diff --git a/scripts/genpytable.py b/scripts/genpytable.py index b5f34dc..b285d76 100644 --- a/scripts/genpytable.py +++ b/scripts/genpytable.py @@ -25,6 +25,7 @@ import bopomofo import chewing from fuzzy import * + def check_pinyin_chewing_map(): for pinyin_key in pinyin.PINYIN_DICT.keys(): if pinyin_key in bopomofo.PINYIN_BOPOMOFO_MAP.keys(): @@ -32,9 +33,27 @@ def check_pinyin_chewing_map(): else: print("pinyin %s has no chewing mapping", pinyin_key) +def get_chewing(pinyin_key): + initial = 'CHEWING_ZERO_INITIAL' + middle = 'CHEWING_ZERO_MIDDLE' + final = 'CHEWING_ZERO_FINAL' + assert pinyin_key != None + assert pinyin_key in bopomofo.PINYIN_BOPOMOFO_MAP + bopomofo_str = bopomofo.PINYIN_BOPOMOFO_MAP[pinyin_key] + for char in bopomofo_str: + if char in chewing.CHEWING_ASCII_INITIAL_MAP: + initial = chewing.CHEWING_ASCII_INITIAL_MAP[char] + if char in chewing.CHEWING_ASCII_MIDDLE_MAP: + middle = chewing.CHEWING_ASCII_MIDDLE_MAP[char] + if char in chewing.CHEWING_ASCII_FINAL_MAP: + final = chewing.CHEWING_ASCII_FINAL_MAP[char] + return initial, middle, final ### main function ### if __name__ == "__main__": #pre-check here check_pinyin_chewing_map() + #dump + for pinyin_key in pinyin.PINYIN_DICT.keys(): + print (pinyin_key, get_chewing(pinyin_key)) |