Print/Download

Technical information

Print this page

SPARQL endpoint tutorial

SPARQL

http://en.wikipedia.org/wiki/SPARQL is a query language for RDF; this page exposes an endpoint for SPARQL queries on the Australian Curriculum. SPARQL can carry out the following types of query:

  • SELECT: Extract the values matching a query over the RDF, much like an SQL SELECT statement
  • ASK: Report whether a query is true or false
  • CONSTRUCT: Extract information out of the endpoint, and present it as valid RDF
  • DESCRIBE: Extract a complete RDF graph out of the endpoint

Variables in SPARQL are prefixed with ?, e.g. ?x. The namespaces of URIs used in queries are given through PREFIX. For example, the query “return all content descriptions tagged with SCOT term 975 (Algebra), and their corresponding year levels” is

prefix asn: <http://purl.org/ASN/schema/core/> 
prefix scot: <http://vocabulary.curriculum.edu.au/scot/>
prefix dc: <http://purl.org/dc/terms/> 

select ?x ?y 
where { 
    ?x asn:conceptTerm scot:975 . 
    ?x asn:statementLabel "Content description" @en-au . 
    ?x dc:educationLevel ?y . 
}
    

—that is, return all instances of x and y for which:

  • x has the concept term scot:975
  • x has the statement label “Content Description” [with the mandatory language tag “en-au”]
  • x has the education level y

(To run this query, you will need to change the content type in the pulldown menu to application/sparql-results+xml or application/sparql-results+json).

Sample queries

Retrieve All Curriculum Documents

The default query on the SPARQL endpoint is to return RDF for all Standards Documents in the Australian Curriculum:

prefix asn: <http://purl.org/ASN/schema/core/> 
construct { ?s ?p ?o }
where 
{ 
    ?s a asn:StandardDocument . ?s ?p ?o . 
} 
    

—that is, build RDF statements for instances of s for which “s is a Standard Document” is true. Each RDF statement will have a predicate ?p, an object ?p, and a subject ?s constrained to being a Standard Document.

From this page several things can be demonstrated:

  • You can run the default query to see the RDF of the ASN Standard Documents.
  • You can click the link below the query results to see the RDF directly in your browser. (All SPARQL queries can be retrieved through URL encoding of the query.)
  • You can copy-and-paste any of the RDF URLs into a browser and get auto-redirected to the ".html" friendly page.
  • You can remove the year and month from the URL and it redirects back to the URL of the latest version of the curriculum statement.
  • You can use the simple HTML pages to navigate down the statement hierarchy to a content description and click on the linked statement code to see that it redirects of the latest version of the curriculum statement.
  • You can change the URL of a page ending in ".html" to end with ".rdf" instead to see the machine readable RDF/XML of the curriculum statement rather than the human-friendly version.
  • You can click on the manifest link (only visible on the HTML page of a Standard Document) to see the ASN manifest.

Retrieve All Curriculum Statements

Because every statement is "part of" a Standard Document the default SPARQL query can be extended to retrieve all curriculum statements. Compare:

prefix asn: <http://purl.org/ASN/schema/core/> 
prefix dct: <http://purl.org/dc/terms/>

construct 
    { ?s ?p ?o } 
where 
{ 
    {
        ?s a asn:StandardDocument . 
        ?s ?p ?o . 
    } 
    union
    { 
        ?d a asn:StandardDocument . 
        ?s dct:isPartOf ?d . 
        ?s ?p ?o . 
    } 
} 
    

—that is, build RDF statements for any ?s which are Standards Documents, as well as any ?s which are “part of” a Standard Document ?d. Running this query will retrieve all Standard Documents, and their associated Standard Statements.

If we wished to constrain the query to one curriculum area, we would look up the URI of the area, and include it in the query. The URIs for the curriculum areas are:

  • Mathematics F-10 curriculum: http://rdf.australiancurriculum.edu.au/elements/2012/08/4e0d84fb-9095-4db6-a031-9e4600a2533d
  • English F-10 curriculum: http://rdf.australiancurriculum.edu.au/elements/2012/08/7f6bd186-fcdf-4e46-a727-9e4600a2a39b
  • Science F-10 curriculum: http://rdf.australiancurriculum.edu.au/elements/2012/08/593bf494-a404-4057-8cb2-9e4600a2dba8
  • History F-10 curriculum: http://rdf.australiancurriculum.edu.au/elements/2012/08/da83c9fc-914a-46dd-a383-9e4600a31686

Retrieve the History Curriculum Document and all its Curriculum Statements

So to retrieve just the History curriculum, including all its statements, we would issue the query:

prefix asn: <http://purl.org/ASN/schema/core/> 
prefix dct: <http://purl.org/dc/terms/>
    
construct 
{ ?s ?p ?o } 
where 
{ 
    { 
        <http://rdf.australiancurriculum.edu.au/elements/2012/08/da83c9fc-914a-46dd-a383-9e4600a31686> ?p ?o . 
    } 
    union 
    { 
        ?s dct:isPartOf <http://rdf.australiancurriculum.edu.au/elements/2012/08/da83c9fc-914a-46dd-a383-9e4600a31686> . 
        ?s ?p ?o . 
    }
} 
	

—that is, retrieve the RDF of all statements about the History Curriculum document, and all statements which are part of the History Curriculum document.

Although this query returns data for all of the individual statements it does not contain information about the correct ordering of statements. On side-effect of aligning with ASN export version 3.1 is that we no longer guarantee the order of <dcterms:haschild> relationships in the RDF. To ensure that parent-child relationships are ordered correctly the ASN manifest must be utilised.

The data for each Standard Document contains a <dcterms:tableofcontents> that holds the URL for the manifest related to that Document. The manifest is a JSON file that shows the correct parent-child ordering (e.g. the order of content descriptions in a sub-strand).

Back to top