“PlaintextCorpusReader”对象没有属性“文件”

Mon*_*lal 2 python nlp nltk

我正在遵循 NLTK教程,在 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'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Pad*_*ham 5

该教程已有 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']
Run Code Online (Sandbox Code Playgroud)