sparqlmediawikimediawiki-apiwikidatawikimedia-commons

Wikimedia Commons: Get names of sub-categories (using SPARQL or MediaWiki API)


Given a specific category (i.e. https://commons.wikimedia.org/wiki/Category:Motorcycles) I want to get names of all sub-categories recursively, either in SPARQL:

SELECT ?category ?entityLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  #get sub categories of category wd:Q7025402
}
LIMIT 10000

or using MediaWiki API:

https://commons.wikimedia.org/w/api.php?{get all subcategories of Category:Motorcycles}

Is there a way to do this?


Solution

  • SPARQL

    As of July 2018, the structure of Wikimedia Commons categories is not covered by Wikidata:

    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

    Not possible, see T37402.

    Alternatives

    Use the PetScan tool: