poetrygen.py
This software has the following prerequisites:
- Python 2.5 or better with the gdbm module
- pyparsing
- isledict (only to generate the initial database files)
- rhyming dictionary
Download just the script: poetrygen.gz (4.70 KB)
Download the script, pyparsing 1.4.3, isledict 0.2, and rhyming dictionary 0.9's databases: poetrygen-databases.tar.bz2 (6.24 MB)
Usage
The first time you run the script, it must be run with the -T option, which generates databases that it uses from isledict.
Poetry can also be analyzed without a pattern, which will determine a rhyme scheme and a stress pattern. If the analyzer asks for a stress pattern, it must be inputted using 1s to represent stressed syllables and 0s to represent unstressed syllables with no spaces. For example, hypothetical would be typed as: 10100
To make custom poetry, you can make a pattern for the generator to use. The syntax for this is pretty simple:
o is an unstressed syllable
x is a stressed syllable
. is just a syllable.
By combining these, you can make a line. You can also postfix a syllable or a group of syllables with a number, which repeats it that many times. Groups of syllables are syllables that are in parentheses. For example, iambic pentameter is "(ox)5", and the first line of a haiku is ".5".
Every line has a capital letter on the end to denote rhyme scheme. Poems that don't rhyme still require a rhyme scheme. For example, a whole haiku: ".5A .7B .5C"
To re-use a syllable pattern from another line, type a colon and then the line number. For a heroic couplet: "(ox)5A :1A"
To re-use an entire line, including its rhyme scheme, type a semicolon and then the line number. Again, the heroic couplet: "(ox)5A ;1"
Or, a limerick: "(oxo)3A ;1 (oxo)2B ;3 ;1"
A single "n" after a line definition will add a line break in the output. White space doesn't matter in the pattern. You can put it anywhere and the pattern parser won't care.
For Python 2.4 and lower
Here's a quick patch to make poetrygen.py work on Python 2.3 and 2.4: poetrygen.patch (441 Bytes)