2.1 Accessing Text Corpora

Gutenberg Corpus
NLTK includes a small selection of texts from the Project Gutenberg electronic text
archive, which contains some 25,000 free electronic books, hosted at http://www.gu
tenberg.org/. We begin by getting the Python interpreter to load the NLTK package,
then ask to see nltk.corpus.gutenberg.fileids(), the file identifiers in this corpus:

import nltk
nltk.corpus.gutenberg.fileids()
[‘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’]
Let’s pick out the first of these texts—Emma by Jane Austen—and give it a short name,
emma, then find out how many words it contains:

emma = nltk.corpus.gutenberg.words(‘austen-emma.txt’)
len(emma)

192427

Leave a Reply