NLTK PortStemmer missing positional argument

风流意气都作罢 提交于 2019-12-25 02:44:59

问题


I have been experimenting with nltk, and I do not understand what my mistake is.`

I tried this:

from nltk.stem import PorterStemmer

stemmer = PorterStemmer
examples = ["cars", "eating", "quickly"]

for w in examples:
    print(stemmer.stem(w))

And Python returns this:

TypeError: stem() missing 1 required positional argument: 'word'

Could anyone explain to me what I am doing wrong? Thanks in advance!


回答1:


Add () to PorterStemmer since it is a class instantiation and it should work:

from nltk.stem import PorterStemmer

stemmer = PorterStemmer()
examples = ["cars", "eating", "quickly"]

for w in examples:
    print(stemmer.stem(w))

stdout:

car
eat
quickli


来源:https://stackoverflow.com/questions/54483061/nltk-portstemmer-missing-positional-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!