How to build correct SPARQL Query

廉价感情. 提交于 2019-12-11 01:06:28

问题


I need to get all players who have ever played for football team using SPARQL query and dbpedia.org

I can get current team members using http://dbpedia.org/sparql and this query:

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 ?


回答1:


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

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 (i.e., things that have a dbpedia-owl:team property, but that aren't players). Similarly, adding dbpedia-owl:wikiPageID [] ensures that the results are things that exist as articles. 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. (Note that Ryan Giggs has, e.g., dbpedia-owl:careerStation dbpedia:Ryan_Giggs__1.)



来源:https://stackoverflow.com/questions/27721834/how-to-build-correct-sparql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!