Discovering the version of a SPARQL endpoint

671 views Asked by At

Given a SPARQL endpoint (which can be either SPARQL 1.0 or 1.1), say for example http://pt.dbpedia.org/sparql, how do I find which version of SPARQL it supports?

[One option is to try out a 1.1 feature such as aggregate functions and see it works but I guess there should be a better way to do this].

The SPARQL 1.1 Service Description specification says

SPARQL services made available via the SPARQL Protocol should return a service description document at the service endpoint when dereferenced using the HTTP GET operation without any query parameter strings provided. This service description must be made available in an RDF serialization, may be embedded in (X)HTML by way of RDFa [RDFA], and should use content negotiation [CONNEG] if available in other RDF representations

and further,

3.2.10 sd:supportedLanguage Relates an instance of sd:Service to a SPARQL language (e.g. Query and Update) that it implements. subPropertyOf: sd:feature domain: sd:Service range: sd:Language

3.3.3 sd:Language An instance of sd:Language represents one of the SPARQL languages, including specific configurations providing particular features or extensions. This document defines three instances of sd:Language: sd:SPARQL10Query, sd:SPARQL11Query, and sd:SPARQL11Update. type: rdfs:Class subClassOf: sd:Feature

But when I dereference most of the SPARQL endpoints, they just sends me an HTML SPARQL query editor.

UPDATE: HTML editor issue was because I didn't use proper content negotiation on the endpoint. But now the question is there a good way to differentiate between a SPARQL 1.0 endpoint and a SPARQL 1.1 endpoint that doesn't provide a service description?

There are some work done on discovering and monitoring SPARQL endpoints such as SPARQL Web-Querying Infrastructure: Ready for Action?, Discoverability of SPARQL Endpoints in Linked Open Data but I didn't see a straight-forward way of finding the version.

1

There are 1 answers

2
Joshua Taylor On

The first thing that you should check is that when you're dereferencing the endpoint, you're asking for content in an RDF format, not the text/html, etc., that a web browser would specify by default, and that the endpoint isn't giving you certain outputs based on the user agent, etc. For instance, if you visit the DBpedia endpoint at http://dbpedia.org/sparql, you get an HTML query editor. However, if you request that page with the Accept header set to "application/rdf+xml", you'll get the service description. Without knowing what endpoints you're having trouble with, we can't really be much more help. This should work, but some endpoint doesn't do it, that's not really a technical problem that we can debug, especially if you don't tell us which endpoints you have problems with. Here's what this looks like using curl:

$ curl -H "Accept: application/rdf+xml" http://dbpedia.org/sparql 
<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
        xmlns:sd="http://www.w3.org/ns/sparql-service-description#" >
  <rdf:Description rdf:about="http://dbpedia.org/sparql">
    <rdf:type rdf:resource="http://www.w3.org/ns/sparql-service-description#Service" />
    <sd:endpoint rdf:resource="http://dbpedia.org/sparql" />
    <sd:feature rdf:resource="http://www.w3.org/ns/sparql-service-description#UnionDefaultGraph" />
    <sd:feature rdf:resource="http://www.w3.org/ns/sparql-service-description#DereferencesURIs" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/SPARQL_Results_JSON" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/SPARQL_Results_XML" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/Turtle" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/N-Triples" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/N3" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/RDF_XML" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/SPARQL_Results_CSV" />
    <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/RDFa" />
    <sd:supportedLanguage rdf:resource="http://www.w3.org/ns/sparql-service-description#SPARQL10Query" />
    <sd:url rdf:resource="http://dbpedia.org/sparql" />
  </rdf:Description>

Here's a live version that uses d3's XmlHttpRequest functionality. (I know you can do this without libraries, but I've been using a lot of d3 lately.)

/** 
 * Make a GET request to dbpedia.org/sparql
 * and show the response in a PRE element.
 */
d3.xhr("http://dbpedia.org/sparql")
  .get(function(error,data) {
    console.log(error);
    console.log(data);
    d3.select("body")
      .append("pre")
      .text(data.response);
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>