针对Steven Bird等著《Python自然语言处理》书中问题总结:
P3:
nltk.download()不好用
文件下载:百度网盘下载,提取码:7dbt
下载完成后解压放在C:\下即可
P7:
xxx.generate()函数报错
NLTK3.x.x等新版本无此函数了,旧版本才有这么高级的功能。
P18:
fdist1输出问题
P22
.collocations()运行报错
高版本的nltk库中此函数会报错,提示ValueError: too many values to unpack (expected 2),按报错提示信息找到collocations()函数中,将函数改为如下:
P288
探索文本语料库小节代码报错:NotImplementedError: Use label() to access a node label.
解决方法有两种。
#第一种改法:
if subtree.node=='CHUNK':
#改为:
if subtree._label=='CHUNK':
#第二种改法:
#找到Tree类中函数_get_node(),并改为:
def _get_node(self):
"""Outdated method to access the node value; use the label() method instead."""
#raise NotImplementedError("Use label() to access a node label.")
return self._label