使用给定的 RDF 图处理 SPARQL 查询的错误

Error handling of SPARQL query with given RDF graph

我有以下带前缀的 RDF 图

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

和查询

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.
}

我现在想知道输出会是什么样子。我试过使用 https://dbpedia.org/sparql 但这会导致解析错误。 这是一个正确的查询吗? 该图的 Book 前缀为 r,查询在三元组中具有 o:Book

解析错误是由于r:Category后面的冒号引起的。缩写 IRI 中的冒号只能用作前缀的一部分。此查询应该有效:

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> .
}

或者,如果您想要更简洁的 WHERE 子句:

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 .
}