Acrostic Shakespearean Sonnets
by Paul Thompson - firstname.lastname@example.org
Full plaintext output can be found here.
Total word count is 602,175.
On my machine it runs in about 70 seconds.
Generate a set of sonnets that are acrostics, using every one of the letters
of each of Shakespeare's sonnets to start each line. Each line of the result
will be selected from elsewhere in the Shakespeare cannon, and they will use
ababcdcdefefgg rhyming form.
The first 2 lines of the first sonnet are:
From fairest creatures we desire increase, That thereby beauty's rose might never die,
So, removing non-alphas and splitting into 14-letter chunks, the first five output poems will be acrostic sonnets on:
fromfairestcre atureswedesire increasethatth erebybeautysro semightneverdi
The Sonnets is used as the basis of the acrostics, and the actual lines themselves come from anywhere in any of the plays and poems.
Amendment 1: Sonnet 146
Sonnet 146 suffers from a typographical error in the original publication, where the first two syllables of the second line are overwritten by words from the preceding line. The affected line is recorded in the Open Source Shakespeare database as:
[ ] these rebel powers that thee array;
I wasn't sure what to do with this lacuna. Should I leave it as is, or should I replace it with a more poetic alternative? There are a few well regarded choices I could have selected, among them:
Why feed'st Starv'd by Foiled by Fenced by Fool'd by Feeding Rebuke
I was sentimentally tempted to go with
Fool'd by, as that's the replacement
used in my great-grandmother's Complete Works, but I went with
instead. The reason: it makes the envoi a four letter acrostic on
love, which really I think is just perfect.
Amendment 2: Zounds!
My first attempt at generation failed. It left 16 sonnets that could not be created using the correct letters with the correct rhymes. I investigated this and discovered that it was the letter "Z" that was causing the issue. There simply were not enough lines beginning with that letter in the corpus.
Examining the database, the only lines that start with "Z" are lines beginning
Zounds. But because "zounds" is a contraction, there were other lines
in the data that begin instead with
My solution was to remove any leading apostrophes from lines that start with
Zounds, and the acrostic regex can match
Pretty simple change, and it fixed the issue completely.
Replication / Forking
To install and run this code yourself, you'll need Ruby and PostgreSQL.
shakespeare.sql from this repo.
Create a database using the instructions in the repo.
Save an environment variable 'DB_URL_SHAKESPEARE' with the database URL in the below format:
i.e. postgres://user:password@server/database e.g. postgres://Paul:swordfish@localhost/shakespeare
git clone https://github.com/nossidge/shakespeare_acrostics.git cd shakespeare_acrostics bundle install
The generation code is in