# -*- coding: utf-8 -*-
from collections import defaultdict
Inputfilename = "../data/199801_seg&pos.txt"
Outputfilename = "../data/dic.txt"
def BuildDic(Ip=Inputfilename,Op=Outputfilename):
fi = open(Ip,'r',encoding='gbk')
fo = open(Op,'w',encoding='gbk')
worddic = defaultdict(lambda:0)
for line in fi :
line = str(line)
words = line.split(" ")[1:]
for word in words:
if word.find('/')==-1:
continue
else:
thisword = word[0:word.find('/')]
worddic[thisword] += 1
newdic = sorted(worddic.items(),key = lambda x:x[1],reverse = True)
for word in newdic:
fo.write(word[0]+'\t'+str(word[1])+'\n')
fi.close()
fo.close()
if __name__ == '__main__':
BuildDic()
3.1Generate
最新推荐文章于 2024-08-08 14:28:23 发布