英文词频统计(代码片段)

lawliet12 lawliet12     2022-10-28     364

关键词:

综合练习:英文词频统计

  1. 词频统计预处理
  2. 下载一首英文的歌词或文章
  3. 将所有,.?!’:等分隔符全部替换为空格
  4. 将所有大写转换为小写
  5. 生成单词列表
  6. 生成词频统计
  7. 排序
  8. 排除语法型词汇,代词、冠词、连词
  9. 输出词频最大TOP10
    word = \'\'\'
    Lately, I\'ve been, I\'ve been losing sleep
    Dreaming about the things that we could be
    But baby, I\'ve been, I\'ve been praying hard,
    Said, no more counting dollars
    We\'ll be counting stars, yeah we\'ll be counting stars
    I see this life like a swinging vine
    Swing my heart across the line
    And my face is flashing signs
    Seek it out and you shall find
    Old, but I\'m not that old
    Young, but I\'m not that bold
    I don\'t think the world is sold
    I\'m just doing what we\'re told
    I feel something so right
    Doing the wrong thing
    I feel something so wrong
    Doing the right thing
    I could lie, coudn\'t I, could lie
    Everything that kills me makes me feel alive
    Lately, I\'ve been, I\'ve been losing sleep
    Dreaming about the things that we could be
    But baby, I\'ve been, I\'ve been praying hard,
    Said, no more counting dollars
    We\'ll be counting stars
    \'\'\'
    #标点替换为空格
    symbol = [",", ".", "!", "?", "\'", ":", "-"]
    #无意义的单词
    
    words = [\'t\',\'ve\',\'ll\',\'m\']
    
    new_art = word
    for i in range(len(symbol)):
        new_art = new_art.replace(symbol[i],\' \') #把文章的标点符号替换
    
    new_art = new_art.lower() #改成小写
    art_list = new_art.split() #以空格将字符串分成单词列表
    
    dic = dict(zip())
    for i in art_list:
        dic[i] = new_art.count(i) #用字典记录单词和其出现次数
    for i in words:
        if(dic.get(i)!=None): #如果为冠词之类的无意义的词,将其舍弃
            dic.pop(i)
    
    new_dic = sorted(dic.items(),key=lambda x:x[1],reverse = True)
    
    for i in range(10):
        print(new_dic[i]) #取出现频率最高的10个单词

英文词频统计(代码片段)

str=‘‘‘Inhisspeechattheclosingsessionofthisyear‘sNationalPeople‘sCongress,ChinesePresidentXiJinpingreiteratedthetwocentenarygoalsandemphasizedavisionofa"CommunityofSharedFutureforMankind".Theaspectsof 查看详情

综合练习:英文词频统计(代码片段)

词频统计预处理下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格将所有大写转换为小写生成单词列表生成词频统计排序排除语法型词汇,代词、冠词、连词输出词频最大TOP10song=‘‘‘Ifyousayyou’rethefireworkatthe... 查看详情

英文小说词频统计(代码片段)

strYoung=‘‘‘youngforyouGalasunday‘scomingiwannadrivemycartoyourapartmentwithpresentlikeastarforecastersaidtheweathermayberainyhardbutiknowthesunwillshineforusohlazyseagullflymefromthedarkidressmyjeans 查看详情

综合练习:英文词频统计(代码片段)

词频统计预处理下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格将所有大写转换为小写生成单词列表生成词频统计排序排除语法型词汇,代词、冠词、连词输出词频最大TOP10song=‘‘‘Troublewillfindyounomatterwherey... 查看详情

综合练习:英文词频统计(代码片段)

str=‘‘‘AslongasyoulovemeWe‘reunderpressureSevenbillionpeopleintheworldtryingtofitinKeepittogetherSmileonyourfaceeventhoughyourheartisfrowningButheynowyouknowgirlWebothknowit‘sacruelworldButIwilltakemy 查看详情

综合练习:词频统计(代码片段)

1.英文词频统计下载一首英文的歌词或文章a=‘‘‘WakingupIseethateverythingisokThefirsttimeinmylifeandnowit‘ssogreatSlowingdownIlookaroundandIamsoamazedIthinkaboutthelittlethingsthatmakelifegreatIwouldn‘tchangeathingaboutitT 查看详情

综合练习:词频统计(代码片段)

1.英文词频统下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格将所有大写转换为小写生成单词列表生成词频统计排序排除语法型词汇,代词、冠词、连词输出词频最大TOP201.英文词频统下载一首英文的歌词或文... 查看详情

综合练习:英文词频统计(代码片段)

词频统计预处理下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格将所有大写转换为小写生成单词列表生成词频统计排序排除语法型词汇,代词、冠词、连词输出词频最大TOP101#-*-coding:UTF-8-*-2#-*-author:yjw-*-34Music=... 查看详情

综合练习:英文词频统计(代码片段)

#coding=utf-8song=‘‘‘Skies,wherethebluebirdsfly,Cloudswherethepeopleplacetheirsoulsonto.Brighter,thesunshinesthatgothroughmytears,likesearchingforwhathealsmysorrows,Cry,whenthetwilight‘scome,Rise,when 查看详情

中英文词频统计(代码片段)

...除语法型词汇,代词、冠词、连词等无语义词8.输出TOP(20)英文词频统计withopen(‘English.txt‘,‘r‘)asfb:content=fb.read()#清洗数据importstr 查看详情

综合练习:词频统计(代码片段)

综合练习词频统计预处理下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格str=‘‘‘PassionissweetLovemakesweakYousaidyoucherisedfreedomsoYourefusedtoletitgoFollowyourfaithLoveandhateneverfailedtoseizethedayDon‘tgiveyourselfawayOhwhen 查看详情

201671030119词频统计软件项目报告(代码片段)

...统计软件源码需求分析-使用JAVA编程语言,独立完成一个英文文本词频统计的软件开发-软件基本功能要求如下:1.程序可读入任意英文文本文件,该文件中英文词数大于等于1个。2.程序需要很壮健,能读取容纳英文原版《哈利波... 查看详情

综合练习:词频统计(代码片段)

综合练习词频统计预处理下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格将所有大写转换为小写生成单词列表生成词频统计排序排除语法型词汇,代词、冠词、连词输出词频最大TOP20将分析对象存为utf-8编码... 查看详情

组合数据类型,英文词频统计(代码片段)

#字典classmates=[‘Michael‘,‘Bob‘,‘Tracy‘]scores=[95,75,85]cs=dict(zip(classmates,scores))print(cs)#取值print(cs[‘Michael‘])#长度print(len(‘Michael‘))#删除cs.pop(‘Bob‘)print(cs)#遍历print(cs.keys())print((cs.ite 查看详情

综合练习:词频统计(代码片段)

综合练习词频统计预处理下载一首英文的歌词或文章将所有,.?!’:等分隔符全部替换为空格将所有大写转换为小写生成单词列表生成词频统计排序排除语法型词汇,代词、冠词、连词输出词频最大TOP20将分析对象存为utf-8编码... 查看详情

完整的英文词频统计(代码片段)

1.准备utf-8编码的文本文件file2.通过文件读取字符串str3.对文本进行预处理4.分解提取单词list5.单词计数字典set,dict6.按词频排序list.sort(key=)7.排除语法型词汇,代词、冠词、连词等无语义词8.输出TOP(20)代码:#读取fire文本文件f=open(... 查看详情

完整的中英文词频统计(代码片段)

#读取字符串strf=open(‘zz.txt‘,‘r‘,encoding=‘utf-8‘)strbig=f.read()f.close()sep=‘‘‘.,;:?!-_‘‘‘forchinsep:strbig=strbig.replace(ch,‘‘)strbig=strbig.lower()print(strbig)strlist=strbig.split()print(len(strlist 查看详情

python3用字典来统计词频(代码片段)

...述使用freqDict=eval(input())读入单词词频字典,再读入一段英文,更新词频字典后输出。‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬... 查看详情