{"id":1577,"date":"2013-04-02T13:26:49","date_gmt":"2013-04-02T12:26:49","guid":{"rendered":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/?p=1577"},"modified":"2013-04-02T13:46:57","modified_gmt":"2013-04-02T12:46:57","slug":"contemporaneous-part-two","status":"publish","type":"post","link":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/2013\/04\/contemporaneous-part-two\/","title":{"rendered":"Contemporaneous part two"},"content":{"rendered":"<p>Following on from my <a href=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/2013\/04\/contemporaneous-part-one\/\">previous post about BNB and SPARQL<\/a>\u00a0in this post I&#8217;m going to describe briefly building a Chrome browser extension that uses the SPARQL query described in that post &#8211; which given a VIAF URI for an author tries to find authors with the same birth year (i.e. contemporaries of the given author).<\/p>\n<p>Why this particular query? I like it because it exposes data created and stored by libraries that wouldn&#8217;t normally be easy to query &#8211; the &#8216;birth year&#8217; for people is usually treated as a field for display, but not for querying. The author dates are also interesting in that they give a range for the date a book was actually\u00a0<em>written<\/em> rather than\u00a0<em>published<\/em> which is the date that is used in most library catalogue searching.<\/p>\n<p>The other reason for choosing this was that it nicely demonstrates how using &#8216;authoritative&#8217; URIs for things such as people makes the process of bringing together data across multiple sources much easier. Of course whether a URI is &#8216;authoritative&#8217; is a pretty subjective judgement &#8211; based on things like how much trust you have in the issuing body, how widely it is used across multiple sources, how useful it is. In this case I&#8217;m treating VIAF URIs as &#8216;authoritative&#8217; in that I trust them to be around for a while, and they are already integrated into some external web resources &#8211; notably Wikipedia.<\/p>\n<p>The plan was to create something that would work in a browser &#8211; from a page with a VIAF URI in it (with the main focus being Wikipedia pages), allow the user to find a list of &#8216;contemporaries&#8217; for the person based on BNB data. I could have done this with a bookmarklet (similar to <a href=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/2011\/07\/compose-yourself\/\">other projects<\/a> I&#8217;ve done), but a recent conversation with <a href=\"http:\/\/twitter.com\/orangeaurochs\">@orangeaurochs<\/a> on Twitter had put me in mind of writing a browser extension\/plugin instead &#8211; and especially in this case where a bookmarklet would require the user to already know there was a VIAF URI in the page &#8211; it seemed to make sense.<\/p>\n<p>I decided to write a Chrome extension &#8211; on a vague notion it probably had a larger installed base of any browser except Internet Explorer &#8211; but then later checking <a href=\"http:\/\/en.wikipedia.org\/wiki\/Usage_share_of_web_browsers\">Wikipedia stats on browser use<\/a>\u00a0showed that Chrome was the most used on Wikipedia at the moment anyway &#8211; which is my main use case.<\/p>\n<p>I started to look at the Chrome extension documentation. The <a href=\"http:\/\/developer.chrome.com\/extensions\/getstarted.html\">&#8216;Getting Started&#8217; tutorial<\/a>\u00a0got me up and running pretty quickly, and soon I had an extension running that worked pretty much like a bookmarklet and displayed a list of names from BNB based on a hardcoded VIAF URI. The extensions are basically a set of Javascript files (with some html\/css for display), so if you are familiar with Javascript then once you&#8217;ve understood the specific chrome API you should find building an extension quite straightforward.<\/p>\n<p>I then started to look at how I could grab a VIAF URI from the current page in the browser, and only show the extension action when one was found. The documentation suggested this is best handled using the <a href=\"http:\/\/developer.chrome.com\/extensions\/pageAction.html\">&#8216;pageAction&#8217; call<\/a>. A couple of examples (<a href=\"http:\/\/developer.chrome.com\/extensions\/examples\/extensions\/mappy.zip\">Mappy<\/a>\u00a0(zip file with source code) and <a href=\"http:\/\/developer.chrome.com\/extensions\/examples\/api\/pageAction\/pageaction_by_content.zip\">Page Action by content<\/a> (zip file with source code)) and the documentation got me started on this.<\/p>\n<p>Initially I struggled to understand the way different parts of the extension communicate with each other &#8211; partly because the code examples above don&#8217;t use the simplest (or most up to date) approaches (in general there seems to be an issue with the sample extensions sometimes using deprecated approaches). However the <a href=\"http:\/\/developer.chrome.com\/extensions\/messaging.html\">&#8216;Messaging&#8217; documentation<\/a> is much clearer and up to date.<\/p>\n<p>The other challenge is parsing the XML returned from the SPARQL query &#8211; this would be much easier if I used some additional javascript libraries &#8211; but I didn&#8217;t really want to add a lot of baggage\/dependencies to the extension &#8211; although I guess many extensions must include libraries like jQuery to simplify specific tasks. While writing this I&#8217;ve realised that the BNB SPARQL endpoint supports content negotiation, so it is possible to specify JSON as a response format (using Accept: sparql-results+json as per <a href=\"http:\/\/www.w3.org\/TR\/2013\/REC-sparql11-results-json-20130321\/#content-type\">SPARQL 1.1 specification<\/a>) &#8211; which would probably be simpler and faster &#8211; I suspect I&#8217;ll re-write shortly to do exactly this.<\/p>\n<p>The result so far is a Chrome extension that displays an icon in the address bar when it detects a VIAF URI in the current page. The extension then tries to retrieve results from the BNB. At the moment failure (which can occur for a variety of reasons) just means a blank display. The speed of the extension leaves something to be desired &#8211; which means that sometimes you have to wait quite a while for results to display &#8211; which can look like &#8216;failure&#8217; &#8211; I need to add something to show &#8216;working&#8217; status and a definite message on &#8216;failure&#8217; for whatever reason.<\/p>\n<p>A working example looks like this:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-01-at-15.19.16.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-1578\" alt=\"Demonstration of Contemporaneous browser extension\" src=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-01-at-15.19.16-1024x617.png\" width=\"717\" height=\"432\" srcset=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-01-at-15.19.16-1024x617.png 1024w, http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-01-at-15.19.16-300x180.png 300w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\" \/><\/a><\/p>\n<p>Each name in the list links to the BNB URI for the person (which results in a readable HTML display in a browser, but often not a huge amount of data). It might be better to link to something else, but I&#8217;m not sure what. I could also display more information in the popup &#8211; I don&#8217;t think the overhead of retrieving additional basic information from the BNB would be that high. I could also do with just generally prettying up the display and putting some information at the top about what is actually being displayed and the common &#8216;year of birth&#8217; (this latter would be nice as it would allow easy comparison of the BNB data to any date of birth in Wikipedia.<\/p>\n<p>As mentioned, the extension looks for VIAF URIs in the page &#8211; so it works with other sources which do this &#8211; like WorldCat:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-02-at-13.37.36.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-1580\" alt=\"Demonstration of Contemporaneous extension working with WorldCat.org\" src=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-02-at-13.37.36-1024x392.png\" width=\"717\" height=\"274\" srcset=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-02-at-13.37.36-1024x392.png 1024w, http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-02-at-13.37.36-300x114.png 300w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\" \/><\/a><\/p>\n<p>While not doing anything incredibly complicated, I think that it gives one example which starts to answer the question <a href=\"http:\/\/www.meanboyfriend.com\/overdue_ideas\/2012\/08\/what-to-do-with-linked-data\/\">&#8220;What to do with Linked Data?&#8221; which I proposed and discussed in a previous post<\/a>, with particular reference to the inclusion of schema.org markup in WorldCat.<\/p>\n<p>You can download the extension ready for installation, or look at\/copy the source code from\u00a0<a href=\"https:\/\/github.com\/ostephens\/contemporaneous\">https:\/\/github.com\/ostephens\/contemporaneous<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following on from my previous post about BNB and SPARQL\u00a0in this post I&#8217;m going to describe briefly building a Chrome browser extension that uses the SPARQL query described in that post &#8211; which given a VIAF URI for an author tries to find authors with the same birth year (i.e. contemporaries of the given author). [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1577","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/posts\/1577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/comments?post=1577"}],"version-history":[{"count":3,"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/posts\/1577\/revisions"}],"predecessor-version":[{"id":1581,"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/posts\/1577\/revisions\/1581"}],"wp:attachment":[{"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/media?parent=1577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/categories?post=1577"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue_ideas\/wp-json\/wp\/v2\/tags?post=1577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}