如何使用SPARQL在维基数据查询服务(https://query.wikidata.org)中获取单位类型和日期精确度?
下面是查看tapestries的维度和初始化的示例查询。
SELECT ?item ?itemLabel ?height ?width ?inception
WHERE
{
?item wdt:P31 wd:Q184296 .
OPTIONAL {
?item wdt:P2048 ?height .
?item wdt:P2049 ?width .
?item wdt:P571 ?inception .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} LIMIT 1
我在网站上看到,Bayeux Tapestry(https://www.wikidata.org/wiki/Q187483)以米为单位,是在1070年代制作的。但是当我使用查询服务时,我只获得高度和宽度的数字。并且Inception在网站上是1070年代,但是1070年1月1日在查询服务上。我查看了文档,但无法弄清楚。
如何在查询服务上获取单位和日期精度?
答案 0 :(得分:2)
获取有关语句和单位的信息在维基数据中以这种方式运作:
SELECT ?item ?itemLabel
?height ?unitHeightLabel
?width ?unitWidthLabel
?inception ?precisionLabel WHERE {
?item wdt:P31 wd:Q184296 .
OPTIONAL {
?item p:P2048 ?stmnodeHeight . # height
?stmnodeHeight psv:P2048 ?valuenodeHeight.
?valuenodeHeight wikibase:quantityAmount ?height.
?valuenodeHeight wikibase:quantityUnit ?unitHeight.
?item p:P2049 ?stmnodeWidth . # width
?stmnodeWidth psv:P2049 ?valuenodeWidth.
?valuenodeWidth wikibase:quantityAmount ?width.
?valuenodeWidth wikibase:quantityUnit ?unitWidth.
?item p:P571/psv:P571 ?timenode .
?timenode wikibase:timeValue ?inception.
?timenode wikibase:timePrecision ?timeprecision.
# get the label of time precision (by @StanislavKralin)
{
SELECT ?precision (xsd:integer(?precisionDecimal) AS ?timeprecision) {
?precision wdt:P2803 ?precisionDecimal .
}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} LIMIT 1
使用SPARQL 1.1属性路径+ Turtle快捷方式的更紧凑的版本:
SELECT ?item ?itemLabel
?height ?unitHeightLabel
?width ?unitWidthLabel
?inception ?precisionLabel WHERE {
?item wdt:P31 wd:Q184296 .
OPTIONAL {
# height
?item p:P2048/psv:P2048 [ wikibase:quantityAmount ?height ;
wikibase:quantityUnit ?unitHeight ].
# width
?item p:P2049/psv:P2049 [ wikibase:quantityAmount ?width ;
wikibase:quantityUnit ?unitWidth ].
# inception
?item p:P571/psv:P571 [ wikibase:timeValue ?inception;
wikibase:timePrecision ?timeprecision ]
# get the label of time precision (by @StanislavKralin)
{
SELECT ?precision (xsd:integer(?precisionDecimal) AS ?timeprecision) {
?precision wdt:P2803 ?precisionDecimal .
}
}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} LIMIT 1
结果:
+-------------+-----------------+--------+-----------------+-------+----------------+-------------+---------------+
| item | itemLabel | height | unitHeightLabel | width | unitWidthLabel | inception | precisionLabel |
+-------------+-----------------+--------+-----------------+-------+----------------+-------------+---------------+
| wd:Q187483 | Bayeux Tapestry | 0.5 | metre | 68.38 | metre | Jan 1, 1070 | 8 |
+-------------+-----------------+--------+-----------------+-------+----------------+-------------+---------------+
精确度的代码是0亿年,1:亿年,3:百万年,4:十万年,5:一万年,6:千年,7:世纪,8:十年,9:年,10:月,11:日,12:小时,13:分,14:秒。