码迷,mamicode.com
首页 > 其他好文 > 详细

中文词频统计

时间:2017-09-29 23:04:31      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:中文分词   odi   小说   对话   意义   ima   word   .com   utf-8   

 

中文分词

  1. 下载一中文长篇小说,并转换成UTF-8编码。
  2. 使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。
  3. 排除一些无意义词、合并同一词。
import jieba

txt=open(‘888.txt‘,‘r‘,encoding=‘utf-8‘).read()
words=list(jieba.cut(txt))

exp={‘?‘,‘,‘}

keys=set(words)-exp
dic={}
for w in keys:
    if len(w)>1:
        dic[w]=words.count(w)

wc=list(dic.items())
wc.sort(key=lambda x:x[1],reverse=True)

for i in range (20):
    print(wc[i])

  技术分享

4,对词频统计结果做简单的解读

这篇小说主要人物是勇作,美左子,晃彦,织田,主要也是以对话来组成

中文词频统计

标签:中文分词   odi   小说   对话   意义   ima   word   .com   utf-8   

原文地址:http://www.cnblogs.com/YWEIEN/p/7610346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!