DBpedia SPARQL为特定团队效力的球员的职业生涯

时间:2019-03-28 12:38:54

标签: sparql dbpedia

我想获得为特定团队效力且在特定日期之后出生的球员的职业信息。我设法执行以下查询:

select ?playerName ?year ?teamName ?matches ?goals where {
  ?player a dbo:SoccerPlayer ;
            rdfs:label ?playerName ;
            dbo:birthDate ?birthDate ;
            dbo:careerStation ?station .
  ?station dbo:years ?year ;
           dbo:team ?team ;
           dbo:team/rdfs:label ?teamName ;
           dbo:numberOfMatches ?matches ;
           dbo:numberOfGoals ?goals .
  filter (langMatches(lang(?teamName), "EN"))
  filter (xsd:date(?birthDate) > "1980-01-01"^^xsd:date)
  filter (
     ?team = <http://dbpedia.org/resource/Olympique_Lyonnais>
  || ?team = <http://dbpedia.org/resource/AS_Monaco_FC>
  )
}
order by ?playerName ?year

我的问题是:

  • 我只获得与该球员为被过滤的球队实际效力的年份相对应的年份,我希望拥有他的全部职业生涯
  • 有很多行重复了,我不知道为什么
  • 某些行与我的过滤器不对应。示例:

    "Gaëtan Perrin"@en | 2014... | "Olympique Lyonnais Reserves and Academy"@en | 3 | 1
    

谢谢您的帮助!

1 个答案:

答案 0 :(得分:1)

正如评论中指出的那样,您必须使用子查询来获取所有为这些球队效力并在1980年之后出生的球员。在外部查询中,您可以获取他们的所有职业数据:

select ?playerName ?year ?teamName ?matches ?goals where {

# get all players for given teams born after 1980  
{
select distinct ?player {
?player a dbo:SoccerPlayer ;           
        dbo:birthDate ?birthDate ;
        dbo:careerStation/dbo:team ?team 
filter (?team in (dbr:Olympique_Lyonnais, dbr:AS_Monaco_FC))
filter (xsd:date(?birthDate) > "1980-01-01"^^xsd:date)
}
}

# get all their career station data
  ?player a dbo:SoccerPlayer ;
            rdfs:label ?playerName ;
            dbo:birthDate ?birthDate ;
            dbo:careerStation ?station .
  ?station dbo:years ?year ;
           dbo:team ?team ;
           dbo:team/rdfs:label ?teamName ;
           dbo:numberOfMatches ?matches ;
           dbo:numberOfGoals ?goals .
  filter (langMatches(lang(?teamName), "EN"))

}
order by ?playerName ?year