Wednesday, March 04, 2009

Shakespeare : Sonnets In XML

A long long time ago I found Shakespeare in XML, by Jon Bosak, and I’ve quite literally carried it around with me ever since.  If you’re not a programming geek you may not know the value of XML, so let me try to explain.  XML is like a database inside a file – it is self describing of what’s in it.  So instead of this:

Act 1, Scene 1

SCENE I. Elsinore. A platform before the castle.
    FRANCISCO at his post. Enter to him BERNARDO
    Who's there?

You get something more like this:


<Title>Act 1</Title>


<Title>Scene 1</Title>

<Stagedir>Elsinore.  A platform before the castle … </Stagedir>





<Line>Who’s there?</Line>


Get the idea?  So if you’re a code geek you look at that and start seeing the logic you can apply, like “In Act #3 how many lines are there in all of the speeches spoken by Hamlet?” and it’s quite literally one or two lines of code.

Anyway, I never found the Sonnets in XML.  There’s one or two out there as examples of how to do XML, but I never found the whole set of 154, and I wanted it.

So I made it

It’s very basic, but it does what I need.  If others find it useful and make enhancements I’d appreciate hearing about it.



Anonymous Contractor said...

Thanks Duane! Needed this for syntactic analysis.

Sam Dutton said...

Many thanks for this.

Just to be pedantic, I've spotted what seem to be a few minor errors.

(I'm comparing with the Project text.)

Sonnet 22
Presume not on th;heart when mine is slain,
-> Presume not on thy heart when mine is slain,

Sonnet 29
From sullen earth, sings hymns at heaven's gate,;
-> From sullen earth, sings hymns at heaven's gate;

Sonnet 44
I must attend, time's leisure with my moan;
-> I must attend time's leisure with my moan;

Sonnet 51
In winged speed no motion shall I know,
-> In winged speed n:motion shall I know,

Sonnet 74
Too base of thee to be remembered,.
-> Too base of thee to be remembered.

Sonnet 149
But, love, hate on, for now I know thy mind,;
-> But, love, hate on, for now I know thy mind;

Sonnet 152
To swear against the truth so foul a lie.!
-> To swear against the truth so foul a lie!



Duane said...

Thanks, Sam -- I will update the file with your corrections shortly.

Sam Dutton said...

Cheers Duane.

For what it's worth, I've also ported ;) the sonnets to JSON.

Details in this blog post.

Using the JSON (with apologies for shameless self promotion) I've built an 'instant' sonnet search app.