Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python stem函数错误:stem需要一个位置参数_Python_Python 3.x_Nlp_Nltk_Porter Stemmer - Fatal编程技术网

Python stem函数错误:stem需要一个位置参数

Python stem函数错误:stem需要一个位置参数,python,python-3.x,nlp,nltk,porter-stemmer,Python,Python 3.x,Nlp,Nltk,Porter Stemmer,这里的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(wo

这里的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))

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

但是,如果我使用ps.stem(i)而不是stemmer=ps(),然后运行“print(ps.stem(i)”,为什么会显示错误