{"id":591,"date":"2010-12-10T10:32:11","date_gmt":"2010-12-10T10:32:11","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/webteam\/?p=591"},"modified":"2010-12-10T10:33:01","modified_gmt":"2010-12-10T10:33:01","slug":"studying-the-mps","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/webteam\/2010\/12\/10\/studying-the-mps\/","title":{"rendered":"Studying the MPs"},"content":{"rendered":"<p>Last night <a href=\"http:\/\/blog.ouseful.info\/2010\/12\/10\/where-linked-data-would-be-useful-creating-more-mps-maps-from-the-guardian-politics-api\/\">Tony Hirst was trying to work out the birth-places and universities of the current UK MPs<\/a>.<\/p>\n<p>Here&#8217;s what I managed to produce while hacking with a glass of wine &amp; TV on:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"MP Map\" src=\"http:\/\/farm6.static.flickr.com\/5007\/5248153609_3985f88963.jpg\" alt=\"\" width=\"500\" height=\"378\" \/><\/p>\n<p>I did some seat of the pants data munging so I thought it&#8217;s worth explaining the process I used:<\/p>\n<h3>List of MPs<\/h3>\n<p>For the <a href=\"http:\/\/blog.soton.ac.uk\/webteam\/2010\/03\/01\/the-dangers-of-an-indelible-life\/\">graph of MP&#8217;s birth-decade<\/a> I did earlier in the year, I used a dbpedia relationship which gave me a nice little subject &#8216;member of 2005 UK Parliament&#8217;. This time around I can&#8217;t find anything so easy for the 2010 Parliament.<\/p>\n<p>Solution, I used <a href=\"http:\/\/en.wikipedia.org\/wiki\/MPs_elected_in_the_UK_general_election,_2010\">http:\/\/en.wikipedia.org\/wiki\/MPs_elected_in_the_UK_general_election,_2010<\/a> and a dirty little script&#8230;<\/p>\n<address>my @tables = split(\/&lt;table\/, join(&#8221;,&lt;&gt;));<br \/>foreach my $tr ( split( \/&lt;tr\/, $tables[3] ) )<\/address>\n<address>{<\/address>\n<address> my @td =\u00a0 split( \/&lt;td\/, $tr );<\/address>\n<address> if( $td[5] =~ m!&#8221;\/wiki\/([^&#8221;]+)&#8221;! ) {\u00a0\u00a0\u00a0 print &#8220;$1\\n&#8221;; }<br \/>}<\/address>\n<address>(sorry for the godawful formatting, having hassles pasting code into wordpress since our upgrade.)<\/address>\n<p>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)<\/p>\n<p>This gives me this: <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mps.ttl\">data<\/a>, [<a href=\"http:\/\/graphite.ecs.soton.ac.uk\/browser\/?uri=http%3A%2F%2Fgraphite.ecs.soton.ac.uk%2Fexperiments%2Fparlibirth%2Fmps.ttl\">Browse<\/a>].<\/p>\n<p>Later I did something almost identical to produce a file adding affiliations as a party label and as an icon red\/blue\/yellow\/other.<\/p>\n<p>This gives me this: <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/affil.ttl\">data<\/a>, [<a href=\"http:\/\/graphite.ecs.soton.ac.uk\/browser\/?uri=http%3A%2F%2Fgraphite.ecs.soton.ac.uk%2Fexperiments%2Fparlibirth%2Faffil.ttl\">Browse<\/a>].<\/p>\n<p>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.<\/p>\n<h3>Making the Map Data<\/h3>\n<p>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.<\/p>\n<p>View code: <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mpmunge.txt\">http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mpmunge.php<\/a><\/p>\n<p>View output:<a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mpmunge.php\"> http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mpmunge.php<\/a><\/p>\n<p>As it&#8217;s a one-shot, I&#8217;ve just hard wired the relationship as &#8220;http:\/\/dbpedia.org\/ontology\/birthPlace&#8221; and then I just grab the results using curl. eg.<\/p>\n<pre>curl <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mpmunge.txt\">http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/mpmunge.php<\/a> &gt; born.ttl<\/pre>\n<p>&#8230;and then modify to &#8220;almaMater&#8221; and repeat.<\/p>\n<ul>\n<li><a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/born.ttl\">http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/born.ttl<\/a><\/li>\n<li><a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/studied.ttl\">http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/studied.ttl<\/a><\/li>\n<\/ul>\n<h3>Making Maps<\/h3>\n<p>This gives me files which can be loaded into my <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/geo2kml\/\">GeoRDF2KML tool<\/a>. This forwards directly to Google Maps as that will accept the URL of a KML file as an input parameter.<\/p>\n<p>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 &#8216;proper&#8217; predicate to relate a geolocation to a map icon, let me know and I&#8217;ll support it.<\/p>\n<p>To make things simple, I used &#8216;curl&#8217; again to save the KML files to the same website.<\/p>\n<ul>\n<li><a href=\"http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/studied.kml\">MP Universities KML file<\/a><\/li>\n<\/ul>\n<p>Final Maps:<\/p>\n<ul>\n<li><a href=\"http:\/\/maps.google.com\/?q=http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/born.kml\">Where UK MPs were born<\/a><\/li>\n<li><a href=\"http:\/\/maps.google.com\/?q=http:\/\/graphite.ecs.soton.ac.uk\/experiments\/parlibirth\/studied.kml\">Where UK MPs went to university<\/a><\/li>\n<\/ul>\n<p>Note that the data is patchy. It only shows MPs with a geocoded birthplace\/university listed on dbpedia.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last night Tony Hirst was trying to work out the birth-places and universities of the current UK MPs. Here&#8217;s what I managed to produce while hacking with a glass of wine &amp; TV on: I did some seat of the pants data munging so I thought it&#8217;s worth explaining the process I used: List of [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[352,4224,281,4225,138,136],"tags":[],"class_list":["post-591","post","type-post","status-publish","format-standard","hentry","category-data","category-geo-2","category-graphite","category-perl","category-php","category-rdf"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/comments?post=591"}],"version-history":[{"count":8,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/591\/revisions"}],"predecessor-version":[{"id":599,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/591\/revisions\/599"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/media?parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/categories?post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/tags?post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}