在这里,词干函数显示错误,表示词干需要循环使用一个位置自变量?
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))
答案 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))