天天看点

解决NLTK包下载出错问题及nltk测试

官方下载地址

http://www.nltk.org/nltk_data/

解决NLTK包下载出错问题及nltk测试

安装NLTK-Data

你可以作死的尝试:

>>>import nltk
>>>nltk.download()
           

先点击Refresh,刷新下,之后选中all-corpora点击左下角下载就好,至于路径 

要么在C盘中,要么在Python的根目录下!C盘根目录最靠谱!
解决NLTK包下载出错问题及nltk测试

这是官方正统下载方式,但是肯定会出错的!不仅下的慢,而且下一半就出错!

这里才是正确的下载方式:最好的方法是用使用@V_can打包好的的包网盘下载下载地址1:云盘密码znx7,下来的包nltk_data.zip 解压到C盘根目录下,这样是最保险的,防止找不到包。下载地址2:云盘密码4cp3

NLTK测试

In[4]:from nltk.book import *
# 只输入import nltk 会出错的,但却有很多博客上都这么写,我也母鸡
           
之后会出现如下显示:
*** 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
           
继续测试输入:
In[5]:text1
           
会输出:
Out[5]: 
<Text: Moby Dick by Herman Melville 1851>
           
再测试输入:
In[6]: text1.concordance("monstrous")
           
输出:
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ...
           
ok,这里就演示那么多,到此,NLP的环境就装好了,调试完毕,可以用于自己的实验了。

继续阅读