如何使用标签查询维基数据项?
How to query Wikidata items using its labels?
如何查询维基数据以获取所有标签包含单词的项目?
我试过了但没用;它什么也没检索到。
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". }
}
在 Query page 上查看。
如上所述,不区分大小写和截断的查询在 SPARQL 查询服务中非常慢。
我在 github 上找到了这个项目:https://github.com/inventaire/entities-search-engine
它设置了一个 ElasticSearch 索引,允许快速查询自动完成等用例。
截至今天(2020 年 6 月),执行此操作的最佳方法似乎是使用这些 CirrusSearch 扩展。以下代码在所有英文标签中进行子字符串搜索,并在 <20 秒内返回 10,000 个结果。我相信它也会搜索别名和描述。
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" )
# … at this point, you have matching ?item(s)
# and can further restrict or use them
# as in any other SPARQL query
# Example: the following restricts the matches
# to college towns (Q1187811) only
?item wdt:P31 wd:Q1187811 .
}
如何查询维基数据以获取所有标签包含单词的项目? 我试过了但没用;它什么也没检索到。
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". }
}
在 Query page 上查看。
如上所述,不区分大小写和截断的查询在 SPARQL 查询服务中非常慢。 我在 github 上找到了这个项目:https://github.com/inventaire/entities-search-engine 它设置了一个 ElasticSearch 索引,允许快速查询自动完成等用例。
截至今天(2020 年 6 月),执行此操作的最佳方法似乎是使用这些 CirrusSearch 扩展。以下代码在所有英文标签中进行子字符串搜索,并在 <20 秒内返回 10,000 个结果。我相信它也会搜索别名和描述。
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" )
# … at this point, you have matching ?item(s)
# and can further restrict or use them
# as in any other SPARQL query
# Example: the following restricts the matches
# to college towns (Q1187811) only
?item wdt:P31 wd:Q1187811 .
}