€绘梨衣 2022-08-20 10:55 采纳率: 0%
浏览 39

中文词频分析,这是哪错了,哭了呀

def getText("红楼梦.txt"):
f = open("红楼梦.txt","r",encoding="utf-8")
text = f.read()
f.close()
return text
import jieba
def wordFreq(红楼梦.txt,text,200):
words = jieba.lcut(text.strip())
counts = {}
for word in words:
counts[word] = counts.get(word,0) + 1
items = list(counts.items())
items.sort(key = lambda x:x[1],reverse = true)
f = open(filepath[:-4]+'_词频.txt',"w")
for i in range(topn):
word, count = items[i]
f.writelines("{}\t{}\n".format(word,count))
f.ciose()

  • 写回答

1条回答 默认 最新

  • 「已注销」 2022-08-20 15:52
    关注

    有我在,不要哭 嗯,你把文件发给我,我看一下

    评论

报告相同问题?

问题事件

  • 创建了问题 8月20日