SPARQL - 查询 属性 和 return 结果以获得相关 属性

SPARQL - query a property and return results for a related property

我是 SPARQL 的新手,我正在尝试 运行 SPARQL 查询,以便 return 属性 的结果并针对此列出相关 属性.

示例代码为:

SELECT ?player ?position ?club ?goals WHERE {
  ?player a <http://dbpedia.org/ontology/SoccerManager> . filter (contains (str(?player), "Alan_Shearer")) .
  ?player <http://dbpedia.org/ontology/position> ?position .
  ?player <http://dbpedia.org/property/clubs> ?club .
  ?player <http://dbpedia.org/property/goals> ?goals .
}

结果是针对每个俱乐部复制所有目标:

player  position    club    goals
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Southampton_F.C.    23
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Southampton_F.C.    112
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Southampton_F.C.    148
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Newcastle_United_F.C.   23
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Newcastle_United_F.C.   112
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Newcastle_United_F.C.   148
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Blackburn_Rovers_F.C.   23
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Blackburn_Rovers_F.C.   112
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Blackburn_Rovers_F.C.   148

每个俱乐部的目标在数据集中正确关联,所以我想获得的只是各个俱乐部的目标:

player  position    club    goals
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Southampton_F.C.    23
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Newcastle_United_F.C.   112
http://dbpedia.org/resource/Alan_Shearer    http://dbpedia.org/resource/Forward_(association_football)  http://dbpedia.org/resource/Blackburn_Rovers_F.C.   148

但是,我不了解如何在 SPARQL 中执行此操作,非常感谢任何帮助。

注意数据中有一些dbpedia-owl:careerStation 属性值:

dbpedia-owl:careerStation dbpedia:Alan_Shearer__1, dbpedia:Alan_Shearer__2, ...

如果您查看这些属性的值,例如 http://dbpedia.org/page/Alan_Shearer__3,您可以看到 其中一些 有多个目标 属性 .这意味着您可以这样做:

select ?player ?position ?team ?goals {
  values ?player { dbpedia:Alan_Shearer }
  ?player dbpedia-owl:position ?position ;
          dbpedia-owl:careerStation [ dbpedia-owl:team ?team ;
                                      dbpedia-owl:numberOfGoals ?goals ] .
}

SPARQL results

因为不是所有的站都有目标信息,你可能想在这里使用一个可选的来获取站然后目标 if available:

select ?player ?position ?team ?goals {
  values ?player { dbpedia:Alan_Shearer }
  ?player dbpedia-owl:position ?position ;
          dbpedia-owl:careerStation ?station .
  ?station dbpedia-owl:team ?team .
  optional { ?station dbpedia-owl:numberOfGoals ?goals }
}

SPARQL results