python - Pyechant 和 Webtext 库问题
问题描述
我是 python 新手,我正在关注一本书 Python 3 with NLTK (CookBook) 我已经通过在 Cmd 中编写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 导入 webtext
然后还要确保下载它:
nltk.download('webtext')
推荐阅读
- android - 从其他类片段访问另一个类的功能
- java - Gson:使用通用方法处理
- arrays - VBA - Cells.Find 不适用于从数组中获取的值?
- python-3.x - 从非常相似的 HTML 标签中提取文本
- postgresql - WITH 语句中的查询是否在 PostgreSQL 中的单个事务中执行?
- html - 仅接受使用以 DU- 开头的字母的订单号表单输入
- r - 如何在 R 中使图中实数中的值不复数?
- python - 如何在 Python 中修复网站可用检查?
- c++ - boost::filesystem::space() 报告错误的磁盘空间
- reactjs - 按钮单击时的 Axios 请求