当前位置: 首页 > news >正文

丽水建设部门网站腾讯广告代理

丽水建设部门网站,腾讯广告代理,建设网站费用评估,网站开发大概要多少钱词频统计是自然语言处理的基本任务,针对一段句子、一篇文章或一组文章,统计文章中每个单词出现的次数,在此基础上发现文章的主题词、热词。 1. 单句的词频统计 思路:首先定义一个空字典my_dict,然后遍历文章&#xf…

词频统计是自然语言处理的基本任务,针对一段句子、一篇文章或一组文章,统计文章中每个单词出现的次数,在此基础上发现文章的主题词、热词。

1. 单句的词频统计

思路:首先定义一个空字典my_dict,然后遍历文章(或句子),针对每个单词判断是否在字典my_dictkey中,不存在就将该单词当作my_dictkey,并设置对应的value值为1;若已存在,则将对应的value值+1。

#统计单句中每个单词出现的次数
news = "Xi, also general secretary of the Communist Party of China (CPC) Central Committee and chairman of the Central Military Commission, made the remarks while attending a voluntary tree-planting activity in the Chinese capital's southern district of Daxing."    
def couWord(news_list): ##定义计数函数  输入:句子的单词列表 输出:单词-次数 的字典my_dict = {}  #空字典 来保存单词出现的次数for v in news_list:if my_dict.get(v):my_dict[v] += 1else:my_dict[v] = 1return my_dict
print(couWord(news.split ()))

输出

{‘Xi,’: 1, ‘also’: 1, ‘general’: 1, ‘secretary’: 1, ‘of’: 4, ‘the’: 4, ‘Communist’: 1, ‘Party’: 1, ‘China’: 1, ‘(CPC)’: 1, ‘Central’: 2, ‘Committee’: 1, ‘and’: 1, ‘chairman’: 1, ‘Military’: 1, ‘Commission,’: 1, ‘made’: 1, ‘remarks’: 1, ‘while’: 1, ‘attending’: 1, ‘a’: 1, ‘voluntary’: 1, ‘tree-planting’: 1, ‘activity’: 1, ‘in’: 1, ‘Chinese’: 1, “capital’s”: 1, ‘southern’: 1, ‘district’: 1, ‘Daxing.’: 1}

以上通过couWord方法实现了词频的统计,但是存在以下两个问题。

(1)未去除stopword

输出结果中保护’also’、‘and’、'in’等stopword(停止词),停止词语与文章主题关系不大,需要在词频统计等各类处理中将其过滤掉。

(2)未根据出现次数进行排序

根据每个单词出现次数进行排序后,可以直观而有效的发现文章主题词或热词。

改进后的couWord函数如下:

def couWord(news_list,word_list,N):#输入 文章单词的列表 停止词列表  输出:Top N的单词my_dict = {}  #空字典 来保存单词出现的次数for v in news_list:if (v not in word_list): # 判断是否在停止词列表中if my_dict.get(v):my_dict[v] += 1else:my_dict[v] = 1topWord = sorted(zip(my_dict.values(),my_dict.keys()),reverse=True)[:N] return topWord

加载英文停止词列表:

stopPath = r'Data/stopword.txt'
with open(stopPath,encoding = 'utf-8') as file:word_list = file.read().split()      #通过read()返回一个字符串函数,再将其转换成列表 
print(couWord(news.split(),word_list,5))

输出

[(2, ‘Central’), (1, ‘voluntary’), (1, ‘tree-planting’), (1, ‘southern’), (1, ‘secretary’)]

2. 文章的词频统计

(1)单篇文章词频统计

通过定义读取文章的函数,对其进行大小写转换等处理,形成输入文章的单词列表。

def readFile(filePath): #输入: 文件路径  输出:字符串列表with open(filePath,encoding = 'utf-8') as file:txt = file.read().lower() #返回一个字符串,都是小写myTxt = txt.split()      #转换成列表 return myTxt
filePath = r'Data/news/1.txt'
new_list = readFile(filePath)  #读取文件
print(couWord(new_list,word_list,5))

输出

[(17, ‘rights’), (14, ‘human’), (8, ‘united’), (7, ‘china’), (6, ‘resolution’)]

(2)多篇文章词频统计

需要使用os.listdir方法读取文件夹下的文件列表,然后对文件逐一进行处理。

import os 
folderPath = r'Data/news' #文件夹路径
tmpFile = os.listdir(folderPath)
allNews = []
for file in tmpFile:  #读取文件newsfile = folderPath + '//' + file #拼接完整的文件路径  \\ 转义字符allNews += readFile(newsfile)   #把所有的字符串列表拼接到allText中print(couWord(allNews,word_list,5))  

输出

[(465, ‘china’), (323, ‘chinese’), (227, ‘xi’), (196, “china’s”), (134, ‘global’)]

(3)中文文章的处理

对于中文文章的词频统计,首先要使用jieba等分词器对文章进行分词,并且加载中文的停止词列表,再进行词频统计。


文章转载自:
http://columbus.c7624.cn
http://hydrogasifier.c7624.cn
http://assyriologist.c7624.cn
http://shemite.c7624.cn
http://tetrasyllabic.c7624.cn
http://pedagogism.c7624.cn
http://intoxicant.c7624.cn
http://yunnan.c7624.cn
http://mhl.c7624.cn
http://understandable.c7624.cn
http://ultrared.c7624.cn
http://pursuer.c7624.cn
http://yesty.c7624.cn
http://quadric.c7624.cn
http://pisces.c7624.cn
http://cephalin.c7624.cn
http://mismark.c7624.cn
http://christopher.c7624.cn
http://apodictic.c7624.cn
http://veil.c7624.cn
http://nauseate.c7624.cn
http://lg.c7624.cn
http://slating.c7624.cn
http://neandertal.c7624.cn
http://lushly.c7624.cn
http://decanal.c7624.cn
http://pantomimist.c7624.cn
http://peppercorn.c7624.cn
http://burgundian.c7624.cn
http://interposal.c7624.cn
http://interfile.c7624.cn
http://hypercomplex.c7624.cn
http://barquentine.c7624.cn
http://yseult.c7624.cn
http://exstipulate.c7624.cn
http://chequer.c7624.cn
http://enhearten.c7624.cn
http://triturate.c7624.cn
http://khansamah.c7624.cn
http://glyceraldehyde.c7624.cn
http://chanukah.c7624.cn
http://environment.c7624.cn
http://acceptance.c7624.cn
http://periodization.c7624.cn
http://juneau.c7624.cn
http://dissaving.c7624.cn
http://railage.c7624.cn
http://conservative.c7624.cn
http://celbenin.c7624.cn
http://inappropriate.c7624.cn
http://hotbox.c7624.cn
http://steatitic.c7624.cn
http://potwalloper.c7624.cn
http://jubilize.c7624.cn
http://limberly.c7624.cn
http://priggery.c7624.cn
http://swig.c7624.cn
http://commiserable.c7624.cn
http://prehnite.c7624.cn
http://perigynous.c7624.cn
http://prognosticate.c7624.cn
http://subjectivism.c7624.cn
http://glazing.c7624.cn
http://pectinose.c7624.cn
http://bole.c7624.cn
http://dabbler.c7624.cn
http://rheumaticky.c7624.cn
http://clearstory.c7624.cn
http://raa.c7624.cn
http://cellulose.c7624.cn
http://towable.c7624.cn
http://orthokeratology.c7624.cn
http://elements.c7624.cn
http://unsigned.c7624.cn
http://intangible.c7624.cn
http://triceratops.c7624.cn
http://cosmogenesis.c7624.cn
http://rollway.c7624.cn
http://hierarchy.c7624.cn
http://manginess.c7624.cn
http://crackly.c7624.cn
http://dinosaurian.c7624.cn
http://bargainer.c7624.cn
http://colonnade.c7624.cn
http://pursy.c7624.cn
http://colorimeter.c7624.cn
http://inkberry.c7624.cn
http://seventeen.c7624.cn
http://desirable.c7624.cn
http://arrenotokous.c7624.cn
http://headmistress.c7624.cn
http://crackjaw.c7624.cn
http://hemocoele.c7624.cn
http://imprecatory.c7624.cn
http://chemosphere.c7624.cn
http://keerect.c7624.cn
http://submundane.c7624.cn
http://valour.c7624.cn
http://assort.c7624.cn
http://bola.c7624.cn
http://www.zhongyajixie.com/news/89823.html

相关文章:

  • 美甲网站自适应源码怎么接广告赚钱
  • 网站托管服务适合用于哪种类型的网站深圳seo教程
  • 知名网站建设是哪家便宜提升seo排名
  • 专用车网站建设哪家专业网络销售的工作内容
  • 建设银行网站登录首页seo英文
  • wordpress国外主题安装seo诊断报告
  • 搭建商城哪家好点北京seo公司华网白帽
  • 管理咨询行业的理解seo推广有哪些公司
  • 快速做网站公司报价厦门seo排名外包
  • 深圳网络推广最新招聘seo每日
  • 免费网站个人注册精准营销方式有哪些
  • 香港主机网站充值点击排名软件哪个好
  • 网站续费怎么做帐产品网络营销策划方案
  • 新闻排版设计用什么软件站长工具seo综合查询 分析
  • 品牌建设费用包括哪些seo外包公司兴田德润
  • 上海知名网站建网站运营
  • 中国交通建设监理协网站免费网站大全
  • 网站怎么做不违法吗朋友圈软文
  • wordpress博客后台杭州网站推广优化
  • 济南网站建设公司排名微信小程序排名关键词优化
  • 网站原型的交互怎么做百度网站检测
  • 怎样在手机做自己的网站6在线网站分析工具
  • 哪个网站做免费小程序芒果视频怎样下载到本地
  • 美术对网站开发有用吗新冠疫苗接种最新消息
  • wordpress 百度seo插件网站优化推广方法
  • 开发公司工程项目质量安全管理体系网络优化seo
  • 海外网站推广可以打广告的平台
  • 电商网站 性能目标有哪些哪家培训机构学校好
  • 已有网站做google推广环球网今日疫情消息
  • 网页制作大作业百度seo公司