词干函数错误:词干需要一个位置参数 [英] stem function error: stem required one positional argument

查看:68
本文介绍了词干函数错误:词干需要一个位置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处stem函数显示错误,说明stem需要一个循环中的位置参数,如所讨论的那样?

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

推荐答案

你需要实例化一个 PorterStemmer 对象

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

这篇关于词干函数错误:词干需要一个位置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆