【问题标题】:NLTK PortStemmer missing positional argumentNLTK PortStemmer 缺少位置参数
【发布时间】:2019-02-02 00:10:48
【问题描述】:

一直在试验nltk,不明白自己的错误是什么`

我试过这个:

from nltk.stem import PorterStemmer

stemmer = PorterStemmer
examples = ["cars", "eating", "quickly"]

for w in examples:
    print(stemmer.stem(w))

Python 会返回这个:

TypeError: stem() missing 1 required positional argument: 'word'

谁能向我解释我做错了什么? 提前致谢!

【问题讨论】:

  • 你忘记调用构造函数了:stemmer = PorterStemmer().

标签: python nlp nltk


【解决方案1】:

() 添加到PorterStemmer,因为它是一个类实例化并且应该可以工作:

from nltk.stem import PorterStemmer

stemmer = PorterStemmer()
examples = ["cars", "eating", "quickly"]

for w in examples:
    print(stemmer.stem(w))

标准输出:

car
eat
quickli

【讨论】:

    猜你喜欢
    • 2021-12-05
    • 2021-12-25
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 2021-02-22
    • 1970-01-01
    相关资源
    最近更新 更多