Using SPARQL with our education datasets

One of the large databases that have been converted into Linked Data by the data.gov.uk team is Edubase, DCSFs database of all the schools. This is a large database (about 6 million triples) and a little too big to download, especially if you only want a small amount of the information that Edubase contains (like, say, just the schools in Norfolk), rather than the whole database.

We have made Edubase available in RDF (our thanks to Stewart Williams, Dave Reynolds and Brian McBride of Hewlett Packard), and you can query it using SPARQL by making requests to: http://services.data.gov.uk/education/sparql.

To help developers use SPARQL, Leigh has kindly created a number of example SPARQL queries of the Edubase data. To begin with you may find it easier to adapt some of these queries, than start creating your own from scratch. The results are returned using the SPARQL XML results format. You can also return results in JSON by adding "&output=json" to the URL.

Try some of these queries out for yourself on the Education SPARQL endpoint. One other tip is to think about what you are asking for – some SPARQL queries that return a lot of data may take a little time to run.

Select the names of schools in the Administrative District of the City of London, ordering results by name of the school

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
SELECT ?name WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:districtAdministrative
<http://education.data.gov.uk/placeholder-id/administrativeDistrict/City-...
}
ORDER BY ?name

Which schools in the BANES area have a nursery?

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:districtAdministrative
<http://education.data.gov.uk/placeholder-id/administrativeDistrict/Bath-... ;
sch-ont:nurseryProvision "true"^^xsd:boolean
}
ORDER BY ?name

Select the names and addresses of schools in the Administrative District of the City of London, ordering results by name of the school.

Note: we use OPTIONAL here as not every school has an address listed in the data

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
SELECT ?name ?address1 ?address2 ?postcode ?town WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:districtAdministrative
<http://education.data.gov.uk/placeholder-id/administrativeDistrict/City-... .

OPTIONAL {
?school sch-ont:address ?address .

?address sch-ont:address1 ?address1 ;
sch-ont:address2 ?address2 ;
sch-ont:postcode ?postcode ;
sch-ont:town ?town .
}
}
ORDER BY ?name

Select the name, lowest and highest age ranges, capacity and pupil:teacher ratio for all schools in the Bath & North East Somerset district.

Note, again we use OPTIONAL to allow for missing data items.

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
SELECT ?name ?lowage ?highage ?capacity ?ratio WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:districtAdministrative
<http://education.data.gov.uk/placeholder-id/administrativeDistrict/Bath-... .
OPTIONAL {
?school sch-ont:statutoryLowAge ?lowage ;
}

OPTIONAL {
?school sch-ont:statutoryHighAge ?highage ;
}

OPTIONAL {
?school sch-ont:schoolCapacity ?capacity ;
}

OPTIONAL {
?school sch-ont:pupilTeacherRatio ?ratio
} }
ORDER BY ?name

What is the URI, name, and opening date of the oldest school in the UK?

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
SELECT ?school ?name ?date WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:districtAdministrative
<http://education.data.gov.uk/placeholder-id/administrativeDistrict/Bath-... ;
sch-ont:openDate ?date.
}
ORDER BY ASC(?date)
LIMIT 1

Select the name, easting and northing for the 100 newest schools in the UK.

Note, this could be used to plot them on a map.

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
SELECT ?school ?name ?date ?easting ?northing WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:openDate ?date ;
sch-ont:easting ?easting ;
sch-ont:northing ?northing .
}
ORDER BY DESC(?date)
LIMIT 100

Select the URI, name, easting and northing for all schools opened in 2008

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?school ?name ?date ?easting ?northing WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name;
sch-ont:openDate ?date ;
sch-ont:easting ?easting ;
sch-ont:northing ?northing .
FILTER (?date > "2008-01-01"^^xsd:date && ?date < "2009-01-01"^^xsd:date)
}

In which parliamentary constituencies did schools open in 2008?

prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?cons ?label WHERE {
?school a sch-ont:School; sch-ont:establishmentName ?name ;
sch-ont:openDate ?date ;
sch-ont:parliamentaryConstituency ?cons .
?cons rdfs:label ?label.
FILTER (?date > "2008-01-01"^^xsd:date && ?date < "2009-01-01"^^xsd:date)
}
ORDER BY ?cons

Comments

How do you find out the full list of sch-ont?

What query will reveal the list of accessible sch-ont values?

 Flag as offensive 

Reply to 'How do you find out the full list of sch-ont?'

Here is a link to the education ontology:

http://education.data.gov.uk/ontology/school.rdf

This link is on a blog page that has further links to other useful information - including an explanation of how to use SPARQL to explore an unknown dataset.

The blog page is here:

http://blogs.talis.com/n2/archives/818

Cheers.

 Flag as offensive 

Useful website with RDF schemas

Hi,

This link is to a website suggested by W3C that gathers together information about and links to RDF schemas:

http://www.schemaweb.info/

Cheers.

 Flag as offensive 

Reply to 'How do you find the full list of sch-ont?'

Hi,

I had the same question and found the answer here:

http://education.data.gov.uk/ontology/school.rdf

This link was part of a bigger blog about using SPARQL to query data which is here:

http://blogs.talis.com/n2/archives/818

Cheers,

Iain D.

 Flag as offensive 

DATA exposed with SPARQL endpoints

What other data sets can be accessesd with SPARQL inn addition to the education data set?

 Flag as offensive 

School URI's and the Datastore

Are the school URi's de-referenciable? Doen't look like they are!!

How can a general purpose SPARQL service such as HP's ARQ can be pointed at this data set. Is it possible at all?

Neither of the following works:
http://data.hmg.gov.uk/education
http://education.data.gov.uk

 Flag as offensive 

Why the examples don't work...

I tried each of the examples but each one returned an empty set of results.
After trying the following (much simpler) example
SELECT DISTINCT ?type
WHERE{
?object a ?type.
}
LIMIT 10

it seemed that it was something wrong with the examples provided. (rather than the server, or my soft/hardware, or me)
After that i tried this:

DESCRIBE ?school
WHERE{
?school a .
}
LIMIT 1

and realised that the prefix definition in the examples was wrong.

Swapping
prefix sch-ont: <http://education.data.gov.uk/ontology/school#>
for
prefix sch-ont: <http://education.data.gov.uk/def/school/>
fixes some of the examples.
Hope this helps anyone who was as confused as I.

 Flag as offensive 

Not working

Can someone post some examples that work?

I tried changing the namespace, but got no results.

 Flag as offensive 

Please clearly update your examples

I think it'd help folks if someone would clearly update this blog post with examples to reflect the latest schema. I arrived here this morning and wanted to copy and paste the code and see something work. I was confused when the examples didn't work. Fortunately, Chris Wallace (http://twitter.com/kitwallace/status/8551231207) was kind enough to respond to my tweet of confusion (http://twitter.com/rdhyee/status/8547035043) by pointing out http://blogs.talis.com/n2/archives/818

In retrospect, I could have read the comments to this post and learned about where to find corrections -- but a note at the top of the post pointing to updates would help newbies like me who had heard about data.gov.uk and want to see what it's all about.

Thanks, -Raymond Yee

 Flag as offensive 

this page could certainly do with updating...

Thanks for sharing this with us. I have to agree with the other commentors here that the page would be vastly improved with some formatting and tidying up. http://chromebook.co.uk

 Flag as offensive 

Thanks for every other

Thanks for every other informative site. The place else may just I get that kind of information written in such an ideal means? I have a venture that I’m just now operating on, and I have been on the look out for such information.
www.AFLOdds.com.au

 Flag as offensive