NLTK在自然语言处理方面很方便, 具体介绍官网即可.下面记录了安装以及手动载入nltk-data的过程.
sudo pip install -U nltk
即可
在python
的终端里面,输入:import nltk
如果不报错即表明安装成功.
自动下载安装
import nltk
nltk.download()
手动下载载入
由于在国外的网站下,下载近300M的语料数据,实在太慢了,于是就打算单独下载nlkt-data
国内有人放到了百度网盘打开连接,
下载之后,问题是把这些数据放到那里, 它会自己检测,可以通过下面import
检测到目录:
from nltk.book import *
结果会报错误,其中有一段如:
LookupError:
**********************************************************************
Resource u'corpora/gutenberg' not found. Please use the NLTK
Downloader to obtain the resource: >>> nltk.download()
Searched in:
- '/home/shomy/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
**********************************************************************
一目了然了~ 我们只需要把下载下来的nltk-data.zip
解压到以上的一个目录,就可以了,
In [3]: 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
这样就可以使用nltk-data
了