如何使用其标签查询Wikidata项目?

fat*_*afa 7 sparql wikidata

如何查询维基数据以获取标签包含单词的所有项目?我尝试了这个,但没有奏效; 它什么也没找到.

SELECT ?item ?itemLabel WHERE {
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en".
    ?item rdfs:label ?itemLabel.  
  }
FILTER(CONTAINS(LCASE(?itemLabel), "keyword"))
}
LIMIT 1000
Run Code Online (Sandbox Code Playgroud)

小智 6

根据您的问题和提供的有用评论,我最终得到了这个查询

SELECT ?item ?itemLabel
WHERE { 
  ?item rdfs:label ?itemLabel. 
  FILTER(CONTAINS(LCASE(?itemLabel), "city"@en)). 
} limit 10
Run Code Online (Sandbox Code Playgroud)

我得到了那些结果

item          itemLabel
wd:Q515       city
wd:Q7930989   city
wd:Q15253706  city
wd:Q532039    The Eternal City
wd:Q1969820   The Eternal City
wd:Q3986838   The Eternal City
wd:Q7732543   The Eternal City
wd:Q7737016   The Golden City
wd:Q5119      capital city
wd:Q1555      Guatemala City
Run Code Online (Sandbox Code Playgroud)

试试吧

  • 只是更新,在大多数情况下,此查询会因超时异常而终止(对于其他标签) (4认同)

Ale*_*xan 5

是的,您可以按标签搜索,例如:

SELECT distinct ?item ?itemLabel ?itemDescription WHERE{  
  ?item ?label "Something"@en.  
  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}
Run Code Online (Sandbox Code Playgroud)

查询页面上看到它.

  • 这个答案在 2022 年有效。已接受的答案则不然。 (3认同)