Wikidata Query Service/Categories


Wikidata Query Service also provides access to category graph of all public wikis (except labswiki and labtestwiki).

Currently, the data is updated from the latest weekly dump. Updates happen each Monday.

Accessing the data[edit]

The data is stored in the Blazegraph database in categories namespace. Currently, there is no GUI to access the category data, but SPARQL queries can be made against the namespace by using This SPARQL endpoint works in the same way as the main WDQS SPARQL endpoint.

Note that while each wiki has its own data set, they are all stored in the same namespace.

Example query, providing subcategories of category Ducks on English Wikipedia:

PREFIX gas: <>
prefix mediawiki: <> 

SERVICE gas:service {
     gas:program gas:gasClass "" .
     gas:program gas:linkType mediawiki:isInCategory .
     gas:program gas:traversalDirection "Reverse" .
     gas:program gas:in <>. # one or more times, specifies the initial frontier.
     gas:program gas:out ?out . # exactly once - will be bound to the visited vertices.
     gas:program gas:out1 ?depth . # exactly once - will be bound to the depth of the visited vertices.
     gas:program gas:maxIterations 8 . # optional limit on breadth first expansion.
} ORDER BY ASC(?depth)

Try it!

This query would not work with default GUI! For now, you will have to run it manually against the SPARQL endpoint above. The dataset includes only categories and not pages belonging to categories (the latter would be much bigger data set).

Simpler query[edit]

Simpler form of the query above can be accessed with mediawiki:categoryTree service:

SELECT ?out ?depth WHERE {
  SERVICE mediawiki:categoryTree {
    bd:serviceParam mediawiki:start <> .
    bd:serviceParam mediawiki:direction "Reverse" .
    bd:serviceParam mediawiki:depth 5 .
} ORDER BY ASC(?depth)

Try it!

run it manually

This query produces three output values:

  • ?out — the category found
  • ?depth — the depth for the category
  • ?predecessor — the parent category

Data format[edit]

The data about category describe its URL and the name, e.g.

      <> a mediawiki:Category ; 
            rdfs:label "Test" ;
            mediawiki:pages "74"^^xsd:integer ;
            mediawiki:subcategories "19"^^xsd:integer .

Links between categories are represented as mediawiki:isInCategory relationship, e.g.:

     <> mediawiki:isInCategory <>

Hidden categories have class mediawiki:HiddenCategory.


Prefix mediawiki: is defined as Full ontology can be found at

Dump header[edit]

Dump header contains information about the dump, e.g.:

    <> a schema:Dataset,
         owl:Ontology ;
         cc:license <> ;
         schema:softwareVersion "1.0" ;
         schema:dateModified "2017-09-09T20:00:05Z"^^xsd:dateTime ;
         schema:isPartOf <> ;
         owl:imports <> .

Data dumps[edit]

Data dumps are stored in Full dumps are performed weekly. Each wiki has its own dump file. stores timestamps of the last dump performed.


To update categories, the following can be used:

  1. Create categories namespace: bash categories
  2. Load data: bash categories

Adding wikis[edit]

For now, if you want some wiki added, please comment on the talk page. 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.