query-42f86433cd11c5e7514c408653ac7249

rq turtle/ttl

Propertiessubclass of (P279)country (P17)instance of (P31)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?subclassOccurrence ?subclassOccurrenceLabel ?country ?countryLabel (COUNT(DISTINCT ?instance) AS ?instanceCount) (GROUP_CONCAT(?instanceLabelQ;SEPARATOR=" | ") AS ?instances)
WHERE {
  VALUES ?level {
    wd:Q10864048
  }
  ?subclassOccurrence wdt:P279 ?level;
                      wdt:P17 ?country.
  OPTIONAL {
    ?instance wdt:P31 ?subclassOccurrence.
    OPTIONAL {
      ?instance rdfs:label ?enLabel .
      FILTER(LANG(?enLabel)="en")
      BIND(CONCAT(STR(?enLabel), " (", STRAFTER(STR(?instance), STR(wd:)), ")") AS ?instanceLabelQ)
    }
  }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,zh". 
    ?subclassOccurrence rdfs:label ?subclassOccurrenceLabel .
    ?country rdfs:label ?countryLabel .
  }
}
GROUP BY ?subclassOccurrence ?subclassOccurrenceLabel ?country ?countryLabel
ORDER BY DESC(?instanceCount)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?country"):::projected v9("?countryLabel"):::projected v5("?enLabel") v6("?instance"):::projected v10("?instanceCount") v7("?instanceLabelQ"):::projected v10("?instances") v2("?level") v3("?subclassOccurrence"):::projected v8("?subclassOccurrenceLabel"):::projected c9(["#91;AUTO_LANGUAGE#93;,en,zh"]):::literal c7(["bd:serviceParam"]):::iri bind0[/VALUES ?level/] bind0-->v2 bind00(["wd:Q10864048"]) bind00 --> bind0 v3 --"wdt:P279"--> v2 v3 --"wdt:P17"--> v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P31".-> v3 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."rdfs:label".-> v5 bind1[/"concat(str(?enLabel),' (',substring-after(str(?instance),str('wd:')),')')"/] v5 --o bind1 v6 --o bind1 bind1 --as--o v7 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 v3 --"rdfs:label"--> v8 v4 --"rdfs:label"--> v9 end bind4[/"count(?instance)"/] v6 --o bind4 bind4 --as--o v10 bind5[/"?instanceLabelQ"/] v7 --o bind5 bind5 --as--o v10