Search code examples
emacssparqldbpedia

Setting correct endpoints for dbpedia in emacs-sparql


I am starting to use emacs sparql-mode to edit and execute my sparql queries in scripts instead of in the browser.

My script, test.sparql, is as follows:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

ENDPOINT <http://dbpedia.org/sparql>

SELECT DISTINCT ?Concept WHERE {
  [] a ?Concept
} LIMIT 5

However, when I execute this with C-c C-c, I keep getting:

HTTP/1.1 405 Not Allowed
Server: nginx/1.4.7
Date: Tue, 15 Apr 2014 14:34:16 GMT
Content-Type: text/html
Content-Length: 172
Connection: keep-alive

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.4.7</center>
</body>
</html>

Or when I change

ENDPOINT <http://dbpedia.org/sparql>

to

ENDPOINT <http://dbpedia.org/>

What is a correct endpoint for access that resembles http://dbpedia.org/snorql/ ? And what modifications do I need to do to return results in JSON?


Solution

  • I haven't used sparql-mode, but endpoint isn't part of the SPARQL syntax. The service keyword is used to indicate federated query. It's described more fully in SPARQL 1.1 Federated Query, and there are examples. I think that your query would be something along the lines of:

    select distinct ?concept where {
      service <http://dbpedia.org/sparql> { 
        [] a ?concept
      }
    }
    limit 5
    

    I'm not familiar with all the details, so I'm not sure about whether the remote endpoint gets the information about the limit 5 or not, so it might be helpful to handle it with a subquery within the service:

    select ?concept where {
      service <http://dbpedia.org/sparql> { 
        select distinct ?concept where {
          [] a ?concept
        }
        limit 5
      }
    }
    

    As I said, I don't have sparql-mode, but I can run that query with Jena's command line sparql tool, and I get the kind of results that one would expect. (You might want to increase that limit, though; the first five results I tend to get are things like:

    -----------------------------------------------------------------------
    | concept                                                             |
    =======================================================================
    | <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>               |
    | <http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat>           |
    | <http://www.openlinksw.com/schemas/virtrdf#QuadStorage>             |
    | <http://www.openlinksw.com/schemas/virtrdf#array-of-QuadMap>        |
    | <http://www.openlinksw.com/schemas/virtrdf#QuadMap>                 |
    | <http://www.openlinksw.com/schemas/virtrdf#array-of-QuadMapFormat>  |
    

    which are not the useful DBpedia classes you're probably expecting.)