from cppy.cp_util import *

#
# 生成器
#
def non_stop_words(testfilepath): 
    stopwords = get_stopwords()
    data_str = read_file(testfilepath)
    wordlist = re_split( data_str )
    for word in wordlist:
        if word not in stopwords: 
            yield word   # 弹出一个非停用词


freqs = {}
for word in non_stop_words(testfilepath):
    freqs[word] = freqs.get(word, 0) + 1        

data  = sort_dict(freqs)
print_word_freqs(data)