How to get all of the predicates of an object in SPARQL

I finally discovered the other day how to get all of the predicates of an object in SPARQL. For this example I’ll query the University of Cambridge endpoint to get all of the information they have about The Lord of the Rings.

SELECT * WHERE
{
    'http://data.lib.cam.ac.uk/id/entry/cambrdgedb_1327612' ?p ?o .
}

This query returns the following data:

p o
http://purl.org/dc/terms/title The Lord of the Rings
http://purl.org/dc/terms/type http://data.lib.cam.ac.uk/id/type/1cb251ec0d568de6a929b520c4aed8d1
http://purl.org/dc/terms/type http://data.lib.cam.ac.uk/id/type/46657eb180382684090fda2b5670335d
http://purl.org/dc/terms/identifier UkCU1327612
http://purl.org/dc/terms/identifier urn:isbn:0048231576
http://purl.org/dc/terms/issued 1979
http://purl.org/dc/terms/language http://id.loc.gov/vocabulary/iso639-2/eng
http://RDVocab.info/ElementsplaceOfPublication http://id.loc.gov/vocabulary/countries/enk
http://purl.org/ontology/bibo/isbn 0048231576
http://purl.org/dc/terms/creator http://data.lib.cam.ac.uk/id/entity/cambrdgedb_041c446ee6c5c4bd5a63bcc2debe1351
http://iflastandards.info/ns/isbd/elements/P1016 London
http://purl.org/dc/terms/publisher http://data.lib.cam.ac.uk/id/entity/cambrdgedb_b7c309134a35a5455692006ee550ddf6
http://purl.org/dc/terms/created 1979
http://purl.org/dc/terms/extent http://data.lib.cam.ac.uk/id/entity/cambrdgedb_935bf1a181de0991dce6d3ee56b53ba4
http://iflastandards.info/ns/isbd/elements/P1008 3rd ed

You can run this query yourself

Linkey

I’ve very pleased to announce that LNCD have won another JISC funded project under the Access and Identity Management programme. This will be the fifth JISC project I’ll have worked on (for the other projects I’ve been involved with see my bio.

The project is called Linkey (yes we managed to make another Lincoln based pun to join our others – lncn.eu (“Linking You”) and LNCD (“LNCD is Not a Central Development group“) and will be looking at how the OAuth 2.0 specification can be implemented in HEIs. The primary driver for this is to improve the student and staff experience and meet the following objectives:

  1. Richer sharing of data between applications: A student or lecturer should be able to identify themselves to multiple applications and approve access to the sharing of personal data between those applications.
  2. A consistent user experience (UX): We are initially aiming for ‘consistent sign on’ rather than ‘single sign on’, where the user is presented with a consistent UX when signing into disparate applications.
  3. Rapid deployment: New applications that we develop or purchase should be easier to implement, plugging into either OAuth or the UAG and immediately benefiting from 1) and 2).

The project will last for 12 months and the primary outcomes will be:

  1. A case study about our use and implementation of OAuth here at the University of Lincoln
  2. Significantly adding to my CodeIgniter OAuth 2.0 server by implementing the OAuth SAML bearer specification as well as hopefully all of the main authentication flows. I’m also going to work with on turning it it into a generic PHP Composer package so any PHP application can get some OAuth love. Finally I want to look at implementing [Selenium] tests (in addition to the usual PHPUnit tests) so that there is an awesome user experience.
  3. A public workshop on the use of OAuth 2.0 in Further and Higher Education.
  4. A conference/journal paper, based on our case study.
I’d just like to say a quick thanks to Joss Winn for writing another fantastic bid which I’ve embedded:

Learning SPARQL

In my post about the future of data.lincoln.ac.uk I committed us to providing a SPARQL endpoint for University of Lincoln open linked data. Today I’ve spent an insane amount of time learning how on earth SPARQL works.

I set up a local triplestore on my laptop using ARC2, I used EasyRDF to output a dump of the staff directory as RDF XML, I used Chris Gutteridge’s Graphite and Browser code to check the EasyRDF output looked right, then finally after I’d loaded the data into the triplestore I used Dave Challis’ SPARQLfront to query the data.

So far I’ve managed to work out the following queries:

(copied from https://gist.github.com/2475211/)


Get all divisions

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX org: <http://www.w3.org/ns/org#>
SELECT DISTINCT ?dept ?deptName
WHERE {
  ?dept a org:OrganizationalUnit .
  ?dept rdfs:label ?deptName .
  ?dept org:unitOf <http://lincoln.ac.uk/> .
}

Get all departments in $DIVISION$

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX org: <http://www.w3.org/ns/org#>

SELECT DISTINCT ?dept ?deptName
WHERE {
  ?dept a org:OrganizationalUnit .
  ?dept rdfs:label ?deptName .
  ?dept org:unitOf <http://id.online.lincoln.ac.uk/division/$DIVISION$> .
}

Get all staff in $DIVISION$

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX org: <http://www.w3.org/ns/org#>

SELECT  ?givenName ?familyName
WHERE {
  ?person a foaf:Person .
  ?person org:memberOf <http://id.online.lincoln.ac.uk/division/$DIVISION$> .
  ?person org:memberOf ?division .
  ?division a org:OrganizationalUnit .
  ?division org:unitOf ?parent .
  ?person foaf:givenName ?givenName .
  ?person foaf:familyName ?familyName .
  FILTER (?parent = "http://lincoln.ac.uk/")
}

Get all staff in $DEPARTMENT$

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX org: <http://www.w3.org/ns/org#>

SELECT ?givenName ?familyName
WHERE {
  ?person a foaf:Person .
  ?person org:memberOf <http://id.online.lincoln.ac.uk/department/$DEPARTMENT$> .
  ?person org:memberOf ?division .
  ?division a org:OrganizationalUnit .
  ?division org:unitOf ?parent .
  ?person foaf:givenName ?givenName .
  ?person foaf:familyName ?familyName .
  FILTER (?parent != "http://lincoln.ac.uk/")
}

Get the division that a member of staff is in

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX org: <http://www.w3.org/ns/org#>

SELECT ?name
WHERE {
  ?division a org:OrganizationalUnit .
  ?division org:unitOf <http://lincoln.ac.uk/> .
  ?division rdfs:label ?name .
  ?division org:hasMember <http://id.online.lincoln.ac.uk/person/$ID$> .
}

Get the department that a member of staff in is

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX org: <http://www.w3.org/ns/org#>

SELECT ?name
WHERE {
  ?division a org:OrganizationalUnit .
  ?division org:unitOf ?parent .
  ?division rdfs:label ?name .
  ?division org:hasMember <http://id.online.lincoln.ac.uk/person/$ID$> .
  FILTER (?parent != "http://lincoln.ac.uk/")
}

So that is what I’ve worked out so far.

Once I’ve got the final spaces data in the next week or so I’ll figure out some more queries which mix people and spaces.

Some of the resources that I found useful whilst learning SPARQL include:

My thanks also go to Chris Gutteridge, Tony Hirst, Dave Challis, Nicholas J Humfrey, and Benjamin Nowack for their various blog posts and code libraries which I also found useful.

Update to my CodeIgniter MongoDB library

I’ve updated my CodeIgniter MongoDB library to version 0.5.1 (zip|tar.gz|spark). It mostly contains bug fixes and optimisations.

Version 2.0 of the library is almost finished – check it out at https://github.com/alexbilbie/codeigniter-mongodb-library/tree/v2 . I’m currently working out how PHP Unit works so that the library can be tested on Travis CI each time a new commit is made.