Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Generates books based on other books using nltk

Project description


A python library using nltk to analyse two books and generate a new one.


pip install bookgen


from bookgen import BookGen

book = BookGen("word_base_book.txt", "sentence_base_book.txt")
# will download the nltk extras required, only needed once



BookGen will parse word classes from the first specified book, looking like this:

{"NOUN": ["Mountain", "Valley"], "VERB": ["take", "went"]}

These are sorted by the nltk universal tagset.

The second book serves as sentence base. It will be parsed into a list of word types that represent the whole book.

["NOUN", "VERB", "PREP", "NOUN", "CONJ", "VERB", "."]

Then, it generates a list of words from the words of the first book based on the second book.

["Nathan", "went", "to", "Valley", "and", "peed", "."]

This is joined with some capitalization fixes and returned.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bookgen, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size bookgen-1.0.0-py3-none-any.whl (3.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bookgen-1.0.0.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page