Apr 01

I recently did a couple of workshops for the British Library about data on the web. As part of these workshops I did some work with the the BNB data using both the API and the SPARQL endpoint. Having a look and play with the data got me thinking about possible uses. One of the interesting things about using the SPARQL endpoint directly in place of the API is that you have a huge amount of flexibility about the data you can extract, and the way SPARQL works lets you do in a single query something that might take repeated calls to an API.

So starting with a query like:

SELECT *
WHERE {
<http://bnb.data.bl.uk/id/person/Bront%C3%ABCharlotte1816-1855> ?p ?o
}

This query finds triples about “Charlotte Brontë”. The next query does the same thing, but uses the fact that the BNB makes (where possible) ‘sameAs’ statements about BNB URIs to the equivalent VIAF URIs:

PREFIX owl:  <http://www.w3.org/2002/07/owl#>
SELECT ?p ?o
WHERE {
?person owl:sameAs <http://viaf.org/viaf/71388025> .
?person ?p ?o
}

This query first finds the BNB Resource which is ‘sameAs’ the VIAF URI for Charlotte Brontë (which is http://bnb.data.bl.uk/id/person/Bront%C3%ABCharlotte1816-1855)  – this is done by:

?person owl:sameAs <http://viaf.org/viaf/71388025>

The result of this query is one (or potentially more than one, although not in this particular case) URI, which are then used in the next part of the query:

?person ?p ?o

In this case, the query is slightly wider in that it is possible that there is more than one BNB resource identified as being the ‘sameAs’ the VIAF URI for Charlotte Brontë (although in actual fact there isn’t in this case).

Taking the query a bit further, we can find the date of birth for Charlotte Brontë:

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
PREFIX bio:  <http://purl.org/vocab/bio/0.1/>
SELECT ?dob
WHERE {
?person owl:sameAs <http://viaf.org/viaf/71388025> .
?person bio:event ?event .
?event rdf:type bio:Birth .
?event bio:date ?dob
}

The ‘prefix’ statements are just to setup a shorthand for the query – rather than having to type out the whole URI each time I can use the specified ‘prefix’ as an equivalent to the full URI. That is:

PREFIX bio:  <http://purl.org/vocab/bio/0.1/>
?person bio:event ?event

is equivalent to

?person <http://purl.org/vocab/bio/0.1/event> ?event

Having got to this stage – the year of birth based on a VIAF URI – we can use this to extend the query to find other people in BNB with the same birth year – the eventual query being:

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
PREFIX bio:  <http://purl.org/vocab/bio/0.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?dob ?name
WHERE {
?persona owl:sameAs <http://viaf.org/viaf/71388025> .
?persona bio:event ?eventa .
?eventa rdf:type bio:Birth .
?eventa bio:date ?dob .
?eventb bio:date ?dob . 
?eventb rdf:type bio:Birth .
?personb bio:event ?eventb .
?personb foaf:name ?name
}

I have to admit I’m not sure if this is the most efficient way of getting the result I want, but it does work – as you can see from the results. What is great about this query is that the only input is the VIAF URI for an author. We can substitute the one used here for any VIAF URI to find people born in the same year as the identified person (as long as they are in the BNB).

Since VIAF URIs are now included in many relevant Wikipedia articles, I thought it might be fun to build a browser extension that would display a list of ‘contemporaries’ for using the BNB data – partly to show how the use of common identifiers can make these things just fit together, partly to try building a browser extension and partly because I think it is a nice demonstration of the potential uses of library data which we have in libraries but often don’t exploit (like the years of birth/death for people).

But since this post has gone on long enough I’ll do a follow up post on building the extension – but if you are interested the code is available at https://github.com/ostephens/contemporaneous

written by ostephens

One Ping to “Contemporaneous part one”

  1. Contemporaneous part two » Overdue Ideas Says:

    […] Contemporaneous part one […]


Leave a Reply