From e39223215f96debb725fd9a85f8e2df7d5ff03d7 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 14 Jan 2013 15:15:05 +0800 Subject: code re-factor --- scripts/specialtable.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'scripts/specialtable.py') diff --git a/scripts/specialtable.py b/scripts/specialtable.py index 5d1d599..b6fb680 100644 --- a/scripts/specialtable.py +++ b/scripts/specialtable.py @@ -37,28 +37,17 @@ def load_phrase(filename): for line in phrasefile.readlines(): line = line.rstrip(os.linesep) (pinyin_str, freq) = line.split(None, 1) - freq = int(math.floor(float(freq))) + freq = int(freq) if 0 == freq: #print(pinyin_str) continue + # no duplicate here if "'" in pinyin_str: (first_key, second_key) = pinyin_str.split("'") - if first_key[-1].isdigit(): - first_key = first_key[:-1] - if second_key[-1].isdigit(): - second_key = second_key[:-1] - if (first_key, second_key) in phrase_dict: - phrase_dict[(first_key, second_key)] += freq - else: - phrase_dict[(first_key, second_key)] = freq + phrase_dict[(first_key, second_key)] = freq else: - if pinyin_str[-1].isdigit(): - pinyin_str = pinyin_str[:-1] - if pinyin_str in phrase_dict: - phrase_dict[pinyin_str] += freq - else: - phrase_dict[pinyin_str] = freq + phrase_dict[pinyin_str] = freq phrasefile.close() -- cgit