jieba分词-红楼梦

Posted untitied

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jieba分词-红楼梦相关的知识,希望对你有一定的参考价值。

import jieba
excludes = {"quot","什么","一个","我们","那里","你们","如今","说道","知道","起来","姑娘","这里","出来","他们","众人","自己",
"一面","只见","怎么","两个","没有","不是","不知","这个","听见","这样","进来","咱们","告诉","就是",
"东西","袭人","回来","只是","大家","只得","老爷","丫头","这些","不敢","出去","所以","不过","的话","不好",
"姐姐","探春","鸳鸯","一时","不能","过来","心里","如此","今日","银子","几个","答应","二人","还有","只管",
"这么","说话","一回","那边","这话","外头","打发","自然","今儿","罢了","屋里","那些","听说","小丫头","不用","如何"}

txt = open("红楼梦.txt","r",encoding=\'utf-8\').read()
words = jieba.lcut(txt)
counts = {}
for word in words:
if len(word) == 1:
continue
else:
counts[word] = counts.get(word,0) + 1
for word in excludes:
del(counts[word])
items = list(counts.items())
items.sort(key=lambda x:x[1],reverse = True)
for i in range(20):
word,count = items[i]
print("{0:<10}{1:>5}".format(word,count))

 

 

以上是关于jieba分词-红楼梦的主要内容,如果未能解决你的问题,请参考以下文章

jieba分词的词性表

中文分词-jieba#人工智能

jieba分词(R vs. python)

jieba分词怎样 去掉或替换 默认词库里的词

jieba分词算法使用

python将怎么将jieba分词结果写入文本,各种编码问题啊