summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-02 14:49:24 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-02 14:49:24 +0800
commit880b6876320b98e7d9a17aa3029c1ae35c9d0809 (patch)
tree1cddf2789a9a78c827a6cf11a350cbfd03f28867 /scripts
parent7486c26af092ed6b40c640cd1dbf99456ba51892 (diff)
downloadlibpinyin-880b6876320b98e7d9a17aa3029c1ae35c9d0809.tar.gz
libpinyin-880b6876320b98e7d9a17aa3029c1ae35c9d0809.tar.xz
libpinyin-880b6876320b98e7d9a17aa3029c1ae35c9d0809.zip
fixes gen special table
Diffstat (limited to 'scripts')
-rw-r--r--scripts/genspecialtable.py7
-rw-r--r--scripts/pinyintable.py22
2 files changed, 18 insertions, 11 deletions
diff --git a/scripts/genspecialtable.py b/scripts/genspecialtable.py
index b16319d..9ea45f2 100644
--- a/scripts/genspecialtable.py
+++ b/scripts/genspecialtable.py
@@ -22,7 +22,7 @@
import operator
import pinyin
-from pinyintable import get_chewing
+from pinyintable import get_chewing, get_shengmu_chewing
from specialtable import *
pinyin_list = sorted(pinyin.PINYIN_LIST)
@@ -40,10 +40,11 @@ def sort_all():
def get_chewing_string(pinyin):
if pinyin not in pinyin_list:
if pinyin in shengmu_list:
- return "Error"
+ (initial, middle, final) = get_shengmu_chewing(pinyin)
else:
assert False, "Un-expected pinyin string."
- (initial, middle, final) = get_chewing(pinyin)
+ else:
+ (initial, middle, final) = get_chewing(pinyin)
chewing_str = 'ChewingKey({0}, {1}, {2})'.format(initial, middle, final)
return chewing_str
diff --git a/scripts/pinyintable.py b/scripts/pinyintable.py
index 3457aba..979f9b7 100644
--- a/scripts/pinyintable.py
+++ b/scripts/pinyintable.py
@@ -110,21 +110,27 @@ def gen_pinyins():
flags, get_chewing(pinyin_key)
+def get_shengmu_chewing(shengmu):
+ assert shengmu in shengmu_list, "Expected shengmu here."
+ chewing_key = 'CHEWING_{0}'.format(shengmu.upper())
+ if chewing_key in chewing.ASCII_CHEWING_INITIAL_MAP:
+ initial = chewing_key
+ else:
+ initial = 'PINYIN_{0}'.format(shengmu.upper())
+ return initial, "CHEWING_ZREO_MIDDLE", "CHEWING_ZERO_FINAL"
+
def gen_shengmu():
#generate all shengmu
for shengmu in shengmu_list:
if shengmu in pinyin_list:
continue
flags = ["IS_PINYIN", "PINYIN_INCOMPLETE"]
- chewing_key = 'CHEWING_{0}'.format(shengmu.upper())
- if chewing_key in chewing.ASCII_CHEWING_INITIAL_MAP:
- initial = chewing_key
+ chewing_key = get_shengmu_chewing(shengmu)
+ chewing_initial = chewing_key[0]
+ if chewing_initial in chewing.ASCII_CHEWING_INITIAL_MAP:
chewing_key = chewing.ASCII_CHEWING_INITIAL_MAP[chewing_key]
- else:
- chewing_key = 'PINYIN_{0}'.format(shengmu.upper())
- initial = chewing_key
- yield shengmu, shengmu, chewing_key, \
- flags, (initial, "CHEWING_ZREO_MIDDLE", "CHEWING_ZERO_FINAL")
+ yield shengmu, shengmu, chewing_initial, \
+ flags, chewing_key
def gen_corrects():