wikidata获取带有标签和项目值的所有属性 [英] wikidata get all properties with labels and values of an item

查看:259
本文介绍了wikidata获取带有标签和项目值的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我如何才能提取所有属性,并且在那里最好也可以通过SPARQL从wikidata提取网页上呈现的相应标签。

My question is how I can extract all properties and there respective labels that are also rendered on the webpage from wikidata preferably over SPARQL.

例如 Google 条目在wikidata上。对于属性P414(证券交易所)或P159,有子属性,例如P969(位于街道地址)。实际上,一旦您查询,它们就会显示出来 wbgetentities 作为限定词。 wbgetentities 的问题是缺少标签。我通过以下SPARQL查询获得了所需的输出(例如 wdt:P17 => country =>美利坚合众国):

Take for example the Google entry on wikidata. For the property P414 (stock exchange) or P159 there are subproperties like P969 (located at street address). They actually show up once you query wbgetentities as qualifieres. The problem with wbgetentities is that the labels are missing. I get the desired output (e.g. wdt:P17 => country => United States of America) with the following SPARQL query:

SELECT ?prop_id ?prop_label ?prop_val_label WHERE {
  VALUES (?company) {
    (wd:Q95)
  }
  ?company ?prop_id ?company_item.
  ?wd wikibase:directClaim ?prop_id.
  ?wd rdfs:label ?prop_label.
  OPTIONAL {
    ?company_item rdfs:label ?prop_val.
    FILTER((LANG(?prop_val)) = "en")
  }
  BIND(COALESCE(?prop_val, ?companyItem) AS ?prop_val_label)
  FILTER((LANG(?prop_label)) = "en")
}

但是缺少这些子属性因为他们没有直接索赔。要提取单个语句限定符,我可以执行以下操作:

But those "subproperties" are missing because they are not under direct claims. To extract a single statements qualifier I can do:

SELECT ?company ?hq ?country WHERE {
  wd:Q95 p:P159 ?company.
  OPTIONAL {
    ?company ps:P159 ?hq.
    ?company pq:P17 ?country. 
  }
}

但是问题是是否有一种合并的方法

But the question is if there is a way to combine everything to one query?

推荐答案

Wikidata数据模型上的有用链接:

Useful links on the Wikidata data model:

  • RDF dump format
  • Wikidata qualifiers, references and ranks
  • Help:qualifiers

您的查询应为以下类型:

Your query should be of this kind:

SELECT ?wdLabel ?ps_Label ?wdpqLabel ?pq_Label {
  VALUES (?company) {(wd:Q95)}

  ?company ?p ?statement .
  ?statement ?ps ?ps_ .

  ?wd wikibase:claim ?p.
  ?wd wikibase:statementProperty ?ps.

  OPTIONAL {
  ?statement ?pq ?pq_ .
  ?wdpq wikibase:qualifier ?pq .
  }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} ORDER BY ?wd ?statement ?ps_

尝试!

结果中仅包含限定符及其值。既不包括出处引用也不提供值注释(例如时间精度)。如果需要添加它们,请写评论。

Only qualifiers and their values are included in the result. Neither provenance references nor value annotations (e.g. time precision) are included. Please write a comment if you need to add them.

这篇关于wikidata获取带有标签和项目值的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆