Skip to content
This repository has been archived by the owner. It is now read-only.
Go to file
Cannot retrieve contributors at this time
63 lines (51 sloc) 4.14 KB

SPARQL Service

The GNAF LDAPI supports a SPARQL service endpoint at This service can be used to query the RDF graph version of the GNAF data, as opposed to the Postgres version of the data which is queried by the Linked Data API. the graph version is kept in sync with the Postgres version by being emptied and rebuilt on every Postgres verson's release.

Service description

The capabilities of the SPARQL endpoint are described with metadata in accordance with the SPARQL 1.1 Service Description. The service's metadata about its endpoints, functions and other details - such as whether it is read/write or read only - can be retrieved from using an HTTP GET request without any query parameter strings. As per Linked Data norms, the metadata formatted in RDF can be accessed with an Accept header set to an RDF MIME format (e.g. text/turtle or application/rdf_xml) and an HTML version can be accessed with an Accept header of text/html, which is the default. You can visit the service endpoint using a normal web browser to see the HTML version and the RDF version, in the rutle format, is reproduced below:

@prefix rdf:  <> .
@prefix sd:   <> .
@prefix sdf:  <> .
@prefix void: <> .
@prefix xsd:  <> .

    a                       sd:Service ;
    sd:endpoint             <> ;
    sd:supportedLanguage    sd:SPARQL11Query ; # yes, read only!
    sd:resultFormat         sdf:SPARQL_Results_JSON ;  # we only deliver JSON results, sorry!
    sd:feature sd:DereferencesURIs ;
    sd:defaultDataset [ # there are no Named Graphs within this triplestore
        a sd:Dataset ;
        sd:defaultGraph [
            a sd:Graph ;
            void:triples "286779722"^^xsd:integer # yes, more than 286 million triples!

## Example queries
This query gets all the aliases of an Address (ADDRESS_X) and the Alias type:

PREFIX gnaf: SELECT ?aliasAddress ?aliasType WHERE { <ADDRESS_X> gnaf:hasAlias [ gnaf:aliasOf ?aliasAddress . a ?aliasType . ] }```

For the Address, this returns:

?aliasType = <> and
?aliasAddress = <> so we can understand that the original address and the alias address are about a large block with one Address having a first and Last street number and the other having just one number.

How to lodge queries

SPARQL queries, like the above, can be put to this GNAF SPARQL service using the methods in the SPARQL Service Description specification. You can:

In all cases, the SPARQL service will return either JSON or RDF Turtle. If using the HTML form, you will get the result back in the Result section of the form. If POSTing a query, you will get the result back as an HTTP response.