如何使用SPARQL通过ID获取Wikidata标签? [英] How to get Wikidata labels by ID using SPARQL?
本文介绍了如何使用SPARQL通过ID获取Wikidata标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用SPARQL端点通过ID获取英文或Wikidata中其他语言的标签?
How can I get the labels in English or any other language in Wikidata by ID using SPARQL endpoint?
推荐答案
假设 wd:Q146190 是您的 wikidata实体ID
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT *
WHERE {
wd:Q146190 rdfs:label ?label .
FILTER (langMatches( lang(?label), "EN" ) )
}
LIMIT 1
-
here the link to the live try press on play to run the query then you could download a full JSON and get such a rensponse ..only a trunk copied here:
{ "head": { "vars": [ "label" ] }, "results": { "bindings": [ { "label": { "xml:lang": "ar", "type": "literal", "value": "دوار الشمس الدرني" } }, { "label": { "xml:lang": "az", "type": "literal", "value": "Kökyumrulu günəbaxan" } }, ..etc,etc.
在具有多个ID的响应结果集中为每个实体ID获取标签
在这种情况下,您应该使用标签服务
-
SELECT ?p ?pLabel ?w ?wLabel WHERE { wd:Q30 p:P6/ps:P6 ?p . ?p wdt:P26 ?w . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } }
要使用此服务,请在变量中添加
Label
(即:对于?p
标签,您必须使用?pLabel
然后添加to use this service add
Label
to the variable ( ie: for?p
label you must use?pLabel
then addSERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
到
WHERE
块这篇关于如何使用SPARQL通过ID获取Wikidata标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-
查看全文