Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate random text in NLTK 3.0?

Tags:

python

nlp

nltk

The generate method of nltk.text.Text seems to have been removed in NLTK 3.0.

For example:

>>> bible = nltk.corpus.gutenberg.words(u'bible-kjv.txt')
>>> bibleText = nltk.Text(bible)
>>> bibleText.generate()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Text' object has no attribute 'generate'

It may just be that I'm remembering wrongly how to do this, but everything I can find online seems to support the above method. Any ideas what I'm doing wrong?

like image 474
Peter Macgregor Avatar asked Oct 03 '14 16:10

Peter Macgregor


People also ask

What is Gutenberg NLTK?

1.1 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.gutenberg.org/.

What is a corpora in NLTK?

A corpus can be defined as a collection of text documents. It can be thought as just a bunch of text files in a directory, often alongside many other directories of text files. How it is done ? NLTK already defines a list of data paths or directories in nltk.

What is concordance NLTK?

Saving output of NLTK text. concordance() NLTK provides the function concordance() to locate and print series of phrases that contain the keyword. However, the function only print the output. The user is not able to save the results for further processing unless redirect the stdout.


1 Answers

A note in the first online chapter of the NLTK book says that:

The generate() method is not available in NLTK 3.0 but will be reinstated in a subsequent version.

like image 173
arturomp Avatar answered Sep 21 '22 14:09

arturomp