Pyechant 和 Webtext 库问题

Pyechant and Webtext library issue

我是 python 的新手,我正在关注一本书 Python 3 with NLTK (CookBook) 我已经通过编写 pip install nltk 成功安装了 nltk 包 在命令中。现在我正在尝试像这样安装 webtext 和 pyechant 库,但我遇到了这个问题:

这也是代码,这些是我遇到的错误 代码:

from nltk.collocations import TrigramCollocationFinder
from nltk.metrics import TrigramAssocMeasures
words = [w.lower() for w in webtext.words('singles.txt')]
tcf = TrigramCollocationFinder.from_words(words)
tcf.apply_word_filter(filter_stops)
tcf.apply_freq_filter(3)
print(tcf.nbest(TrigramAssocMeasures.likelihood_ratio, 4))

错误:

    File "C:/Users/lenovo/Desktop/cook book/ch1(15).py", line 3, in <module>
        words = [w.lower() for w in webtext.words('singles.txt')]
  NameError: name 'webtext' is not defined

添加

从 nltk.corpus 导入网页文本

然后还要确保下载它:

nltk.download('webtext')