【问题标题】:DBpedia SPARQL career of players having played for a particular teamDBpedia SPARQL 球员为特定球队效力的职业生涯
【发布时间】:2019-03-28 12:38:53
【问题描述】:

我想获取为特定球队效力的球员以及在特定日期之后出生的球员的职业信息。我设法做了以下查询:

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
    

感谢您的帮助!

【问题讨论】:

  • 您想为球队获得球员的所有进球吗?因为你写了 "I only get the years 对应于玩家的年份" - 我想应该是 "I only get the goals 对应玩家的年份” - 我说的对吗?如果没有,你能举个例子吗?
  • 我们以亚历山大·拉卡泽特为例。他曾为 Olympique Lyonnais 效力,并且出生于 1980 年 1 月 1 日之后,因此必须将他考虑在内。对于这位球员,我想拥有所有的职业生涯(在里昂奥林匹克和其他地方)
  • 不确定这是不是你想要的:select ?playerName ?teamName (sum(?_matches) as ?matches) (sum(?_goals) as ?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) &gt; "1980-01-01"^^xsd:date) filter (?team = &lt;http://dbpedia.org/resource/Olympique_Lyonnais&gt; || ?team = &lt;http://dbpedia.org/resource/AS_Monaco_FC&gt; )} group by ?playerName ?teamName order by ?playerName (max(?year))
  • 显然有一个限制,当一个球员在不同的时间段为同一支球队效力时,例如2012 - 20142016 - 2017,上面的查询无法区分

标签: sparql dbpedia


【解决方案1】:

正如 cmets 中所指出的,您必须使用子查询来获取所有为这些球队效力且出生于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多