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

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

时间:2017-09-26 21:04:14      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:sda   opera   off   ping   lead   red   environ   英文   image   

1.读入待分析的字符串

2.分解提取单词 

3.计数字典

4.排除语法型词汇

5.排序

6.输出TOP(20)

fo =open(test.txt,w)
fo.write(‘‘‘BEIJING - China hopes to work closely with countries and international organizations on global security, and jointly build universal security for humankind, President Xi Jinping said here Tuesday.
Xi made the remarks in Beijing while addressing the opening ceremony of the 86th Interpol General Assembly.

He spoke highly of Interpol‘s important role in global law enforcement, security cooperation and combating crimes.

Since becoming a member state of Interpol in 1984, China has been committed to developing cooperation with Interpol and other member states, and contributed to maintaining world security and stability, Xi said.

In order to beef up global law enforcement and security cooperation, Xi proposed enhanced reform and innovation, sticking to the rule of law and mutual benefits.

"Countries should adopt a concept of common, comprehensive, cooperative and sustainable security, and jointly respond to security challenges," he said.

Xi asked to promote global security governance in a more fair, reasonable and effective way.

"Countries and intergovernmental organizations should shoulder the main responsibilities of security governance, while non-governmental organizations, multinationals and civil society are encouraged to jointly work for it," he said.

He called on countries to adhere to the UN Charter and Interpol regulations, seriously fulfill conventions against transnational crimes and corruption, and improve relevant international regulations.

"Countries, while maintaining their own security, should take into account other countries‘ security," Xi said. He asked major countries to offer more support for underdeveloped countries and regions in security and development.

"To provide people with a safe and sound living environment is our important target," Xi said, adding that China had made remarkable progress in combating crimes of various kind and building crime prevention and control system.

"More and more people believe China is one of the most secure countries in the world, which is an important contribution China has made to the world," he said. "China has actively participated in global law-enforcement cooperation and global security governance, resolutely supported international fight against terrorism, joined global cooperation in combating cyber crimes, worked with other countries in fugitive repatriation, fighting against telecome fraud and other crimes."

The Chinese president vowed stronger support for Interpol in the five years to come to raise its global influence and leadership.

Meng Hongwei, Interpol president and vice minister of public security in China, presided over the opening ceremony.

Participants from 158 countries and regions gathered in Beijing for the conference, which lasts from Tuesday to Friday.

‘‘‘)
fo.close()


fo =open(test.txt,r)
str= fo.read()
exc={the,and,to,of,in,a,for,with,‘‘}
for i in ,.?!\n": str=str.replace(i, ) str=str.lower() str=str.split(" ") words=set(str) dic={} keys=set(str)#出现过单词的集合,字典的KEY keys=keys-exc for i in keys: dic[i]=str.count(i) w=list(dic.items()) w.sort(key=lambda x:x[1],reverse=True)
for i in range(20): print(w[i]) fo.close()

 

 

技术分享

 

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

标签:sda   opera   off   ping   lead   red   environ   英文   image   

原文地址:http://www.cnblogs.com/guomeiting/p/7595155.html

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