参考书籍《Python自然语言处理》,书籍中的版本是Python2和NLTK2,我使用的版本是Python3和NLTK3

安装NLTK3,Natural Language Toolkit,自然语言工具包,地址:http://www.nltk.org/

安装命令:pip install nltk

代码:

SaintKings-Mac-mini:~ saintking$ sudo pip install nltk

Password:

The directory '/Users/saintking/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/Users/saintking/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Collecting nltk

Requirement already satisfied: six in /Library/Python/2.7/site-packages (from nltk)

Installing collected packages: nltk

Successfully installed nltk-3.2.5

SaintKings-Mac-mini:~ saintking$

安装完成后测试:import nltk

SaintKings-Mac-mini:~ saintking$ python

Python 2.7.10 (default, Jul 30 2016, 18:31:42)

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import nltk

>>> nltk.download()

showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml

没有报错即表明安装成功。

下载NLTK-Data,在Python中输入命令:

>>>import nltk

>>>nltk.download()

弹出新的窗口,用于选择下载的资源

双击行后安装.

>>> import nltk

>>> nltk.download()

showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml

True

>>>

点击File可以更改下载安装的路径。all表示全部数据集合,all-corpora表示只有语料库和没有语法或训练的模型,book表示只有书籍中例子或练习的数据。需要注意一点,就是数据的保存路径,要么在C盘中,要么在Python的根目录下,否则后面程序调用数据的时候会因为找不到而报错。

【注意:软件安装需求:Python、NLTK、NLTK-Data必须安装,NumPy和Matplotlin推荐安装,NetworkX和Prover9可选安装】

简单测试NLTK分词功能:

---

下面看一下NLTK数据的几种方法:

1.加载数据

>>> from nltk.book import *

*** Introductory Examples for the NLTK Book ***

Loading text1, ..., text9 and sent1, ..., sent9

Type the name of the text or sentence to view it.

Type: 'texts()' or 'sents()' to list the materials.

text1: Moby Dick by Herman Melville 1851

text2: Sense and Sensibility by Jane Austen 1811

text3: The Book of Genesis

text4: Inaugural Address Corpus

text5: Chat Corpus

text6: Monty Python and the Holy Grail

text7: Wall Street Journal

text8: Personals Corpus

text9: The Man Who Was Thursday by G . K . Chesterton 1908

>>>

2.搜索文本

>>> print(text1.concordance('monstrous'))

Displaying 11 of 11 matches:

ong the former , one was of a most monstrous size . ... This came towards us ,

ON OF THE PSALMS . " Touching that monstrous bulk of the whale or ork we have r

ll over with a heathenish array of monstrous clubs and spears . Some were thick

d as you gazed , and wondered what monstrous cannibal and savage could ever hav

that has survived the flood ; most monstrous and most mountainous ! That Himmal

they might scout at Moby Dick as a monstrous fable , or still worse and more de

th of Radney .'" CHAPTER 55 Of the Monstrous Pictures of Whales . I shall ere l

ing Scenes . In connexion with the monstrous pictures of whales , I am strongly

ere to enter upon those still more monstrous stories of them which are to be fo

ght have been rummaged out of this monstrous cabinet there is no telling . But

of Whale - Bones ; for Whales of a monstrous size are oftentimes cast up dead u

None

>>>

3.相似文本

>>> print(text1.similar('monstrous'))

imperial subtly impalpable pitiable curious abundant perilous

trustworthy untoward singular lamentable few determined maddens

horrible tyrannical lazy mystifying christian exasperate

None

>>>

4.共用词汇的上下文

>>> print(text2.common_contexts(['monstrous','very']))

a_pretty is_pretty a_lucky am_glad be_glad

None

>>>

5.词汇分布图

>>> text4.dispersion_plot(['citizens','democracy','freedom','duties','America'])

6.词汇统计

#encoding=utf-8

importnltkfrom nltk.book import *

print('~~~~~~~~~~~~~~~~~~~~~~~~~')print('文档text3的长度:',len(text3))print('文档text3词汇和标识符排序:',sorted(set(text3)))print('文档text3词汇和标识符总数:',len(set(text3)))print('单个词汇平均使用次数:',len(text3)*1.0/len(set(text3)))print('单词 Abram在text3中使用次数:',text3.count('Abram'))print('单词Abram在text3中使用百分率:',text3.count('Abram')*100/len(text3))

自然语言处理和python_Python与自然语言处理搭建环境相关推荐

  1. Python与自然语言处理搭建环境

    参考书籍<Python自然语言处理>,书籍中的版本是Python2和NLTK2,我使用的版本是Python3和NLTK3 实验环境Windows8.1,已有Python3.4,并安装了Nu ...

  2. AIBlockChain:“知名博主独家讲授”人工智能创新应用竞赛【精选实战作品】之《基于计算机视觉、自然语言处理和区块链技术的乘客智能报警系统》案例的界面简介、功能介绍分享之自然语言处理技术

    AI&BlockChain:"知名博主独家讲授"人工智能创新应用竞赛[精选实战作品]之<基于计算机视觉.自然语言处理和区块链技术的乘客智能报警系统>案例的界面简 ...

  3. 深度学习、自然语言处理和表征方法

    深度学习.自然语言处理和表征方法 2014/10/18 · IT技术 · 3 评论 · 机器学习, 深度学习, 自然语言处理 分享到:0 本文由 伯乐在线 - XiaoxiaoLi 翻译.未经许可,禁 ...

  4. 【机器学习基础】太棒了!这里有385篇自然语言处理和机器学习领域的综述总结...

    文章来源于python遇见NLP,作者自然语言er 综述论文对于初学者来说,可以方便其在研究初期尽快掌握该方向的发展趋势.目前我在GitHub上发现一个开源项目,上面总结了385篇自然语言处理和机器学 ...

  5. 30个顶级Python库 | 用于深度学习、自然语言处理和计算机视觉

    CDA数据分析师 出品 作者:Matthew Mayo 编译:Mika 今天我们来盘点一下有哪些用于深度学习.自然语言处理和计算机视觉的顶级Python库. 我们尽力将每个库按预期的使用情况进行归类, ...

  6. lump搭建环境知识点

    lump搭建环境知识点: 1.nginx使用fastCGI(CGI通用网关接口,可以用任何一种语言编写,只要这种语言具有标准输入.输出和环境变量.)实现与php的通信.apache开启php扩展模块实 ...

  7. AIBlockChain:“知名博主独家讲授”人工智能创新应用竞赛【精选实战作品】之《基于计算机视觉、自然语言处理和区块链技术的乘客智能报警系统》案例的界面简介、功能介绍分享之总篇

    AI&BlockChain:"知名博主独家讲授"人工智能创新应用竞赛[精选实战作品]之<基于计算机视觉.自然语言处理和区块链技术的乘客智能报警系统>案例的界面简 ...

  8. AIBlockChain:“知名博主独家讲授”人工智能创新应用竞赛【精选实战作品】之《基于计算机视觉、自然语言处理和区块链技术的乘客智能报警系统》案例的界面简介、功能介绍分享之区块链技术

    AI&BlockChain:"知名博主独家讲授"人工智能创新应用竞赛[精选实战作品]之<基于计算机视觉.自然语言处理和区块链技术的乘客智能报警系统>案例的界面简 ...

  9. AIBlockChain:“知名博主独家讲授”人工智能创新应用竞赛【精选实战作品】之《基于计算机视觉、自然语言处理和区块链技术的乘客智能报警系统》案例的界面简介、功能介绍分享之汽车驾驶乘客自动报警

    AI&BlockChain:"知名博主独家讲授"人工智能创新应用竞赛[精选实战作品]之<基于计算机视觉.自然语言处理和区块链技术的乘客智能报警系统>案例的界面简 ...

最新文章

  1. 今日 Paper | 新闻推荐系统;多路编码;知识增强型预训练模型等
  2. NIPS改名为NeurIPS的原因
  3. 通过汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的
  4. 高速串行总线设计基础(四)眼图的形成原理
  5. Xamarin.IOS中MvvmCross的plugin使用方式
  6. java面试和笔试大全
  7. 交付铁三角的故事之兵戎相见
  8. ARC和MRC混合使用
  9. 做科普自媒体是怎么挣钱的?
  10. spring中定时器cron表达式在线生成器
  11. php中wamp具体指的是,phpwamp和wampserver有什么关系,为什么名字都带wamp这几个字母,两者有区别吗?我应该用哪个?...
  12. 《Conditional BERT Contextual Augmentation》论文笔记
  13. 仙剑永恒的经典──仙剑诗集
  14. 一起来看 Google 在中国国际进口博览会的精彩展示!
  15. spinningup环境搭建
  16. 后台管理 vue+element 开源框架
  17. pytorch深度学习框架--gpu和cpu的选择
  18. 内网信息收集——工作组/域信息收集
  19. 实现多个文件夹名同时重命名的操作
  20. Idea创建JavaEE项目

热门文章

  1. 2018计算机专硕学硕,2018考生快上车!专硕VS学硕,究竟怎么选?
  2. 2207.16吃货联盟设计大纲和全部代码
  3. NC系统销售业务说明
  4. Java实现pdf文件转图片
  5. 深信服 一面 2018 秋招
  6. 【PC工具】压缩包密码破解工具,暴力破解压缩包密码,zip密码获取
  7. OGG FOR BIGDATA 安装(修正)
  8. MySQL语句-查看当前数据库有哪些表(SHOW TABLES)
  9. 三个灭点来衡量一个立方体
  10. linux下交叉编译date命令,arm移植NTP(同步嵌入式linux系统时间)