【NLTK】安装和使用NLTK分词和去停词

黄聪:Python+NLTK自然语言处理学习(一):环境搭建 

http://www.cnblogs.com/huangcong/archive/2011/08/29/2157437.html

 

安装NLTK可能出现的问题:
1. pip install ntlk
2. 如果遇到缺少stopwords报错如下:(http://johnlaudun.org/20130126-nltk-stopwords/
LookupError:
**********************************************************************
  Resource u'corpora/stopwords' not found. Please use the
  NLTK Downloader to obtain the resource: >>> nltk.download()
  Searched in:
    - 'C:\\Users\\Tree/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'F:\\Program Files (x86)\\python\\nltk_data'
    - 'F:\\Program Files (x86)\\python\\lib\\nltk_data'
    - 'C:\\Users\\Tree\\AppData\\Roaming\\nltk_data'
**********************************************************************
则有一下输入:
In[3]: import nltk
In[4]: nltk.download()
showing info http://www.nltk.org/nltk_data/
弹出窗口:

选择Corpora 然后找到stopword list确认,刷新
Out[4]: True

3.如果遇到缺少punkt报错如下:
LookupError:
**********************************************************************
Resource u'tokenizers/punkt/english.pickle' not found. Please
use the NLTK Downloader to obtain the resource:

    >>>nltk.download()

  Searched in:
    - 'C:\\Users\\Tree/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'F:\\Program Files (x86)\\python\\nltk_data'
    - 'F:\\Program Files (x86)\\python\\lib\\nltk_data'
    - 'C:\\Users\\Tree\\AppData\\Roaming\\nltk_data'
**********************************************************************
解决方法
In[5]: nltk.download('punkt')
[nltk_data] Downloading package punkt to
[nltk_data] C:\Users\Tree\AppData\Roaming\nltk_data...
[nltk_data] Unzipping tokenizers\punkt.zip.
Out[5]: True

文章:http://www.52nlp.cn/%E5%A6%82%E4%BD%95%E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E6%96%87%E6%A1%A3%E7%9A%84%E7%9B%B8%E4%BC%BC%E5%BA%A6%E4%B8%89 文章: http://www.52nlp.cn/%E5%A6%82%E4%BD%95%E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E6%96%87%E6%A1%A3%E7%9A%84%E7%9B%B8%E4%BC%BC%E5%BA%A6%E4%B8%89
详细讲述了如何使用NLTK进行英文分词、去除停用词、词干化、训练LSI、等等文本预处理的步骤。

 

在使用sumy demo时候出错:

C:\Python27\python.exe D:/Python/jieba/demo/sklearn/sumy_demo1.py
Traceback (most recent call last):
  File "D:/Python/jieba/demo/sklearn/sumy_demo1.py", line 20, in <module>
    parser = HtmlParser.from_url(url, Tokenizer(LANGUAGE))
  File "C:\Python27\lib\site-packages\sumy\nlp\tokenizers.py", line 33, in __init__
    self._sentence_tokenizer = self._sentence_tokenizer(tokenizer_language)
  File "C:\Python27\lib\site-packages\sumy\nlp\tokenizers.py", line 45, in _sentence_tokenizer
    "NLTK tokenizers are missing. Download them by following command: "
LookupError: NLTK tokenizers are missing. Download them by following command: python -c "import nltk; nltk.download('punkt')"

 

转载于:https://my.oschina.net/mickelfeng/blog/840864

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值