【问题标题】:Wikidata get all properties of an item with unitsWikidata 获取具有单位的项目的所有属性
【发布时间】:2022-01-01 01:21:29
【问题描述】:

我们正在创建一个应用程序,它使用来自 Wikidata 服务的数据和 Sparql 查询。 基本任务是获取项目的所有属性以及相应的单位和精度。

有一个很好的查询示例here,但它缺少有关单位和精度的数据。 我们在此示例中添加了一些详细信息,但单位仅适用于特定属性 P2102。

所以问题是 - 如何在这样的 Sparql 通用查询中使用非特定属性(即通用属性,与下面示例中的特定 p:P2102、ps:P2102 或 psv:P2102 不同)?

这是我们的查询示例:

SELECT ?wd ?wdLabel ?wdDescription ?ps_ ?ps_Label ?ps_Description ?wdpq ?wdpqLabel ?wdpqDescription ?pq_ ?pq_Label ?pq_Description ?bpUnit ?bpUnitLabel {
  VALUES (?itm) {(wd:Q407225)}
  
  ?itm ?p ?statement .
  ?statement ?ps ?ps_ .
  
  ?wd wikibase:claim ?p.
  ?wd wikibase:statementProperty ?ps.
  
  OPTIONAL {
  ?statement ?pq ?pq_ .
  ?wdpq wikibase:qualifier ?pq .
   
   ?itm p:P2102 [  # -- custom property unit
          ps:P2102 ?bp ;
          psv:P2102/wikibase:quantityUnit  ?bpUnit
        ].
  }  
  
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} 
ORDER BY ?wd ?statement ?ps_

【问题讨论】:

  • 您可以通过属性限定符节点获取单位:
  • SELECT ?wd ?wdLabel ?wdDescription ?ps_ ?ps_Label ?ps_Description ?wdpq ?wdpqLabel ?wdpqDescription ?pq_ ?pq_Label ?pq_Description ?pq_unit ?pq_unitLabel{ VALUES (?itm) {(wd:Q407225)} VALUES ?wd {wd:P2119} ?itm ?p ?statement . ?statement ?ps ?ps_ . ?wd wikibase:claim ?p. ?wd wikibase:statementProperty ?ps. OPTIONAL { ?statement ?pq ?pq_ . ?wdpq wikibase:qualifier ?pq . ?wdpq wikibase:qualifierValue ?pqv . OPTIONAL {?statement ?pqv [wikibase:quantityUnit ?pq_unit]} } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } ORDER BY ?wd ?statement ?ps_

标签: generics properties sparql wikidata


【解决方案1】:
SELECT ?wd ?wdLabel ?wdDescription ?ps_ ?ps_Label ?ps_Description ?wdpq ?wdpqLabel 
       ?wdpqDescription ?pq_ ?pq_Label ?pq_Description ?pq_unit ?pq_unitLabel {  
    VALUES ?itm { wd:Q407225 } 
    VALUES ?wd { wd:P2119 } 
    ?itm ?p ?statement .  
    ?statement ?ps ?ps_ .   
    ?wd wikibase:claim ?p.   
    ?wd wikibase:statementProperty ?ps.   
    OPTIONAL {   
        ?statement ?pq ?pq_ .   
        ?wdpq wikibase:qualifier ?pq .   
        ?wdpq wikibase:qualifierValue ?pqv .   
        OPTIONAL { ?statement ?pqv [wikibase:quantityUnit ?pq_unit] } 
    } 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } 
} ORDER BY ?wd ?statement ?ps_

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多