Search code examples
pythonmachine-learningnltkporter-stemmer

what is missing parameter in the below mentioned program?


For the below-mentioned python program it is displaying an error

from nltk.stem import PorterStemmer 
ps=PorterStemmer
words = ["program", "programs", "programer", "programing", "programers"]
for w in words: 
    print(w, " : ", ps.stem(w)) 

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

I'm not able to find out the missing parameter. What is that parameter?


Solution

  • You need to instantiate the PorterStemmer class, not use it directly.

    This:

    ps=PorterStemmer

    needs to become this:

    ps = PorterStemmer()

    More on the matter here.


    Future word of advice

    It is imperative that you try to research as much as possible before posting on stackoverflow. You could have found the answer to this question, as it is a simple question, if you took the error (exactly as it is) and just pasted it on Google.

    You would have found this answer and also this answer and this one and many more. And you would have gained a lot more than simply getting the answer.