stem function error: stem required one positional argument

假如想象 提交于 2020-02-04 01:55:47

问题


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)

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

回答1:


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))


来源:https://stackoverflow.com/questions/53140392/stem-function-error-stem-required-one-positional-argument

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