Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sparql 如何使用其标签查询Wikidata项?_Sparql_Wikidata - Fatal编程技术网

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

Sparql 如何使用其标签查询Wikidata项?,sparql,wikidata,Sparql,Wikidata,如何查询Wikidata以获取标签中包含单词的所有项目? 我试过了,但没有成功;它什么也找不到 SELECT ?item ?itemLabel WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "en". ?item rdfs:label ?itemLabel. } FILTER(CONTAINS(LCASE(?itemLabel), "keyword")) } LIMIT 1000

如何查询Wikidata以获取标签中包含单词的所有项目? 我试过了,但没有成功;它什么也找不到

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

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

SELECT ?item ?itemLabel
WHERE { 
  ?item rdfs:label ?itemLabel. 
  FILTER(CONTAINS(LCASE(?itemLabel), "city"@en)). 
} limit 10
我得到了这些结果

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

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

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". }    
}

如上所述,在SPARQL查询服务中,不区分大小写和截断的查询速度非常慢。 我在github上找到了这个项目:
它建立了一个ElasticSearch索引,允许对自动完成之类的用例进行快速查询。

截至今天2020年6月,最好的方法似乎是使用这些CirruseSearch扩展。以下内容在所有英文标签中进行子字符串搜索,并在wikibase中返回10000个结果:标签?如果没有前缀,很难说出哪里出了问题。前缀wikibase:那么wikibase:语言信息在此数据集中在哪里?如果没有,连接在作为单个SPARQL查询执行的服务部分中显然是空的。。我想如果你把第一个三元组放在服务条款之外,它可能会起作用。我的意思是相反的。我想您应该使用本体图中的标签http://wikiba.se/ontology-1.0.owl 您在SERVICE子句中指定的。而且这个不包含wikibase:language属性,因此您应该将这个放在SERVICE子句之外,而不是另一个。但老实说,你想从你的查询中得到什么还不清楚。特别是,您使用服务wikibase:label指定的图形应该是什么?您对属性使用前缀URI,但可能只需要本体。您在哪里运行查询?为什么不使用SERVICE子句就不能在Wikidata SPARQL端点上执行此操作呢?只是一个更新,在大多数情况下,对于其他标签,此查询会以超时异常终止
SELECT DISTINCT ?item ?label
WHERE
{
  SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:endpoint "www.wikidata.org";
                    wikibase:api "Generator";
                    mwapi:generator "search";
                    mwapi:gsrsearch "inlabel:city"@en;
                    mwapi:gsrlimit "max".
    ?item wikibase:apiOutputItem mwapi:title.
  }
  ?item rdfs:label ?label. FILTER( LANG(?label)="en" )

}