Carle B. Navy
Carle B. Navy

Reputation: 1156

Error handling of SPARQL query with given RDF graph

I have the following RDF graph with prefixes

PREFIX r: <http://dbpedia.org/resources/>
PREFIX o: <http://dbpedia.org/ontology/>

graph

And the query

PREFIX r: <http://dbpedia.org/resources/>
PREFIX o: <http://dbpedia.org/ontology/>

SELECT ?s ?author
WHERE {
   ?s o:type o:Book .
   ?s o:author ?author .
   ?author ?incategory r:Category:American_atheists.
}

I am now wondering what the output would look like. I have tried using https://dbpedia.org/sparql but this results in a parsing error. Is this a proper query anyway ? The graph has the prefix r for Book and the query has o:Book in the triple.

Upvotes: 0

Views: 360

Answers (1)

Antoine Zimmermann
Antoine Zimmermann

Reputation: 5485

The parsing error is due to the colon after r:Category. Colon in abbreviated IRIs can only be used as part of the prefix. This query should work:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX r: <http://dbpedia.org/resource/>
PREFIX o: <http://dbpedia.org/ontology/>

SELECT ?s ?author
WHERE {
  ?s rdf:type o:Book .
  ?s o:author ?author .
  ?author ?incategory <http://dbpedia.org/resource/Category:American_atheists> .
}

Or, if you want a more concise WHERE clause:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX r: <http://dbpedia.org/resource/>
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX c: <http://dbpedia.org/resource/Category:>

SELECT ?s ?author
WHERE {
  ?s rdf:type o:Book .
  ?s o:author ?author .
  ?author ?incategory c:American_atheists .
}

Upvotes: 3

Related Questions