Wikimedia Commons:获取子类别的名称(使用 SPARQL 或 MediaWiki API)
Wikimedia Commons: Get names of sub-categories (using SPARQL or MediaWiki API)
给定一个特定类别(即 https://commons.wikimedia.org/wiki/Category:Motorcycles)我想递归地获取所有子类别的名称,无论是在 SPARQL 中:
SELECT ?category ?entityLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
#get sub categories of category wd:Q7025402
}
LIMIT 10000
或使用 MediaWiki API:
https://commons.wikimedia.org/w/api.php?{get all subcategories of Category:Motorcycles}
有办法吗?
SPARQL
类别共享资源
Exception is Commons, which has by far the largest set of categories and thus we decided not to cover it for now, until we ensure everything works as planned with smaller data sets.
MediaWiki API
不可能,参见 T37402。
备选方案
使用 PetScan 工具:
API:
https://commons.wikimedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Motorcycles&cmtype=subcat&utf8=1&format=json
SQL:
https://quarry.wmflabs.org/query/28793
(通过 Quarry 工具或如果您有帐户直接使用 on Toolforge)
但只能通过 PetScan 递归或通过 API/SQL 通过查询链手动递归(查询每个类别,其中 subcats 不为 0):
https://commons.wikimedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Motorcycles&gcmtype=subcat&prop=categoryinfo&utf8=1&format=json
https://quarry.wmflabs.org/query/28794
给定一个特定类别(即 https://commons.wikimedia.org/wiki/Category:Motorcycles)我想递归地获取所有子类别的名称,无论是在 SPARQL 中:
SELECT ?category ?entityLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
#get sub categories of category wd:Q7025402
}
LIMIT 10000
或使用 MediaWiki API:
https://commons.wikimedia.org/w/api.php?{get all subcategories of Category:Motorcycles}
有办法吗?
SPARQL
类别共享资源
Exception is Commons, which has by far the largest set of categories and thus we decided not to cover it for now, until we ensure everything works as planned with smaller data sets.
MediaWiki API
不可能,参见 T37402。
备选方案
使用 PetScan 工具:
API:
https://commons.wikimedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Motorcycles&cmtype=subcat&utf8=1&format=json
SQL:
https://quarry.wmflabs.org/query/28793
(通过 Quarry 工具或如果您有帐户直接使用 on Toolforge)
但只能通过 PetScan 递归或通过 API/SQL 通过查询链手动递归(查询每个类别,其中 subcats 不为 0):
https://commons.wikimedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Motorcycles&gcmtype=subcat&prop=categoryinfo&utf8=1&format=json
https://quarry.wmflabs.org/query/28794