1

我正在导入 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 数据。

4

1 回答 1

1

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

>>> 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不适用于不规则复数

看一眼:

于 2015-10-02T10:28:26.450 回答