query-7805c3d072f8ea3e9f65513238bece34

rq turtle/ttl

Propertiessubclass of (P279)country (P17)instance of (P31)located in the administrative territorial entity (P131)

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 
?administrativeContainerLabel 
?instanceType
?instanceTypeLabel
(COUNT(DISTINCT ?instance) AS ?instanceCount) 
(GROUP_CONCAT(DISTINCT ?instanceLabelQ;SEPARATOR=" | ") AS ?instances) 

WHERE {
  VALUES ?administrativeContainer {
    wd:Q1370
  }
  VALUES ?level {
    wd:Q13220204
  }
  VALUES ?country {
    wd:Q30 #United States of America
  }
  ?subclassOccurrence wdt:P279 ?level;
                      wdt:P17 ?country.
  OPTIONAL {
    ?instance wdt:P31/wdt:P279* ?subclassOccurrence.

    OPTIONAL {
      ?instance wdt:P131 ?administrativeContainer .
    }
    OPTIONAL {?instance wdt:P31 ?instanceType}
    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 .
    ?administrativeContainer rdfs:label ?administrativeContainerLabel .
    ?instanceType rdfs:label ?instanceTypeLabel .
  }
}
GROUP BY ?subclassOccurrence ?subclassOccurrenceLabel ?country ?countryLabel ?administrativeContainerLabel ?instanceType ?instanceTypeLabel
ORDER BY DESC(?instanceCount)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?administrativeContainer") v12("?administrativeContainerLabel"):::projected v4("?country"):::projected v11("?countryLabel"):::projected v6("?enLabel") v7("?instance"):::projected v14("?instanceCount") v9("?instanceLabelQ"):::projected v8("?instanceType"):::projected v13("?instanceTypeLabel"):::projected v14("?instances") v3("?level") v5("?subclassOccurrence"):::projected v10("?subclassOccurrenceLabel"):::projected a1((" ")) c10(["#91;AUTO_LANGUAGE#93;,en,zh"]):::literal c8(["bd:serviceParam"]):::iri bind0[/VALUES ?administrativeContainer/] bind0-->v2 bind00(["wd:Q1370"]) bind00 --> bind0 bind1[/VALUES ?level/] bind1-->v3 bind10(["wd:Q13220204"]) bind10 --> bind1 bind2[/VALUES ?country/] bind2-->v4 bind20(["wd:Q30"]) bind20 --> bind2 v5 --"wdt:P279"--> v3 v5 --"wdt:P17"--> v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P31".-> a1 a1 --"wdt:P279"--> v5 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P131".-> v2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P31".-> v8 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v7 -."rdfs:label".-> v6 bind3[/"concat(str(?enLabel),' (',substring-after(str(?instance),str('wd:')),')')"/] v6 --o bind3 v7 --o bind3 bind3 --as--o v9 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 v5 --"rdfs:label"--> v10 v4 --"rdfs:label"--> v11 v2 --"rdfs:label"--> v12 v8 --"rdfs:label"--> v13 end bind6[/"count(?instance)"/] v7 --o bind6 bind6 --as--o v14 bind7[/"?instanceLabelQ"/] v9 --o bind7 bind7 --as--o v14