NLTK PortStemmer缺少位置参数

时间:2019-02-01 16:05:12

标签: python nlp nltk

我一直在尝试nltk,但我不明白我的错误是什么。`

我尝试过:

from nltk.stem import PorterStemmer

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

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

Python返回此:

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

有人可以向我解释我做错了什么吗? 预先感谢!

1 个答案:

答案 0 :(得分:0)

()添加到PorterStemmer,因为它是一个类实例,它应该可以工作:

from nltk.stem import PorterStemmer

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

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

标准输出:

car
eat
quickli