SPARQL
This page allows you to lodge SPARQL queries against the triplestore (graph database) that stores all of this systems' vocabularies'.
Use the interactive Query UI below to lodge queries interactively or send queries directly to the system using the instructions below that.
For some help with sparql please visit our github repo.
Interactive UI
Enter SPARQL queries in the text box below to lodge them interactively:
Example Queries
Collection Count
Here is an example query you can copy 'n paste into the Query UI text area above to test with. It counts the number of Collections (i.e. vocabularies) in this system and will return an integer:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT (COUNT(?c) AS ?count) WHERE { ?c a skos:Collection . }
It should return something like 286
.
Concept Labels
Here is another example. It returns the URI and prefLabel(s) of 5 random Concepts on this system:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?c ?pl WHERE { ?c a skos:Concept ; skos:prefLabel ?pl . } LIMIT 5
Concept Schemes
This query returns a sorted list of NVS' Concept Schemes (thesauri)' URIs and their titles (prefLabels):
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?c ?pl WHERE { ?c a skos:ConceptScheme ; skos:prefLabel ?pl . } ORDER BY ?pl
Direct Queries
The SPARQL endpoint for this system is:
http://vocab.nerc.ac.uk/sparql/sparql
If you would like to lodge queries directly against this SPARQL endpoint without using the Query UI above, first create the query, URL-encode it, and lodge it like this:
http://vocab.nerc.ac.uk/sparql/sparql?query={YOUR_QUERY_URL_ENCODED}
You can use the query encoder below to URL-encode your query.
Machine-readable responses
If you lodge your query as above with a web browser, the system will place it in the interactive UI text area (above) and you will see the result below that.
To obtain a machine-readable response to your query, you must supply an HTTP Accept header for the type of response you would like, in accordance with the SPARQL Protocol standard.
For example, to get a SPARQL JSON format response for {YOUR_QUERY_URL_ENCODED}
, use the curl program like this:
curl 'http://vocab.nerc.ac.uk/sparql/sparql?query={YOUR_QUERY_URL_ENCODED}'
-H 'Accept: application/sparql-results+json'
SPARQL response Accept Headers
The following Media Types are to be used for machine-readable responses:
- SPARQL response formats:
application/sparql-results+json
text/csv
text/tab-separated-values
- RDF response formats:
text/turtle
application/rdf+xml
application/ld+json
text/n3
application/n-triples
If you omit one of the above headers, your query will be placed into this page and the result displayed interactively.
If the header you've included doesn't match the format of the SPARQL response type, you will receive that response type's default format, e.g. text/turtle
for CONSTRUCT
queries, application/sparql-results+json
for SELECT
queries.
GET & POST queries
You can lodge both GET
and POST
queries against this system, as per the SPARQL Protocol standard.
Query Encoder
Enter your SPARQL query into this text box and click "URL Encode" to URL encode it. That will
generate a single encoded string with spaces replaced by "%20" and other character replacements
which you can then use in place of {YOUR_QUERY_URL_ENCODED}
above.
You might like to test out your query first using the Query UI above too.