Skip to content

Studying the MPs

Last night Tony Hirst was trying to work out the birth-places and universities of the current UK MPs.

Here’s what I managed to produce while hacking with a glass of wine & TV on:

I did some seat of the pants data munging so I thought it’s worth explaining the process I used:

List of MPs

For the graph of MP’s birth-decade I did earlier in the year, I used a dbpedia relationship which gave me a nice little subject ‘member of 2005 UK Parliament’. This time around I can’t find anything so easy for the 2010 Parliament.

Solution, I used,_2010 and a dirty little script…

my @tables = split(/<table/, join(”,<>));
foreach my $tr ( split( /<tr/, $tables[3] ) )
my @td =  split( /<td/, $tr );
if( $td[5] =~ m!”/wiki/([^”]+)”! ) {    print “$1\n”; }
(sorry for the godawful formatting, having hassles pasting code into wordpress since our upgrade.)

This then got munged in a text editor to create a .ttl file (much nicer way to express RDF than XML, esp. when doing hacky scripts)

This gives me this: data, [Browse].

Later I did something almost identical to produce a file adding affiliations as a party label and as an icon red/blue/yellow/other.

This gives me this: data, [Browse].

In retrospect I could have done this in one go, but it was late. Note the raw data of this file is just of the N-Triples format which is really easy to create and easy to import as RDF.

Making the Map Data

I then wrote a quick PHP script using my own Graphite Library to turn this data into geocoded RDF. eg. each resource as rdfs:label, geo:lat, geo:long and also an icon predicate I made up for the day.

View code:

View output:

As it’s a one-shot, I’ve just hard wired the relationship as “” and then I just grab the results using curl. eg.

curl > born.ttl

…and then modify to “almaMater” and repeat.

Making Maps

This gives me files which can be loaded into my GeoRDF2KML tool. This forwards directly to Google Maps as that will accept the URL of a KML file as an input parameter.

Full disclosure; I added a dirty late night hack to geo2kml to accept my icon predicate to allow you to change what icon appears so I can get the by-party-colour-codes. If anyone has a ‘proper’ predicate to relate a geolocation to a map icon, let me know and I’ll support it.

To make things simple, I used ‘curl’ again to save the KML files to the same website.

Final Maps:

Note that the data is patchy. It only shows MPs with a geocoded birthplace/university listed on dbpedia.

Posted in Geo, Graphite, Perl, PHP, RDF.

Tagged with .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.