码迷,mamicode.com
首页 > 其他好文 > 详细

文件方式实现完整的英文词频统计实例

时间:2017-09-26 12:54:27      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:统计   more   img   ble   ade   分享   flavor   price   技术   

1.读入待分析的字符串

2.分解提取单词 

3.计数字典

4.排除语法型词汇

5.排序

6.输出TOP(20)

str=‘‘‘For Chinese people, eating mooncakes with families is one of the important ways to celebrate the Mid-Autumn Festival, which falls on Oct 4 this year, or the 15th day of the 8th Chinese lunar month.

As mass-produced mooncakes sweep market with different flavors mooncakes and various stuffing, customers are inclined to turn to traditional taste, which makes hand-made mooncakes a hot commodity in the market.

Wei Quanfa‘s hand-made mooncakes is one such case. The 72-year-old baker inherited the traditional craft from his family and started his new business in Zhengzhou, Central China‘s Henan province.

He carries out every procedure by himself, mooncakes including making stuffing and the mooncake mould, boiling oil, and baking. Because of that, Wei is able to make no more than 40 kg a day in the last month before the festival, and a 30-centimeter-diameter mooncake is priced at over 200 yuan ($30).

With the festival just around the corner, reserving Wei‘s mooncakes even two days in advance is next to impossible.‘‘‘
fo=open(C:\\Users\\Administrator\\Desktop\\news.txt,w)
fo.write(str)
fo.close


fo=open(C:\\Users\\Administrator\\Desktop\\news.txt,r)
news=fo.read()
fo.close()

news=str.lower()  #小写

for i in ",.()-$":
    news=news.replace(i," ")  #空格替换


news=news.split(" ")  #分割字段

exc={the,one,which,his, ,a,with,for,to,is,of,on,in,out,no,at,over‘‘such,that,and,or}



words=set(news)
words=words-exc

dt={}

for i in words:
    dt[i]=news.count(i)  #统计


item=list(dt.items())

item.sort(key=lambda x:x[1],reverse=True)

for i in range(20):
    print(item[i])

技术分享

 

文件方式实现完整的英文词频统计实例

标签:统计   more   img   ble   ade   分享   flavor   price   技术   

原文地址:http://www.cnblogs.com/silu666-666/p/7596039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!