词干函数错误:词干需要一个位置自变量

时间:2018-11-04 11:37:39

标签: python python-3.x nlp nltk porter-stemmer

在这里,词干函数显示错误,表示词干需要循环使用一个位置自变量?

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 个答案:

答案 0 :(得分:3)

您需要实例化PorterStemmer对象

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