2

如何使用 SPARQL在 Wikidata 查询服务 ( https://query.wikidata.org ) 中获取单位类型和日期精度?

下面是查看挂毯尺寸和开始的示例查询。

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 年代,但在 Query Service 上是 1070 年 1 月 1 日。我查看了文档,但无法弄清楚。

如何获取查询服务的单位和日期精度?

4

1 回答 1

3

在 Wikidata 中以这种方式获取有关语句和单位的信息:

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:秒。

于 2017-09-19T06:44:18.457 回答