Skip to main content

https://data.blog.gov.uk/2009/10/02/using-sparql-with-our-education-datasets/

Using SPARQL with our education datasets

Posted by: , Posted on: - Categories: Uncategorized

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-of-London>;
}
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-and-North-East-Somerset> ;
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-of-London> .

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-and-North-East-Somerset> .
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-and-North-East-Somerset> ;
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

Sharing and comments

Share this page

10 comments

  1. Comment by Anonymous posted on

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

  2. Comment by Anonymous posted on

    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

  3. Comment by Anonymous posted on

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

  4. Comment by Anonymous posted on

    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 <http://education.data.gov.uk/def/school/School>. } 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.

  5. Comment by Anonymous posted on

    Can someone post some examples that work?

    I tried changing the namespace, but got no results.

  6. Comment by Anonymous posted on

    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

  7. Comment by Anonymous posted on

    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.
    http://www.AFLOdds.com.au