Managed to get some simple processing of the Louvre HTML with TagSoup. I love the TagSoup library because it gives the same kind of whipupitude you might expect from Perl, the ability to just throw together to do something that works by eyeball. You can use it as a sort of tag-aware grep, for example, taking a potentially
malformed page and extracting only the interesting text:
The Chiusi funerary monuments
This plaque from an Etruscan funerary monument was discovered in 1843. It entered the Louvre's collections in 1863 with the purchase by Napoleon III of the Marquis Campana's antiquities collection. It comes from the region of Chiusi in Umbria, where it was created around 490-480 BC. At that time, the Chiusi workshops were particularly famous for their funerary monuments - stone columns that were used to indicate the placement of tombs or to hold urns. This plaque is characteristic of this production. The bas-relief is sculpted in a local stone that, when quarried, gives off a very disagreeable odor caused by the infiltration of sulfurous water. For this reason it is called "fetid limestone".
A funeral ceremony
...
The TagSoup model should remind you a bit of SAX. You get a list of objects like
TagOpen "a" [("href","http://...)..] which you can trundle through with your basic Haskell stdlib higher order list functions. The kind of code you get is not just terse, but simple, very very simple. Just a pipeline of function compositions. Here's the pipeline I used (read it right-to-left, mathy style like f o g)
louvreText = intersperse (TagText "\n\n")
. map trimText
. filter isRealText
. takeWhile (~/= "<div id=bibliographie>")
. drop 1
. dropWhile (\x -> x ~/= "Description" && x ~/= "Notice")
The two part (with Description) chops off any bits of the documentation before a bit of HTML text that either says "Description" or "Notice", the second part chops off that little bit of text, then we grab anything up to the bibliographie div, and finally we get rid of any boring text (boring here is defined as whitespace only -- isRealText is a small helper function I wrote), get rid of the whitespace surrounding the HTML text we do have, and then insert double newlines in between each paragraph.
There... so much for my Haskell propaganda. It's not so much about building short programs -- code golf is stupid -- but simple ones. Simple here meaning few moving parts, absence of bureaucracy, homogeneity (ie. just a pipeline). Understanding what a higher order function is may be not so simple at first, but once you're happy with that, you get to knock out little programs like the above without having to think so much.
Today, I intend to continue my TagSoup adventure, grabbing links to all 303 texts and fetching the corresponding documents. Then I'll have built up a little mini corpus which I can do some more interesting text processing on. I'm afraid I'm still doing this to procrastinate on the main job of analysing the output on the Sussex Sculptures texts... probably one of my personal failings, a tendency to prefer tasks that involve Doing rather than Thinking :-/