python自然语言处理-学习笔记(二)
来源:互联网 发布:小米4支持4g网络吗 编辑:程序博客网 时间:2024/05/22 10:41
在第二章中,主要介绍了各个预料库的使用,这里不再赘述,对于预料库的操作,之前书中都提到过。这里只说一下一个问题,在inaugural预料库中,测试输出条件分布图的时候,他的代码里有个问题,我按照书中写的方法,得到的结果如下:
>>> cfd = nltk.ConditionalFreqDist(\... (target, file[:4])\... for fileid in inaugural.fileids()\... for w in inaugural.words(fileid)\... for target in ['america','citizen']\... if w.lower().startswith(target))Traceback (most recent call last): File "<stdin>", line 3, in <module> File "/usr/local/lib/python2.7/dist-packages/nltk-3.0a4-py2.7.egg/nltk/probability.py", line 1695, in __init__ for (cond, sample) in cond_samples: File "<stdin>", line 6, in <genexpr>TypeError: 'type' object has no attribute '__getitem__'其实,在操作之前就对函数里的首项中的file有疑问,以为可能会有默认的设置,结果出错了,在这里将file改成fileid接可以了,代码如下:
>>> cfd = nltk.ConditionalFreqDist(\... (target, fileid[:4])\... for fileid in inaugural.fileids()\... for w in inaugural.words(fileid)\... for target in ['america','citizen']\... if w.lower().startswith(target))>>>在wordnet那一小结里面,所有的synset对象属性的调用,其实都是方法的调用(不知道这么说对不对???),也就是说书中的wn.synset('car.n.01').examples要写成wn.synset('car.n.01').examples()才对正确的,整一节都是类似的问题,有很多,在这里就不一一列举了,大家如果遇到下面这句话:TypeError: 'instancemethod' object is not iterable,就在你的变量的属性改成方法就行,也就是'.'后面的变量加‘()’让它变成方法
0 0
- python自然语言处理-学习笔记(二)
- 《Python自然语言处理》学习笔记(二)
- python自然语言处理学习笔记二
- python自然语言处理-学习笔记(一)
- 《Python自然语言处理》学习笔记(一)
- 《Python自然语言处理》学习笔记(三)
- python自然语言处理(二)
- Python+NLTK自然语言处理学习(二…
- Python 自然语言处理学习笔记(一)-- 软件安装需求
- python自然语言处理学习笔记第一章
- python自然语言处理学习笔记第二章
- python自然语言处理学习笔记第三章
- python nltk自然语言处理学习笔记1
- python nltk自然语言处理学习笔记2
- python自然语言处理学习笔记一
- python自然语言处理学习笔记三
- 《Python自然语言处理》学习笔记-第一章
- 《Python自然语言处理》学习笔记-第二章
- 16 oj 小平
- 解决【HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容】
- linux网络编程学习笔记之五 -----并发机制与线程池
- hdu4217 Data Structure?
- HDU 1176 免费馅饼 (DP)
- python自然语言处理-学习笔记(二)
- SecureCRT中的Ctrl+C不可用
- mysql查看表结构 乐杨俊
- web开发利用filter拦截未登录用户
- 外贸网站优化实用的五种方法
- 单链表建立c++实现
- [笔记]VS2010 LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 的解决方法
- Java老学员重回广州传智,大方传授面试经验
- 我在博看文思学习生活