0

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.

6
  • 1
    And you couldn't figure out why the parsing error occurs? The prefixed form of categories doesn't work with an additional colon, i.e. r:Category:American_atheists. is invalid. Either you use the full URI <http://dbpedia.org/resources/Category:American_atheists> you use an additional prefix for the categories, usually it's PREFIX dbc: <http://dbpedia.org/resources/Category:> and then write dbc:American_atheists Commented Jan 28, 2018 at 13:04
  • 1
    The screenshot is from a textbook, yes? So if this is some kind of exercise, the wrong prefix of book is either a typo or part of the exercise to demonstrate how important using the correct prefix is. Commented Jan 28, 2018 at 13:32
  • 1
    Please consider changing the title of your question. All questions tagged #SPARQL could be generalised with the current title. Commented Jan 28, 2018 at 16:11
  • 1
    Besides the syntax error with the prefix, you have two other issues that cause the empty query. 1) it must be http://dbpedia.org/resource/ 2) it must be rdf:type Commented Jan 29, 2018 at 3:17
  • 1
    For correctness, yes. Or you can use the Turtle shortcut a, i.e. ?s a o:Book . Commented Jan 29, 2018 at 11:24

1 Answer 1

3

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 .
}
Sign up to request clarification or add additional context in comments.

9 Comments

Thank you! I did not know that. What about the prefix of Book. This causes that you won't get any output (even with proper syntax now), right ?
@CarleB.Navy Correct
o:type is for sure the wrong relation, it must be rdf:type.
@Sentry No, that's not correct. The prefix for Book is correct, but not for the type relation
@AntoineZimmermann Can you please fix this: o:type -> rdf:type and http://dbpedia.org/resources/ -> http://dbpedia.org/resource/
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.