diff options
author | Peng Wu <alexepico@gmail.com> | 2013-09-10 14:20:10 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-09-10 15:35:18 +0800 |
commit | 55103cca7eb56f50946fa9ecb6ec091d8c150385 (patch) | |
tree | d08feb52a448bef04cc09a74fb13703c554300cb | |
parent | d1028a43ac2bbadb81a0a5fdc705010c9187f58f (diff) | |
download | libzhuyin-55103cca7eb56f50946fa9ecb6ec091d8c150385.tar.gz libzhuyin-55103cca7eb56f50946fa9ecb6ec091d8c150385.tar.xz libzhuyin-55103cca7eb56f50946fa9ecb6ec091d8c150385.zip |
write handle rules
-rw-r--r-- | scripts/genpinyintable.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/genpinyintable.py b/scripts/genpinyintable.py index 68ee239..2c285db 100644 --- a/scripts/genpinyintable.py +++ b/scripts/genpinyintable.py @@ -144,8 +144,36 @@ def check_rule(correct, wrong): assert '*' not in wrong elif correct.endswith('*'): assert wrong.endswith('*') + else: + assert False, "unknown rule format" return True +def handle_rules(bopomofo, corrects): + matches = [] + for (correct, wrong) in corrects: + if '*' not in correct: + if correct == bopomofo: + matches.append(wrong) + elif correct.endswith('*'): + starts = correct[0:-1] + if bopomofo.startswith(starts): + remained = bopomofo[len(starts):] + newstr = wrong[0:-1] + remained + matches.append(newstr) + return matches + +def handle_special_rules(bopomofo, corrects): +# special rules require additional check m_middle == zero + matches = [] + if 'ㄧ' in bopomofo: + return matches + if 'ㄨ' in bopomofo: + return matches + if 'ㄩ' in bopomofo: + return matches +# Note: special rules always contains '*' + return handle_rules(bopomofo, corrects) + def gen_chewing_key_table(): return gen_table_index(content_table) |