SPARQL

From OSF Wiki
Jump to: navigation, search
SPARQL endpoint version:
1.1
2
3

The SPARQL Web service is used to send custom SPARQL queries against the OSF Web Service data structure. This is a general purpose querying Web service.

Developers communicate with the SPARQL Web service using the HTTP POST method. You may request one of the following mime types: (1) text/xml, (2) application/rdf+xml, (3) application/rdf+n3, (4) application/sparql-results+xml, (5) application/sparql-results+json or (6) application/json. The content returned by the Web service is serialized using the mime type requested and the data returned depends on the parameters selected.

Version

This documentation page is used for the version 3 of this endpoint. Check at the top of this page to see the documentation pages for the other versions of this endpoint.

Usage

This Web service is intended to be used by content management systems, developers or administrators to manage access to WSF (Web Service Framework) resources (users, datasets, Web services endpoints).

If the requested content type sent to the SPARQL web service endpoint is not "application/sparql-results+xml" nor "application/sparql-results+json", then it means that the web service is used to return complete record descriptions based on a SPARQL search pattern. Only the two SPARQL resultsets serialization formats will return the except SPARQL resultsets.

If the SPARQL endpoint is used to get complete records description based on SPARQL patterns, then the three variables (1) ?s, (2) ?p and (3) ?o variables have to be bound in the SPARQL query, otherwise no result will be returned. Here is an example of a query that match all the records that are muni:County and that have an iron:prefLabel. However, as you can notice in the query, the three variable ?s ?p ?o are bound so that the SPARQL endpoint return the complete record description for the requested content type "application/rdf+xml":

 
SELECT ?s ?p ?o
WHERE
{
  ?s a <http://purl.org/ontology/muni#County> ;
  <http://purl.org/ontology/iron#prefLabel> ?name ;
     ?p ?o .
}
ORDER BY ?s

Optionally, the requester can define a fourth variable (4) ?g to get the dataset location of each returned result in the resultset. This location is defined in the record's description using the dcterms:isPartOf predicate. Here is an example of such a query:

 
SELECT ?s ?p ?o ?g
WHERE
{
  graph ?g
  {
    ?s a <http://purl.org/ontology/muni#County> ;
       <http://purl.org/ontology/iron#prefLabel> ?name ;
       ?p ?o .
  }
}
ORDER BY ?s

Finally the requester can define additional bound variables to get the datatype (?otype) and language (?olang) of the values, and possible reification statements (?rei_s, ?rei_p and ?rei_o) for the triples that defines the records:

 
SELECT ?s ?p ?o ?g (DATATYPE(?o)) AS ?otype (LANG(?o)) AS ?olang ?rei_s ?rei_p ?rei_o
WHERE
{
  {
    graph ?g
    {
      ?s ?p ?o
    }
  }
  UNION
  {
    graph ?g_rei
    {
      ?rei_s <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?s ;
      ?rei_p ?rei_o .
    }
  }  
}
ORDER BY ?s

To comply with the SPARQL protocol, the parameters default-graph-uri and named-graph-uri are supported by the endpoint.

When a query is sent to this SPARQL endpoint, the user has to specify the dataset he wants to query, and he has to have access to it. If the dataset URI is not specified, or if he doesn't have access to it, then an error will be reported by the endpoint.

To specify the dataset he wants to send the query against, the user can specify it via the endpoint parameters dataset, default-graph-uri or named-graph-uri. Also, he can specify it directly within the SPARQL query via the clauses FROM and FROM NAMED.

Note that any SPARQL queries that uses GRAPH clauses will return a 205 error if the SPARQL query is not bound to one or a set of FROM NAMED clauses. This is the only way to ensure that the user will access the data he has access to. If you are a developer, you may want to use the Auth: Lister Web service endpoint to get all the datasets accessible to the user, and then to put all of them into the SPARQL query using the FROM NAMED clause so that you can use the GRAPH clause within your SPARQL queries.

Finally, any SPARUL queries will be dropped by the endpoint, and a 203 error will be returned to the requester.

Web Service Endpoint Information

This section describes the permissions you need in the WSF (Web Service Framework) to send a query to this Web service endpoint, and it describes how to access it.

To access this Web service endpoint you need the proper CRUD (Create, Read, Update and Delete) permissions on a specific graph (dataset) of the WSF. Without the proper permissions on this graph you won't be able to send any queries to the endpoint.

Needed registered CRUD permission:
  • Create: False
  • Read: True
  • Update: False
  • Delete: False

As shown on the graph URI:

  • URI of the dataset where the instance record is indexed

Here is the information needed to communicate with this Web service's endpoint. Descriptions of the parameters are included below.

Note: if a parameter has a default value, the requester can omit it and the default value will be used. Also, some baseline Web services may not offer other values than the default.

HTTP method:
  • POST

Possible "Accept:" HTTP header field values:

  • text/xml (structXML)
  • application/json (structJSON)
  • application/rdf+xml (RDF+XML)
  • application/rdf+n3 (N3/Turtle)
  • application/iron+json (irJSON)
  • application/iron+csv (commON)
  • application/sparql-results+xml (SPARQL resultset in XML)
  • application/sparql-results+json (SPARQL resultset in JSON)

Possible "Accept:" HTTP header field values for a DESCRIBE or a CONSTRUCT SPARQL query:

  • text/rdf+n3 (RDF+N3)
  • application/rdf+xml (RDF+XML)
  • application/rdf+json (RDF+JSON)
  • text/plain (NTRIPLES)

URI:

  • http://[...]/ws/sparql/ ?query=param1&dataset=&limit=&offset=&default-graph-uri=&named-graph-uri=&interface=&version=

URI dynamic parameters description:

Note: All parameters have to be URL-encoded

  • query. The SPARQL query to send to the Web service endpoint
  • dataset. URI referring to a target dataset to query.
  • limit. Limit of the number of results to return in the resultset(max 2000)
  • offset. Offset of the "sub-resultset" from the total resultset of the query
  • default-graph-uri. Dataset to target with the sparql query (optional) -- only used for consistency with the SPARQL protocol
  • named-graph-uri. Dataset to target with the sparql query (optional) -- only used for consistency with the SPARQL protocol
  • interface. Source interface used for this web service query. The interface is a different way to process a query (different algorithms, different data management system, etc. The default interface is 'default'
  • version. (default: 3.0) Version of the interface to query

Available Sources Interfaces

A source interface is a way to process a web service query. Different sources interfaces can be implemented for the same OSF Web Service endpoint. Each interface will process the query differently, but all the queries to the web service endpoint will be the same, at the exception of the interface parameter. Each interface shares the same API (the one defined by the web service endpoint), but their processing may differ (like using different algorithms, using different data management systems, etc.)

This is a list of the core interfaces for this endpoint. Organizations that hosts a OSF Web Service network could create their own interface and make it available to the users. However such private source interface won't be part of this list, but should be publicized by the organization.


Source Interface Name Description
default Default source interface for this OSF Web Service endpoint. This interface implements the default behavior of this OSF Web Service endpoint.

Content Returned

The content returned by the Web service endpoint depends on the "Accept:" parameter sent by the requester. The user can request one of the five supported mime types. The converted content from the input document will be returned by using the requested serialization format.


HTTP Status Codes

Here are the possible HTTP status (error) codes returned by this Web service endpoint.

On error code and the specific error, a different message description can be issued (meaning a different error has been returned).


HTTP 200

Message Description
OK


HTTP 400

ID Level Name Description
WS-SPARQL-200 Warning No query specified for this request No query specified for this request
WS-SPARQL-201 Warning No dataset specified for this request No dataset specified for this request
WS-SPARQL-203 Warning SPARUL not permitted. No SPARUL queries are permitted for this sparql endpoint.
WS-SPARQL-204 Warning CONSTRUCT not permitted. The SPARQL CONSTRUCT clause is not permitted for this sparql endpoint. Please change you mime type if you want to get the resultset in a specific format.
WS-SPARQL-205 Warning GRAPH not permitted without FROM NAMED clauses. The SPARQL GRAPH clause is not permitted for this sparql endpoint. GRAPH clauses are only permitted when you bound your SPARQL query using one, or a series of FROM NAMED clauses.
WS-SPARQL-206 Warning Dataset not accessible. You don' have access to the dataset URI you specified in the dataset parameter of this query.
WS-SPARQL-300 Warning Connection to the sparql endpoint failed Connection to the sparql endpoint failed
WS-SPARQL-301 Notice No instance records found No instance records found for this query
WS-SPARQL-302 Fatal Requested source interface not existing The source interface you requested is not existing for this web service endpoint.
WS-SPARQL-303 Fatal Requested incompatible Source Interface version The version of the source interface you requested is not compatible with the version of the source interface currently hosted on the system. Please make sure that your tool get upgraded for using this current version of the endpoint.
WS-SPARQL-304 Fatal Source Interface's version not compatible with the web service endpoint's The version of the source interface you requested is not compatible with the one of the web service endpoint. Please contact the system administrator such that he updates the source interface to make it compatible with the new endpoint version.

HTTP 403

ID Level Name Description
WS-AUTH-VALIDATION-100 Fatal Unauthorized Request Your request cannot be authorized for this web service call
WS-AUTH-VALIDATION-101 Fatal Unauthorized Request Your request cannot be authorized for this web service call
WS-AUTH-VALIDATION-102 Fatal Couldn't authorize request An internal error occured when we tried to authorize this request
WS-AUTH-VALIDATION-103 Fatal Unauthorized Request Your request cannot be authorized for this user: "---", on this dataset: "---", using this web service endpoint: "---"


HTTP 406

Message Description
Not Acceptable Unacceptable mime type requested


HTTP 500

Message Description
Internal Error