sparql - Wikidata SPARQL - 国家及其(仍然存在的)邻国
问题描述
我想从 Wikidata 中使用 SPARQL 查询一个国家的邻居,如下所示:
SELECT ?country ?countryLabel WHERE {
?country wdt:P47 wd:Q183 .
FILTER NOT EXISTS{ ?country wdt:P576 ?date } # don't count dissolved country - at least filters German Democratic Republic
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
我的问题是,例如,在德国邻国的这个例子中,仍然显示了不再存在的国家,例如:
- 丹麦王国或
- 萨尔州。
已经试过了
我已经可以通过FILTER
声明减少数字了。
问题
- 如何使声明减少到9个国家?
- (也可以划分陆地边界和海上边界)
选择
- 在这个 API 上过滤对我来说也很好https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q35
- 与世界上所有国家/地区有邻国的数据库或列表或准备的HashMaps
解决方案
您可以检查类型为wd:Q133346
('border') 或wd:Q12413618
('international border') 的实体:
SELECT ?border ?borderLabel ?country1Label ?country2Label ?isLandBorder ?isMaritimeBorder ?constraint {
VALUES (?country1) {(wd:Q183)}
?border wdt:P31 wd:Q12413618 ;
wdt:P17 ?country1 , ?country2 .
FILTER (?country1 != ?country2)
BIND (EXISTS {?border wdt:P31 wd:Q15104814} AS ?isLandBorder)
BIND (EXISTS {?border wdt:P31 wd:Q3089219} AS ?isMaritimeBorder)
BIND ((?isLandBorder || ?isMaritimeBorder) AS ?constraint)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY ?country1Label
从某种意义上说,记录是重复的:对于阿富汗-乌兹别克斯坦边界,该列表同时包含(?country1=Afganistan,?country2=Uzbekistan)
和(?country1=Uzbekistan,?country2=Afganistan)
。
- 与世界上所有国家/地区有邻国的数据库或列表或准备的HashMaps
推荐阅读
- android - 我无法将图像保存在 android KitKat 的私人文件中
- c++ - 通过文本文件读取数值数据并存储到变量中
- python - 在 Jupyter Lab 文本编辑器的第一行使用 Shift-Enter 运行块
- kubernetes - 为什么 go-micro Kubernetes 插件需要将 pod 注册到注册表?
- angular - 如何在打字稿的Angular2 highcharts中添加鼠标滚轮代码
- php - 如何将 HTML 文件更改为 PHP
- asp.net-core - 如何正确使用 IdentityServer4 的声明?
- security - 安全存储 API 密钥:环境与 JSON
- ruby-on-rails - Rails 5,Postgesql 和按关联分组
- couchdb - 与织物作曲家一起使用沙发数据库时出错