阀杆功能错误:阀杆需要一个位置参数

2024-06-08 14:47:21 发布

您现在位置:Python中文网/ 问答频道 /正文

这里的stem函数显示了一个错误,说stem在循环中需要一个位置参数?在

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

Tags: 函数textfromimportfor参数myas
1条回答
网友
1楼 · 发布于 2024-06-08 14:47:21

您需要实例化一个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))

相关问题 更多 >