query-00642c73d2921d7e539637b18ae2531b

rq turtle/ttl

(32) Maps of Wuhan pneumonia (COVID-19) outbreak locations: layered by level of cases/deaths/CFRNo.32 (2020.02.29T0543 created)

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 bd: <http://www.bigdata.com/rdf#>
# Wuhan pneumonia (COVID-19) outbreak locations
# querying qualifier
# calculate variables by BIND
# viewed as map of outbreak locations, layered by ?case_level (replaceable by ?death_level or ?CFR_level)
# also viewable as table and image grid
#defaultView:Map{"layer":"?case_level"}
SELECT ?outbreak ?outbreakLabel ?map ?coord ?cases ?case_level ?deaths ?death_level ?CFR ?CFR_level ?start_time ?end_time
WHERE {
  # ?outbreak's "instance of" (P31) statement is ?x
  ?outbreak p:P31 ?x.
  # ?x's value is ?y
  ?x ps:P31 ?y;
     # the value of ?x's qualifier "of" (P642) is COVID-19 (Q84263196)
     pq:P642 wd:Q84263196.
  # ?y is any subclass of (P279*) disease outbreak (Q3241045)
  ### Note: So ?y can be disease outbreak (Q3241045), epidemic (Q44512, subclass of disease outbreak), or pandemic (Q12184, subclass of epidemic). 
  ?y wdt:P279* wd:Q3241045
  # optional: show ?outbreak's distribution map (P1846) as ?map
  OPTIONAL {?outbreak wdt:P1846 ?map}
  # optional: show ?outbreak's coordinate location (P625) as ?coord
  OPTIONAL {?outbreak wdt:P625 ?coord}
  # optional: show ?outbreak's number of cases (P1603) as ?cases
  OPTIONAL {?outbreak wdt:P1603 ?cases}
  # use IF to classify numbers of cases into different levels, and bind the levels as ?case_level
  ### Note: Shown as "10^n (n1-n2)", not just "n1-n2", because, when shown as "n1-n2",
  ### if using thousand separator (e.g., "1,000-9,999"), numbers with and without thousand separator cannot be ordered correctly by "ORDER BY", and
  ### if not using thousand separator (e.g., "1000-9999"), it will be difficult to recognize big number (e.g., 1000000).
  BIND(IF((?cases=0), "0", IF((?cases<10), "10^0 (1-9)", IF((?cases<100), "10^1 (10-99)", IF((?cases<1000), "10^2 (100-999)", IF((?cases<10000), "10^3 (1,000-9,999)", IF((?cases<100000), "10^4 (10,000-99,999)", IF((?cases<1000000), "10^5 (100,000-999,999)", ">=10^6 (1,000,000)" ))))))) AS ?case_level)
  # optional: show ?outbreak's number of deaths (P1120) as ?deaths
  OPTIONAL {?outbreak wdt:P1120 ?deaths}
  # use IF to classify numbers of deaths into different levels, and bind the levels as ?death_level
  BIND(IF((?deaths=0), "0", IF((?deaths<10), "10^0 (1-9)", IF((?deaths<100), "10^1 (10-99)", IF((?deaths<1000), "10^2 (100-999)", IF((?deaths<10000), "10^3 (1,000-9,999)", ">=10^4 (10,000)" ))))) AS ?death_level)
  # bind the quotient of "?deaths divided by ?cases" as ?CFR (case fatality rate)
  ### Note: Got to know how to calculate variables
  BIND (?deaths / ?cases AS ?CFR)
  # use IF to classify case fatality rates into different levels, and bind the levels as ?CFR_level
  BIND(IF((?CFR>=0.1), "10^-1 [10%,100%]", IF((?CFR>=0.01), "10^-2 [1%,10%)", IF((?CFR>=0.001), "10^-3 [0.1%,1%)", IF((?CFR>=0.0001), "10^-4 [0.01%,0.1%)", IF((?CFR=0), "0", ">0, <10^-4 (0%, 0.01%)" ))))) AS ?CFR_level)
  # optional: show ?outbreak's start time (P580) as ?start_time
  OPTIONAL {?outbreak wdt:P580 ?start_time}
  # optional: show ?outbreak's end time (P582) as ?end_time
  OPTIONAL {?outbreak wdt:P582 ?end_time}
  # show label in auto language as default, and English when no default label exists
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
# order layer by ?case_level (replaceable by ?death_level or ?CFR_level)
ORDER BY ?case_level

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v10("?CFR"):::projected v11("?CFR_level"):::projected v8("?case_level"):::projected v7("?cases"):::projected v6("?coord"):::projected v9("?death_level"):::projected v8("?deaths"):::projected v13("?end_time"):::projected v5("?map"):::projected v2("?outbreak"):::projected v12("?start_time"):::projected v3("?x") v4("?y") c4(["wd:Q84263196"]):::iri c6(["wd:Q3241045"]):::iri c14(["bd:serviceParam"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal v2 --"p:P31"--> v3 v3 --"p:statement/P31"--> v4 v3 --"p:qualifier/P642"--> c4 v4 --"p:direct/P279"--> c6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P1846".-> v5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P625".-> v6 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P1603".-> v7 end bind0[/"if(?cases = '0^^xsd:integer','0',if(?cases < '10^^xsd:integer','10^0 (1-9)',if(?cases < '100^^xsd:integer','10^1 (10-99)',if(?cases < '1000^^xsd:integer','10^2 (100-999)',if(?cases < '10000^^xsd:integer','10^3 (1,000-9,999)',if(?cases < '100000^^xsd:integer','10^4 (10,000-99,999)',if(?cases < '1000000^^xsd:integer','10^5 (100,000-999,999)','>=10^6 (1,000,000)')))))))"/] v7 --o bind0 bind0 --as--o v8 subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P1120".-> v8 end bind1[/"if(?deaths = '0^^xsd:integer','0',if(?deaths < '10^^xsd:integer','10^0 (1-9)',if(?deaths < '100^^xsd:integer','10^1 (10-99)',if(?deaths < '1000^^xsd:integer','10^2 (100-999)',if(?deaths < '10000^^xsd:integer','10^3 (1,000-9,999)','>=10^4 (10,000)')))))"/] v8 --o bind1 bind1 --as--o v9 bind2[/"?deaths / ?cases"/] v8 --o bind2 v7 --o bind2 bind2 --as--o v10 bind3[/"if(?CFR >= '0.1^^xsd:decimal','10^-1 #91;10%,100%#93;',if(?CFR >= '0.01^^xsd:decimal','10^-2 #91;1%,10%)',if(?CFR >= '0.001^^xsd:decimal','10^-3 #91;0.1%,1%)',if(?CFR >= '0.0001^^xsd:decimal','10^-4 #91;0.01%,0.1%)',if(?CFR = '0^^xsd:integer','0','>0, <10^-4 (0%, 0.01%)')))))"/] v10 --o bind3 bind3 --as--o v11 subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P580".-> v12 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P582".-> v13 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end