query: SELECT ?item (COUNT(?entity) AS ?count) WHERE {
    BIND(URI("http://www.wikidata.org/entity/Q42") AS ?item)
    ?entity wdt:P31 wd:Q7889.
    OPTIONAL {
      ?property rdf:type wikibase:Property;
        wikibase:propertyType wikibase:ExternalId;
        (wdt:P31/(wdt:P279*)) wd:Q28147643;
        wikibase:directClaim ?wdt.
      ?entity ?wdt ?id.
    }
    FILTER(!(BOUND(?id)))
  }
  GROUP BY ?item