简体   繁体   English

如何建立正确的SPARQL查询

[英]How to build correct SPARQL Query

I need to get all players who have ever played for football team using SPARQL query and dbpedia.org 我需要使用SPARQL查询和dbpedia.org获取曾经为足球队效力的所有球员

I can get current team members using http://dbpedia.org/sparql and this query: 我可以使用http://dbpedia.org/sparql和以下查询获取当前的团队成员:

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX p: <http://dbpedia.org/property/>  
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>           
SELECT * WHERE { 
      <http://dbpedia.org/resource/Manchester_United_F.C.> p:name ?player.
      ?player dbpedia-owl:birthPlace ?city;
              dbpedia-owl:birthDate ?dob.
}

How to get all players who have ever played for this football team ? 如何获得曾经为这支足球队效力的所有球员?

I'd use a query like this: 我会使用这样的查询:

select distinct ?player ?birthPlace ?birthDate where {
  ?player dbpedia-owl:team <http://dbpedia.org/resource/Manchester_United_F.C.> ;
          a dbpedia-owl:Person ;
          dbpedia-owl:wikiPageID [] .
  optional { ?player dbpedia-owl:birthPlace ?birthPlace }
  optional { ?player dbpedia-owl:birthDate ?birthDate }
}

SPARQL results SPARQL结果

Using optional ensures that players without listed birthplaces or birthdates can still be included in the results. 使用可选选项可确保没有列出出生地或出生日期的球员仍可包含在结果中。 Using a dbpedia-owl:Person helps remove some "dirty" data (ie, things that have a dbpedia-owl:team property, but that aren't players). 使用dbpedia-owl:owl有助于删除一些“脏”数据(即具有dbpedia-owl:team属性但不是播放器的东西)。 Similarly, adding dbpedia-owl:wikiPageID [] ensures that the results are things that exist as articles. 同样,添加dbpedia-owl:wikiPageID []可确保结果是作为文章存在的事物。 If you don't include that, then you get results like Manchester_United_F.C.__Ryan_Giggs__1 , which appears to be a sort of career station entity. 如果不包括在内,那么您会得到类似Manchester_United_F.C .__ Ryan_Giggs__1的结果,这似乎是一种职业站实体。 (Note that Ryan Giggs has, eg, dbpedia-owl:careerStation dbpedia:Ryan_Giggs__1 .) (请注意, Ryan Giggs具有例如dbpedia-owl:careerStation dbpedia:Ryan_Giggs__1 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM