query-70dd82aea20b1eb532b842076b414c35

rq turtle/ttl

Subject folders map

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map{"hide": [ "?geoLocation", "?layer", "?count" ], "markercluster": true}
select distinct ?count ?countryLabel ?country (concat(str(?count), ' folders') as ?folderCount) ?pm20Category ?geoLocation ?layer
where {
  # get countries, folder counts and one coordinate value
  { 
    select ?country (count(?item) as ?count) (sample(?coords) as ?geoLocation)
    where {
      ?item wdt:P31 wd:Q91257459 ;
            wdt:P1269 ?country .

      # set default coordinates for items like "world"
      bind("Point(-25 0)"^^geo:wktLiteral as ?defaultCoords)
      optional {
        ?country wdt:P625 ?geoCoords .
      }
      bind(coalesce(?geoCoords, ?defaultCoords) as ?coords)
    }
    group by ?country
  }

  # construct URI for country page access
  ?country p:P8483 ?statement .
  ?statement ps:P8483 ?geoCode ;
             pq:P4390 wd:Q39893449 .
  bind(uri(concat('https://pm20.zbw.eu/category/geo/s/', ?geoCode)) as ?pm20Category)

  # create map layer
  bind(if(?count < 3, "1 - 2 folders",
          if(?count < 51, "3 - 50 folders", "more than 50 folders")) as ?layer)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
order by ?layer

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?coords") v7("?count"):::projected v3("?country"):::projected v4("?defaultCoords") v12("?folderCount") v10("?geoCode") v5("?geoCoords") v8("?geoLocation"):::projected v2("?item") v12("?layer"):::projected v11("?pm20Category"):::projected v9("?statement") c10(["bd:serviceParam"]):::iri c12(["en"]):::literal c2(["wd:Q91257459"]):::iri c8(["wd:Q39893449"]):::iri v2 --"p:direct/P31"--> c2 v2 --"p:direct/P1269"--> v3 bind0[/"sPoint(-25 0)^^<http://www.opengis.net/ont/geosparql#wktLiteral>'"/] bind0 --as--o v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P625".-> v5 end bind1[/"?geoCoords?defaultCoords"/] v5 --o bind1 v4 --o bind1 bind1 --as--o v6 bind4[/"count(?item)"/] v2 --o bind4 bind4 --as--o v7 bind5[/"sample(?coords)"/] v6 --o bind5 bind5 --as--o v8 v3 --"p:P8483"--> v9 v9 --"p:statement/P8483"--> v10 v9 --"p:qualifier/P4390"--> c8 bind6[/"concat('https://pm20.zbw.eu/category/geo/s/',?geoCode)"/] v10 --o bind6 bind6 --as--o v11 bind7[/"if(?count < '3^^xsd:integer','1 - 2 folders',if(?count < '51^^xsd:integer','3 - 50 folders','more than 50 folders'))"/] v7 --o bind7 bind7 --as--o v12 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end bind8[/"concat(str(?count),' folders')"/] v7 --o bind8 bind8 --as--o v12