Shortcuts: WD:WDQ, WD:WDQS, WD:SPARQL
维基数据:SPARQL查询服务
Jump to navigation
Jump to search
Outdated translations are marked like this.
什么是SPARQL
SPARQL(发音为sparkle)是一种RDF查询语言,即数据库的语义查询语言。自2015年9月起,维基数据提供了一个包含强大Web-GUI的SPARQL端点。使用SPARQL,您可以提取任何类型的数据,查询由三元组的逻辑组合组成。
- SPARQL查询服务GUI在这里:https://query.wikidata.org
- SPARQL端点:https://query.wikidata.org/bigdata/namespace/wdq/sparql?query={SPARQL}(部分关于此API端点的手册)
学习SPARQL
帮助门户
其他材料
- SPARQL in 11 minutes (video, English)
- SPARQL Tutorial at the Apache Jena website (English)
- 2016 SPARQL Workshop presented by the Wikimedia Foundation (English)
- Querying Wikidata with SPARQL for Absolute Beginners, 2-hour video tutorial (English)
- Wikidata:SPARQL tutorial (multiple languages)
- Query optimization
- Query limits
{{Item documentation}}
and other generic queries templates
接口
可以发送GET请求到 https://query.wikidata.org/bigdata/namespace/wdq/sparql?query={SPARQL}
(或端点别名https://query.wikidata.org/sparql?query={SPARQL}
)来直接向SPARQL端点提交SPARQL查询。结果默认以XML格式返回,提供查询参数format=json
或Accept: application/sparql-results+json
可要求以JSON格式返回。进一步信息另见 用户手册。访问RDF数据也可通过https://query.wikidata.org/bigdata/ldf
上的Linked Data Fragments[1]接口。
- R package WikidataQueryServiceR查询WDQS SPARQL 端点并返回 data.frames
- R script ([2]) that plots Wikidata content on a world map in R. (Andra Waagmeester, [3])
- Python例子,how to make a plot of causes of death for U.S. Presidents
- 使用SPARQLWrapper库用Python查询WDQS的一个例子: https://people.wikimedia.org/~bearloga/notes/wdqs-python.html
- Apache Jena命令行工具的一个例子。(这很有用,例如应对WDQS UI目前由于解析而无法正确处理的有超过2000行的非常大的SPARQL语句,或者用于编写一批查询的脚本,以便定期运行并通过电子邮件报告结果。)
- R package WikidataQueryServiceR which queries the WDQS SPARQL endpoint and returns data.frames
- R script (https://gist.github.com/andrawaag/2b8c831ab4dd70b16cf2) that plots Wikidata content on a world map in R. (Andra Waagmeester, https://lists.wikimedia.org/pipermail/wikidata/2015-September/007080.html)
- Python example, how to make a plot of causes of death for U.S. Presidents
- An example of using SPARQLWrapper library to query WDQS in Python: https://people.wikimedia.org/~bearloga/notes/wdqs-python.html
- An example using the Apache Jena command line tools. (This is useful e.g. for very large SPARQL statements with +2000 lines which WDQS UI currently cannot handle properly because of the parsing, or e.g., for scripting a batch of queries to run every week (via cron) and report the results by email)
- ttps://wdq2sparql.toolforge.org/w2s.php 转换WDQ(以前的查询维基数据的工具)查询语法到SPARQL(By Stas Malyshev)
- 通过剪切和粘贴查询来生成结果图http://demo.seco.tkk.fi/visu,User:Pyb的一些例子:美国各州的创建日期、某公墓的埋葬数(按年)、2000名百岁老人的出生日期
Wikimedia SPARQL query services
用户友好界面 | Machine's endpoint | 描述 |
---|---|---|
https://query.wikidata.org/sparql
|
Run SPARQL Queries upon the Wikidata Wikibase instance. Run, test, download the data as XML, JSON, CSV, or TSV. Has advanced user-friendly features such as: word hovering to see a term's meaning, code optimization, etc. | |
https://commons-query.wikimedia.org/sparql
|
Run SPARQL Queries upon the Wikimedia Commons Wikibase instance. | |
https://lingualibre.org/sparql
|
Run SPARQL Queries upon the LinguaLibre Wikibase instance. Run, test, download the data as XML, JSON, CSV, or TSV. |
状态
目前資源
- Special:ListDatatypes:涵盖了近似前缀和某些值的解释
- Help:Dates:关于日期的其他说明
- Wikidata:SPARQL query service/Documentation - 有关维基数据SPARQL查询服务文档的集合,基于Diátaxis框架组织
- SPARQL 1.1 W3C建议书
- Blazegraph wiki - Blazegraph是维基数据SPARQL查询服务使用的查询引擎。此wiki提供了有用的见解。