【问题标题】:stem function error: stem required one positional argument茎函数错误:茎需要一个位置参数
【发布时间】:2018-11-04 20:06:03
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    你需要实例化一个 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)' 会显示错误
    猜你喜欢
    • 2012-07-23
    • 1970-01-01
    • 2014-02-27
    • 2017-06-08
    • 2017-02-25
    • 2014-07-17
    • 2011-10-16
    • 2022-01-14
    • 2017-08-26
    相关资源
    最近更新 更多