【问题标题】:NLTK importError when using Porter Stemmer使用 Porter Stemmer 时出现 NLTK importError
【发布时间】:2015-10-02 18:28:46
【问题描述】:

我正在导入 nltk,但它给出了以下错误。

Traceback (most recent call last):
  File "/home/control/Work/Intelligence/Datasets/whats cooking/new.py", line 4, in <module>
    import nltk
  File "/usr/local/lib/python2.7/dist-packages/nltk-3.0.5-py2.7.egg/nltk/__init__.py", line 137, in <module>
    from nltk.stem import *
  File "/usr/local/lib/python2.7/dist-packages/nltk-3.0.5-py2.7.egg/nltk/stem/__init__.py", line 29, in <module>
    from nltk.stem.snowball import SnowballStemmer
  File "/usr/local/lib/python2.7/dist-packages/nltk-3.0.5-py2.7.egg/nltk/stem/snowball.py", line 25, in <module>
    from nltk.stem import porter
ImportError: cannot import name porter

几天前我的 nltk 运行良好,我没有更新或更改任何内容,而且我还安装了所有 nltk 数据。

【问题讨论】:

    标签: python nlp nltk importerror porter-stemmer


    【解决方案1】:

    在 NLTK(参见 http://www.nltk.org/howto/stem.html)中,Porter 词干分析器的惯用用法是:

    >>> from nltk.stem import PorterStemmer
    >>> porter = PorterStemmer()
    >>> sent = 'I went on wild geese chases'
    >>> porter.stem(sent)
    u'I went on wild geese chas'
    

    注意:PorterStemmer 不适用于不规则复数形式

    看看:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多