书中-就职演说语料库这个小程序统计词汇america和citizen随时间推移的使用情况这个小程序有点bug,我电脑python版本(Python 3.6.1)
原书中代码是
>>> 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))
>>>
>>> cfd.plot()
这里改成下面的就可以运行了file[:4] -> fileid[:4]:
>>> 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))
>>>
>>> cfd.plot()