Python: ubuntu 下安装nltk以及载入 nltk-data

1 篇文章 0 订阅

NLTK在自然语言处理方面很方便, 具体介绍官网即可.下面记录了安装以及手动载入nltk-data的过程.

安装NLTK

sudo pip install -U nltk 即可
python 的终端里面,输入:import nltk 如果不报错即表明安装成功.

下载nltk-data 载入

  1. 自动下载安装

    import nltk
    nltk.download()

  2. 手动下载载入
    由于在国外的网站下,下载近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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值