首页 > 其他 > 详细

作业4

时间:2018-09-27 15:09:29      阅读:168      评论:0      收藏:0      [点我收藏+]
# 2018年9月27日完整的英文词频统计
# strYee = ‘‘‘‘‘‘.lower()
# 准备utf-8编码的文本文件file
fo = open(Nothingtolose.txt,r,encoding=utf-8)
# 通过文本读取字符串str
strYee = fo.read()
fo.close()
print(strYee)
# 对文本进行预处理
# 字符串预处理
# 大小写
# 标点符号
# 特殊符号
# 分解提取单词list
sep = ‘‘‘.,;:?!-_‘‘‘
for ch in sep:
    strYee = strYee.replace(ch, )
strList = strYee.split()
print(len(strList),strList)
# 单词计数字典set,dict
# 排除语法型词汇,代词、冠词、连词等无语义词
strSet = set(strList)
exclude = {a,the,and,i,you,in}
strSet = strSet-exclude
print(len(strSet),strSet)

strDic = {}
for word in strSet:
    strDic[word] = strList.count(word)
print(len(strDic),strDic)
# 按词频排序list。sort(key=)
wcList = list(strDic.items())
print(wcList)
wcList.sort(key=lambda x:x[1],reverse=True)
print(wcList)
# print(strDic.items())
# 输出TOP(20)
for i in range(20):
    print(wcList[i])

技术分享图片

技术分享图片

技术分享图片

import jieba
fo = open(我们的少年时代.txt,r,encoding=utf-8)
strYee = fo.read()
fo.close()
print(strYee)
print(list(jieba.cut(strYee)))
print(list(jieba.cut(strYee,cut_all=True)))
print(list(jieba.cut_for_search(strYee)))

技术分享图片

技术分享图片

作业4

原文:https://www.cnblogs.com/GZCC-11-28/p/9712278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!