1

I am importing nltk, but it gives the following error.

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

My nltk was working perfectly a few days ago and i haven't updated or changed anything and I've also installed all the nltk data.

alvas
  • 115,346
  • 109
  • 446
  • 738
ahereza
  • 466
  • 5
  • 10

1 Answers1

1

The idiomatic use of Porter stemmer in NLTK (see http://www.nltk.org/howto/stem.html) would be:

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

Note: that PorterStemmer don't work very well with irregular plurals

Take a look at:

Community
  • 1
  • 1
alvas
  • 115,346
  • 109
  • 446
  • 738