WIkidata:获取维基数据查询结果中的多个参与者
WIkidata: Getting multiple participants in Wikidata query result
提问:大家好。我从维基数据示例页面找到了一个示例脚本,
但在结果中,每个案例都只显示一个参与者,而大多数案例都有很多参与者。有没有办法显示所有参与者的标签?我不明白为什么(以及如何)只选择一个出现。
SELECT distinct ?race ?raceLabel ?musherLabel
WHERE
{
{ ?race wdt:P31/wdt:P279* wd:Q1968664 . }
UNION { ?race wdt:P31/wdt:P641* wd:Q1968664 . }
?race p:P710 ?musherS . #here we have a full statement, not a value
?musherS ps:P710 ?musher . #here we get the value
FILTER NOT EXISTS { ?musherS pq:P1352 ?rank }
FILTER NOT EXISTS { ?musherS pq:P793 ?event }
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" }
}
ORDER BY ?raceLabel
编辑:
这里 (https://www.wikidata.org/wiki/Help:Qualifiers) 我读到:
For multiple values
Example of a statement consisting of multiple values for one property
Wikidata allows for items to have multiple values per property. For certain statements—such as the children of a person or the official languages of a country—it is perfectly reasonable to have multiple values which may not be qualified in any way.
However, it is also possible for items to have statements with multiple values when only really one value is expected for the property. When an item ideally should have only one value—for example, the population of a city—but has multiple values, then qualifiers should be used in order to indicate further information about the values, such as when the values date from, how they were determined, what exactly they refer to, and so on.
那么这是否意味着没有办法只获取它们(标签值)?
对于每场比赛的单行,您必须结合使用 group by
和聚合函数 group_concat
。
查询:
SELECT distinct ?race ?raceLabel (group_concat(?musherLabel; separator="; ") as ?mushers)
WHERE
{
{ ?race wdt:P31/wdt:P279* wd:Q1968664 . }
UNION
{ ?race wdt:P31/wdt:P641* wd:Q1968664 . }
?race p:P710 ?musherS . #here we have a full statement, not a value
?musherS ps:P710 ?musher . #here we get the value
FILTER NOT EXISTS { ?musherS pq:P1352 ?rank }
FILTER NOT EXISTS { ?musherS pq:P793 ?event }
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?musher rdfs:label ?musherLabel .
?race rdfs:label ?raceLabel .
}
}
GROUP BY ?race ?raceLabel
ORDER BY ?raceLabel
输出:
+------------------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| race | raceLabel | mushers |
+------------------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| http://www.wikidata.org/entity/Q19361352 | Q19361352 | Brett Bruggeman; Brett Bruggeman; Brett Bruggeman; Brett Bruggeman; Bryce Mumford; Bryce Mumford; Bryce Mumford; Bryce Mumford |
| http://www.wikidata.org/entity/Q18577453 | 1993 Iditarod | Beverly Masek |
| http://www.wikidata.org/entity/Q18577456 | 1996 Iditarod | Rick Swenson |
| http://www.wikidata.org/entity/Q23014078 | 2016 Iditarod | Robert Redington; Hans Gatt; Anna Berington; DeeDee Jonrowe; Noah Burmeister; Ed Stielstra; Ken Anderson; Tim Pappas; Ellen Halverson; Jodi Bailey; Jeff King; Brent Sass; Becca Moore; Robert Bundtzen; Karin Hendrickson; Sigrid Ekran; Melissa Owens; Rob Cooke; Scott Smith; Kim Franklin; Elliot Anderson; Scott Janssen; Paige Drobny; Ketil Reitan; Justin Savidis; Aliy Zirkle; Cim Smyth; Dag Torulf Olsen; Linwood Fiedler; Kristin Bacon; Monica Zappa; Billy Snodgrass; Tore Albrigtsen; Mats Pettersson; Kristin Knight Pace; Cindy Gallea; Ray Redington; Katherine Keith; James Volek; Joar Leifseth Ulsom; Jim Lanier; Martin Koenig; Ryne Olson; Nathan Schroeder; Hugh Neff; Tom Jamgochian; Larry Daugherty; Lisbet Norris; Zoya DeNure; Ralph Johannesen; Allen Moore; Michael Williams; Sarah Stokey; Rick Casillo; John Baker; Paul Gebhardt; Dallas Seavey; Mary Helwig; Michelle Phillips; Martin Buser; Kristy Berington; Jan Steves; Ryan Redington; Trent Herbst; Jason Campeau; Alan Eischens; Mitch Seavey; Wade Marrs; Richie Diehl; Nicolas Petit; Charley Bejna; Patrick Beall; Lance Mackey; Robert Sørlie; Jessie Royer; Miriam Osredkar; Kelly Maixner; Noah Pereira; Travis Beals; Geir Idar Hjelvik; Matthew Failor; Peter Kaiser; Lars Monsen; Jason Mackey; Cody Strathe |
| http://www.wikidata.org/entity/Q22093610 | 2016 Kuskokwim 300 | Pato Geron |
+------------------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
提问:大家好。我从维基数据示例页面找到了一个示例脚本, 但在结果中,每个案例都只显示一个参与者,而大多数案例都有很多参与者。有没有办法显示所有参与者的标签?我不明白为什么(以及如何)只选择一个出现。
SELECT distinct ?race ?raceLabel ?musherLabel
WHERE
{
{ ?race wdt:P31/wdt:P279* wd:Q1968664 . }
UNION { ?race wdt:P31/wdt:P641* wd:Q1968664 . }
?race p:P710 ?musherS . #here we have a full statement, not a value
?musherS ps:P710 ?musher . #here we get the value
FILTER NOT EXISTS { ?musherS pq:P1352 ?rank }
FILTER NOT EXISTS { ?musherS pq:P793 ?event }
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" }
}
ORDER BY ?raceLabel
编辑:
这里 (https://www.wikidata.org/wiki/Help:Qualifiers) 我读到:
For multiple values
Example of a statement consisting of multiple values for one property Wikidata allows for items to have multiple values per property. For certain statements—such as the children of a person or the official languages of a country—it is perfectly reasonable to have multiple values which may not be qualified in any way.
However, it is also possible for items to have statements with multiple values when only really one value is expected for the property. When an item ideally should have only one value—for example, the population of a city—but has multiple values, then qualifiers should be used in order to indicate further information about the values, such as when the values date from, how they were determined, what exactly they refer to, and so on.
那么这是否意味着没有办法只获取它们(标签值)?
对于每场比赛的单行,您必须结合使用 group by
和聚合函数 group_concat
。
查询:
SELECT distinct ?race ?raceLabel (group_concat(?musherLabel; separator="; ") as ?mushers)
WHERE
{
{ ?race wdt:P31/wdt:P279* wd:Q1968664 . }
UNION
{ ?race wdt:P31/wdt:P641* wd:Q1968664 . }
?race p:P710 ?musherS . #here we have a full statement, not a value
?musherS ps:P710 ?musher . #here we get the value
FILTER NOT EXISTS { ?musherS pq:P1352 ?rank }
FILTER NOT EXISTS { ?musherS pq:P793 ?event }
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?musher rdfs:label ?musherLabel .
?race rdfs:label ?raceLabel .
}
}
GROUP BY ?race ?raceLabel
ORDER BY ?raceLabel
输出:
+------------------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| race | raceLabel | mushers |
+------------------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| http://www.wikidata.org/entity/Q19361352 | Q19361352 | Brett Bruggeman; Brett Bruggeman; Brett Bruggeman; Brett Bruggeman; Bryce Mumford; Bryce Mumford; Bryce Mumford; Bryce Mumford |
| http://www.wikidata.org/entity/Q18577453 | 1993 Iditarod | Beverly Masek |
| http://www.wikidata.org/entity/Q18577456 | 1996 Iditarod | Rick Swenson |
| http://www.wikidata.org/entity/Q23014078 | 2016 Iditarod | Robert Redington; Hans Gatt; Anna Berington; DeeDee Jonrowe; Noah Burmeister; Ed Stielstra; Ken Anderson; Tim Pappas; Ellen Halverson; Jodi Bailey; Jeff King; Brent Sass; Becca Moore; Robert Bundtzen; Karin Hendrickson; Sigrid Ekran; Melissa Owens; Rob Cooke; Scott Smith; Kim Franklin; Elliot Anderson; Scott Janssen; Paige Drobny; Ketil Reitan; Justin Savidis; Aliy Zirkle; Cim Smyth; Dag Torulf Olsen; Linwood Fiedler; Kristin Bacon; Monica Zappa; Billy Snodgrass; Tore Albrigtsen; Mats Pettersson; Kristin Knight Pace; Cindy Gallea; Ray Redington; Katherine Keith; James Volek; Joar Leifseth Ulsom; Jim Lanier; Martin Koenig; Ryne Olson; Nathan Schroeder; Hugh Neff; Tom Jamgochian; Larry Daugherty; Lisbet Norris; Zoya DeNure; Ralph Johannesen; Allen Moore; Michael Williams; Sarah Stokey; Rick Casillo; John Baker; Paul Gebhardt; Dallas Seavey; Mary Helwig; Michelle Phillips; Martin Buser; Kristy Berington; Jan Steves; Ryan Redington; Trent Herbst; Jason Campeau; Alan Eischens; Mitch Seavey; Wade Marrs; Richie Diehl; Nicolas Petit; Charley Bejna; Patrick Beall; Lance Mackey; Robert Sørlie; Jessie Royer; Miriam Osredkar; Kelly Maixner; Noah Pereira; Travis Beals; Geir Idar Hjelvik; Matthew Failor; Peter Kaiser; Lars Monsen; Jason Mackey; Cody Strathe |
| http://www.wikidata.org/entity/Q22093610 | 2016 Kuskokwim 300 | Pato Geron |
+------------------------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+