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