Search code examples
sparqlwikidata

Why do I get more results for querying all instances of a subclass than for a query on the "parent" class?


According to wikidata, a battle is a subclass of a military operation. Yet, when I query for all instances of military operations I get 699 results, whereas for all battles I get 7399.

Query for Military Operations

SELECT ?label WHERE {
  ?subj wdt:P31* wd:Q645883.
  ?subj rdfs:label ?label.
  FILTER((LANG(?label)) = "en")
}

Query for Battles

SELECT ?label WHERE {
  ?subj wdt:P31* wd:Q178561.
  ?subj rdfs:label ?label.
  FILTER((LANG(?label)) = "en")
}

Military Operation: https://www.wikidata.org/wiki/Q645883

Battle: https://www.wikidata.org/wiki/Q178561


Solution

  • Because your SPARQL query, in particular, the property path, is wrong. Types are connected by subClassOf (wdt:P279), but you're asking for the closure of instance-of relations when using wdt:P31*

    It has to be wdt:P31/wdt:P279*

    See https://www.wikidata.org/wiki/Property:P279 and https://www.wikidata.org/wiki/Property:P31 for the difference.