'PlaintextCorpusReader'对象没有属性'files'

时间:2014-08-17 18:18:03

标签: python nlp nltk

我正在关注NLTK tutorial,我在Python交互式shell中遇到了这个错误,而本书显示了另一个结果。知道如何解决这个问题吗?

>>> import nltk
>>> nltk.corpus.gutenberg.files()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'PlaintextCorpusReader' object has no attribute 'files'

enter image description here

1 个答案:

答案 0 :(得分:3)

该教程已有6年历史,因此它使用旧版本NLTKnltk.corpus.gutenberg.fileids()将为您提供所需的结果。

In [22]: nltk.corpus.gutenberg.fileids()
Out[22]: 
['austen-emma.txt',
 'austen-persuasion.txt',
 'austen-sense.txt',
 'bible-kjv.txt',
 'blake-poems.txt',
 'bryant-stories.txt',
 'burgess-busterbrown.txt',
 'carroll-alice.txt',
 'chesterton-ball.txt',
 'chesterton-brown.txt',
 'chesterton-thursday.txt',
 'edgeworth-parents.txt',
 'melville-moby_dick.txt',
 'milton-paradise.txt',
 'shakespeare-caesar.txt',
 'shakespeare-hamlet.txt',
 'shakespeare-macbeth.txt',
 'whitman-leaves.txt']