summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-12-27 17:15:39 +0800
committerPeng Wu <alexepico@gmail.com>2017-12-27 17:15:39 +0800
commit2583889378de8976e74e992fe28d3b08ab1c5276 (patch)
treef596def693c9840a9fb214aff8cfe2e6b99c03fa
parent3e5d3b78c18e7c7d73733af756fb52f483a974d2 (diff)
downloadlibpinyin-2583889378de8976e74e992fe28d3b08ab1c5276.zip
libpinyin-2583889378de8976e74e992fe28d3b08ab1c5276.tar.gz
libpinyin-2583889378de8976e74e992fe28d3b08ab1c5276.tar.xz
refactor code
-rw-r--r--scripts2/chewing.py3
-rw-r--r--scripts2/fullpinyintable.py13
2 files changed, 9 insertions, 7 deletions
diff --git a/scripts2/chewing.py b/scripts2/chewing.py
index c3eab03..b92319d 100644
--- a/scripts2/chewing.py
+++ b/scripts2/chewing.py
@@ -99,6 +99,9 @@ ASCII_CHEWING_TONE_LIST = [
("CHEWING_5" , "˙"),
]
+ASCII_CHEWING_TONE_MAP = dict([(k, v) for k, v in ASCII_CHEWING_TONE_LIST if v])
+
+CHEWING_ASCII_TONE_MAP = dict([(v, k) for k, v in ASCII_CHEWING_TONE_LIST if v])
CHEWING_INITIAL_LIST = [k for k, v in ASCII_CHEWING_INITIAL_LIST]
diff --git a/scripts2/fullpinyintable.py b/scripts2/fullpinyintable.py
index ef0a6a2..6f39acd 100644
--- a/scripts2/fullpinyintable.py
+++ b/scripts2/fullpinyintable.py
@@ -387,17 +387,16 @@ def handle_special_rules(zhuyin, corrects):
def gen_table_index_for_chewing_key():
+ chewings = [x[4] for x in content_table]
+
entries = []
- for i in range(0, len(chewing.CHEWING_INITIAL_LIST)):
- initial = chewing.CHEWING_INITIAL_LIST[i]
- for m in range(0, len(chewing.CHEWING_MIDDLE_LIST)):
- middle = chewing.CHEWING_MIDDLE_LIST[m]
- for f in range(0, len(chewing.CHEWING_FINAL_LIST)):
- final = chewing.CHEWING_FINAL_LIST[f]
+ for initial in chewing.CHEWING_INITIAL_LIST:
+ for middle in chewing.CHEWING_MIDDLE_LIST:
+ for final in chewing.CHEWING_FINAL_LIST:
chewingkey = 'ChewingKey({0}, {1}, {2})'.format(initial, middle, final)
index = -1
try:
- index = [x[4] for x in content_table].index(chewingkey)
+ index = chewings.index(chewingkey)
except ValueError:
pass