SPARQL查询未提供期望的结果

时间:2019-10-26 20:37:14

标签: sparql dbpedia

我使用以下代码列出了Punk Rock乐队的乐队成员:

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema>

SELECT distinct ?bandname ?bandmembername where {
?band
   foaf:name ?bandname;
   dbo:genre dbr:Punk_Rock.
?bandmember
   dbo:bandMember ?bandmember;
   rdfs:label ?bandmembername.
}

我需要任何Punk_Rock乐队的乐队成员。

1 个答案:

答案 0 :(得分:0)

没有语法错误。

查询中有2个错误。

  1. PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema>应该是PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

  2. dbo:bandMember ?bandmember谓词和对象应该描述?band(具有成员),而不是描述?bandmember的成员)

有了这些修复程序in the query,您应该会看到the results您所希望的-

PREFIX  dbo: <http://dbpedia.org/ontology/>
PREFIX  dbr: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?bandname ?bandmembername 
WHERE
{
  ?band
      foaf:name      ?bandname ;
      dbo:bandMember ?bandmember ;
      dbo:genre      dbr:Punk_Rock .
  ?bandmember 
      rdfs:label     ?bandmembername .
}