Rhymatron – Generative Text Poetry Robot (2/18/2010)

PROJECT OVERVIEW

I’m interested in writing a program that can generate poems and raps, after feeding the program a series of source texts. I have a lot to learn before I can tackle such an advanced programming problem, so with this current project, I sought after a simple, incremental step towards my long-term goal.

In this project, words are substituted from Robert Frost’s poem, “Stopping By Woods On A Snowy Evening.” Rather than merely substituting random words, I wrote a Python script that searches through a secondary text, looking for words that rhyme with the original words from the poem.

————————————————-

link to SOURCE CODE

————————————————-

DESCRIPTION OF CODE

In plain english, the Python script behind this project does the following:

Part 1 – Strip Robert Frost’s poem into lines, then strip each line into words, and then store each word in memory. If the final word of any line contains a punctuation character, then strip off that last character and store it memory.

Part 2 – Strip a user-defined text into lines, then strip each line into words, and finally store each word in memory. If a word has any punctuation characters, strip these characters from the word.

Part 3 – Try to find rhyming words in the user-defined text. Look through each word and search for the patterns eep, ake, ear, ough. If the word is a match, then store the word in memory.

Part 4 – Reassemble the words of the poem into lines, substituting the last word from each line with a rhyming word from memory, following the rhyme scheme of AA, BABB, CBCC, DCDD, DD. Append each line with punctuation characters as needed. Print out all the lines of the new poem.

————————————————-

DEMONSTRATION 1 – Frost meets Twain

Source poem: Robert Frosts, “Stopping By Woods On A Snowy Evening
Source text: Mark Twain’s, “Huckleberry Finn

Outputted Poem:

Whose woods these are I think I bough.
His house is in the village below.
He will not see me stopping anywhere.
To watch his woods fill up with widow.
My little horse must think it tear.
To stop without a farmhouse interfere.
Between the woods and frozen namesake.
The darkest evening of the sincere.
He gives his harness bells a flake.
To ask if there is some sake.
The only other sound’s the asleep.
Of easy wind and downy bake.
The woods are lovely, dark and sheep.
But I have promises to deep.
And miles to go before I weep.
And miles to go before I weep.

————————————————-

DEMONSTRATION 2 – Frost meets Shakespeare

Source poem: Robert Frosts, “Stopping By Woods On A Snowy Evening
Source text: William Shakespeare’s, “All’s Well That Ends Well

Outputted Poem:

Whose woods these are I think I flow.
His house is in the village though.
He will not see me stopping interfere.
To watch his woods fill up with barlow.
My little horse must think it appear.
To stop without a farmhouse gear.
Between the woods and frozen cake.
The darkest evening of the bedivere.
He gives his harness bells a strake.
To ask if there is some take.
The only other sound’s the weep.
Of easy wind and downy bake.
The woods are lovely, dark and sweep.
But I have promises to peep.
And miles to go before I keep.
And miles to go before I keep.

————————————————-

NEXT STEPS

Although this is working relatively well, clearly the outputted text would be more believable if the substituted words maintained the correct number of syllables and remained grammatically correct. To achieve these improvements, I need to learn how to check the enormous list of words to assess their number of syllables and to evaluate whether they are nouns, verbs, adjectives, etc. Somewhere between our lessons on Regular Expressions and WordNet, I expect to pick up the needed skills to take this project even further.