我在尝试执行一些python代码时收到了一个我不理解的错误。我试图通过优秀的NLTK教科书学习使用自然语言工具箱。在尝试下面的代码(对图2.1中我自己的数据进行了修改)时,我收到了下面的错误。在
我运行的代码:
import os, re, csv, string, operator
import nltk
from nltk.corpus import PlaintextCorpusReader
dir = '/Dropbox/hearings'
corpus_root = dir
text = PlaintextCorpusReader(corpus_root, ".*")
cfd = nltk.ConditionalFreqDist(
(target, fileid[:3])
for fileid in text.fileids()
for w in text.words(fileid)
for target in ['budget','appropriat']
if w.lower().startswith(target))
cfd.plot()
收到错误(完全回溯):
^{pr2}$我加入了新的IPython行来说明这是完全错误。(在阅读其他问题时,我发现“AssertionError:”后面往往会有更多的信息。在我的错误中,它是空白的。)
如果您能帮助我理解代码中的错误,我将不胜感激!谢谢!在
我可以通过创建一个空文件
foo
,然后调用text.words('foo')
来重现错误:为了避免出现空文件,可以执行以下操作:
^{pr2}$相关问题 更多 >
编程相关推荐