Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 610
Samantha Avatar asked Nov 22 '25 13:11

Samantha


1 Answers

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:

  • HTML output

  • JSON output

like image 64
Stanislav Kralin Avatar answered Nov 24 '25 06:11

Stanislav Kralin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!