Separate cal and IO process.

This commit is contained in:
Richard Wong 2013-07-03 15:03:45 +08:00
parent e1c1d46324
commit 3246236133

View File

@ -264,15 +264,21 @@ def load_userdict(f):
if line_no==1: if line_no==1:
word = word.replace(u'\ufeff',u"") #remove bom flag if it exists word = word.replace(u'\ufeff',u"") #remove bom flag if it exists
if len(tup)==3: if len(tup)==3:
user_word_tag_tab[word]=tup[2].strip() add_word(word, freq, tup[2])
freq = float(freq) add_word(word, freq)
FREQ[word] = log(freq / total)
p = trie def add_word(word, freq, tag=None):
for c in word: global FREQ, trie, total, user_word_tag_tab
if not c in p: freq = float(freq)
p[c] ={} FREQ[word] = log(freq / total)
p = p[c] if tag is not None:
p['']='' #ending flag user_word_tag_tab[word] = tag.strip()
p = trie
for c in word:
if not c in p:
p[c] = {}
p = p[c]
p[''] = '' # ending flag
__ref_cut = cut __ref_cut = cut
__ref_cut_for_search = cut_for_search __ref_cut_for_search = cut_for_search