dbpedia SPARQL 图书搜索查询

dbpedia SPARQL book search query

我正在尝试使用 sparql 搜索检索 dbpedia 的 precedBy 和 followedBy 属性的书名。 例如。 http://dbpedia.org/page/Harry_Potter_and_the_Goblet_of_Fire - 将 return 前后书名的查询。因此,如果我输入书名 'Chamber of Secrets',我会得到 returned 之前和之后的书。

我试过观看一些关于 sparql 的视频,并查看了此处的示例 https://km.aifb.kit.edu/projects/spartiqulator/examples.htm,但似乎无法生成有效的查询。

我试过以下方法,但它会产生语法错误。我不确定如何 link 我试图以正确的方式过滤的属性,例如 rdf: 和 dbp 等

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX res:  <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>


SELECT DISTINCT ?uri  
WHERE {
    ?uri rdf:type dbo:Book .
    ?uri dbp:precededBy res:'Harry Potter and the Chamber of Secrets' .

}

以下运行但没有结果。

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX res:  <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>


SELECT DISTINCT ?uri  
WHERE {
    ?uri rdf:type dbo:Book .
    ?uri dbp:followedBy 'Harry Potter and the Order of the Phoenix' .

}

如果您想知道密室的 preceedBy 和 followedBy,可以使用此查询:

SELECT *
WHERE {
  dbr:Harry_Potter_and_the_Chamber_of_Secrets
    dbp:precededBy ?precededBy;
    dbp:followedBy ?followedBy.
}

请注意名称的格式与维基百科中的格式相同 URL,使用下划线而不是空格。

另请注意,如果一本书没有两者之一,这将 return 没有。您可以使用 OPTIONAL 来解决这个问题。