stem function error: stem required one positional argument

4130 views python
-1

here stem function shows error saying that stem required one positional argument in loop as in question?

from nltk.stem import PorterStemmer as ps 

text = 'my name is pythonly and looking for a pythonian group to be formed by me iteratively'

words = word_tokenize(text)

words

for word in words:
    print(ps.stem(word))

answered question

1 Answer

4

You need to instantiate a PorterStemmer object

from nltk.stem import PorterStemmer as ps
from nltk.tokenize import word_tokenize

stemmer = ps()

text = 'my name is pythonly and looking for a pythonian group to be formed by me iteratively'
words = word_tokenize(text)
for t in words:
    print(t, stemmer.stem(t))

posted this

Have an answer?

JD

Please login first before posting an answer.