问题
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