Pyechant和Webtext库问题

问题描述 投票:0回答:1

我是python的新手,我正在阅读一本带有NLTK(CookBook)的Python 3书。我通过在Cmd中编写pip install nltk成功地安装了nltk包。现在我试图像这样安装webtext和pyechant库,但我遇到了这个问题:enter image description here

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

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

enter image description here

python nltk libraries
1个回答
1
投票

来自nltk.corpus导入webtext

然后还要确保下载它:

nltk.download( 'webtext')

© www.soinside.com 2019 - 2024. All rights reserved.