下面是我尝试编码的一种方法。但是,在代码的第3行中,它表示存在属性错误,并且“ WordListCorpusReader”对象在python中没有属性“ word”。请帮我看看下面的代码:((
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/topicmodel/topicmodel.py", line 41, in <module>
stop = set(stopwords.word('english'))
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\nltk\corpus\util.py", line 119, in __getattr__
return getattr(self, attr)
AttributeError: 'WordListCorpusReader' object has no attribute 'word'
这是运行代码后的追溯:
<div class="row">
<section>
<section>
<section>
<p> My Content </p>
</section>
</section>
</section>
</div>
答案 0 :(得分:1)
是错字。您应该调用的方法是stopwords.words()
。更改:
stop = set(stopwords.word('english'))
进入
stop = set(stopwords.words('english'))
这应该可以解决此问题。
NLTK文档页面上的更多信息: https://www.nltk.org/api/nltk.corpus.html?highlight=corpus#module-nltk.corpus