SPARQL
Introduction¶
The SPARQL plugin provides a compliant endpoint for executing SPARQL queries against an RDF rendering of the data. The underlying data store of Mauro Data Mapper is Postgres, and this plugin uses the D2RQ library for extracting the information as RDF triples.
The REST API ensures that the mapping is configured with correct access constraints so that users may only see a subset of the triples corresponding to their access privileges. In the most basic cases, a system administrator can query across the whole data corpus in triple form; an unauthenticated user on an instance with no publicly available models will not be able to see any triples.
Warning
This plugin allows users to execute their own queries against the data store. A malicious user may write arbitrarily complex queries which could cause Mauro to slow down or become unresponsive. If you install this plugin, you may wish to ensure the Mauro instance is behind a firewall, and ensure that users know what they are doing!
API Endpoints¶
The plugin provides two (equivalent) endpoints which accept a SPARQL query as part of the request body and return results in a variety of formats.
The Accept header determines which format is returned, according to the table below:
Accept Header Value | Response Format |
---|---|
application/sparql-results+xml
xml application/xml |
XML |
text/csv
csv |
CSV |
application/sparql-results+json
json application/json |
JSON |
The default format is for results to be returned in JSON format.
In future, it may be possible to extend this plugin to support RDF/XML and other formats.
Response format¶
For the request body given in Example 1 below, the response body will have one of the following formats:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
1 2 3 |
|
Example Queries¶
This page is not intended to provide a tutorial to writing SPARQL queries - some other tutorials are available online and linked below. These examples serve as a starting point for exploring the triple space.
Example 1: Arbitrary triples¶
Select the first 20 triples from the entire graph:
1 2 3 |
|
Example 2: Restricting types¶
Select the labels of all Data Models:
1 2 3 4 5 6 |
|
Example 3: Relating entities¶
Find the id
of the classes which belong to a model called "Complex Test DataModel":
1 2 3 4 5 6 7 8 |
|
Example 4: Relations, multiple results¶
Find the Enumeration Values which have a 'Value' of "Not known". Find their keys and the label of the containing data type:
1 2 3 4 5 6 7 8 9 |
|
Example 5: Finding metadata¶
Find the schema.org
abstract
property from a Data Model:
1 2 3 4 5 6 7 8 |
|
Example 6: Transitive searches¶
The first query finds the immediate child classes of a model:
1 2 3 4 5 6 7 8 |
|
Compare this with the second, which transitively follows the child_class_of
relationship to find child classes of that class:
1 2 3 4 5 6 7 8 |
|
Example 7: Transitive Searches on Terminologies¶
This search recursively finds all terms narrower than another, and provides their code and definition:
1 2 3 4 5 6 7 8 9 10 11 |
|
Links to SPARQL Tutorials¶
There are many good tutorials available online - this is not intended to represet a comprehensive list. But here are some some that we've found useful in the past: