Covid-19 related queries

Set up the ability to query Wikidata. All results depend on data in Wikidata so should be interpreted in light of the notability criteria, and biases in coverage.

In [1]:
import urllib.parse
from IPython.display import IFrame
baseurl='https://query.wikidata.org/embed.html#'

def wdq(query='',width=800,height=800):
  return IFrame(baseurl+urllib.parse.quote(query), width=width, height=height)

Famous COVID-19 cases

In [2]:
wdq(width=1000,height=1000,query="""
#defaultView:ImageGrid
SELECT ?person ?personLabel ?image WHERE {
   ?person wdt:P1050 wd:Q84263196 .
   ?person wikibase:sitelinks ?sl .
   OPTIONAL { ?person wdt:P18 ?image . }
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
ORDER BY DESC(?sl)
LIMIT 50
""")
Out[2]:

COVID-19 cases age-distribution

In [3]:
wdq(width=1000,height=700,query="""
#defaultView:LineChart
SELECT ?age (COUNT(?person) AS ?count) WHERE {
{
SELECT ?person (SAMPLE(?age) AS ?age)  WHERE {
    ?person wdt:P1050 wd:Q84263196 . 
    OPTIONAL { ?person wdt:P570 ?d }
    ?person wdt:P569 ?dob . BIND(2020-YEAR(?dob) as ?age) 
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
GROUP BY ?person
}
}
GROUP BY ?age
""")
Out[3]:

Famous COVID-19 deaths

In [4]:
wdq(width=1000,height=1000,query="""
#defaultView:ImageGrid
SELECT ?person ?personLabel (SAMPLE(?image) AS ?image) (SAMPLE(?age) AS ?age) (SAMPLE(?d) AS ?d) (SAMPLE(?sl) AS ?sl) WHERE {
 
    ?person wdt:P509 wd:Q84263196 ; wdt:P31 wd:Q5 
    OPTIONAL { ?person wdt:P570 ?d }
    OPTIONAL { ?person wikibase:statements ?st ; wikibase:sitelinks ?sl ; wikibase:identifiers ?ids }
    OPTIONAL { ?person wdt:P569 ?dob ; wdt:P570 ?dod . BIND(YEAR(?dod)-YEAR(?dob) as ?age) }
  
   OPTIONAL { ?person wdt:P18 ?image . }
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
GROUP BY ?person ?personLabel
ORDER BY DESC(?sl)
LIMIT 50
""")
Out[4]:

COVID-19 deaths age-distribution

In [5]:
wdq(width=1000,height=1000,query="""
#defaultView:LineChart
SELECT ?age (COUNT(?person) AS ?count) WHERE {
{
SELECT ?person (SAMPLE(?age) AS ?age)  WHERE {
    ?person wdt:P509 wd:Q84263196 ; wdt:P31 wd:Q5 
    OPTIONAL { ?person wdt:P570 ?d }
    ?person wdt:P569 ?dob ; wdt:P570 ?dod . BIND(YEAR(?dod)-YEAR(?dob) as ?age) 
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
GROUP BY ?person
}
}
GROUP BY ?age
""")
Out[5]:

Occupations of COVID-19 cases

In [11]:
wdq(width=1000,height=800,query="""
#defaultView:BubbleChart
SELECT ?occupation ?occupationLabel (COUNT(*) as ?count) WHERE {
  ?p wdt:P1050 wd:Q84263196 .
  ?p wdt:P106 ?occupation .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
} 
GROUP BY ?occupation ?occupationLabel
ORDER BY DESC(?count)
LIMIT 1000
""")
Out[11]:

Citizenship of COVID-19 cases

In [7]:
wdq(width=1000,height=800,query="""
#defaultView:BubbleChart
SELECT ?citizenship ?citizenshipLabel (COUNT(*) as ?count) WHERE {
  ?p wdt:P1050 wd:Q84263196 .
  ?p wdt:P27 ?citizenship .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
} 
GROUP BY ?citizenship ?citizenshipLabel
ORDER BY DESC(?count) ?citizenshipLabel
LIMIT 1000
""")
Out[7]:

Place of birth of COVID-19 cases - click on a point to find out who it is

In [8]:
wdq(width=1000,height=1000,query="""
#defaultView:Map
SELECT ?person ?personLabel ?birth ?birthLabel ?birthloc WHERE {
   ?person wdt:P1050 wd:Q84263196 .
   ?person wdt:P19 ?birth .
   ?birth wdt:P625 ?birthloc .

   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }  LIMIT 10000
 """)
Out[8]:

Updated chart of the number of infections and deaths caused since the outbreak of SARS-CoV-2, as reported by the World Health Organisation

In [9]:
wdq(width=1000,height=1000,query="""
#defaultView:LineChart
SELECT ?date (MAX(?count) AS ?max_count) ?measureLabel
WHERE {
  BIND(wd:Q81068910 AS ?outbreak).
  {
    BIND(wd:Q166231 AS ?measure).
    ?outbreak p:P1603 ?cases.
    ?cases prov:wasDerivedFrom/pr:P248/wdt:P50 wd:Q7817.
    ?cases pqv:P585/wikibase:timeValue ?date.
    ?cases psv:P1603/wikibase:quantityAmount ?count.
    ?cases psv:P1603/wikibase:quantityAmount ?infection_count.
  } UNION {
    BIND(wd:Q4 AS ?measure).
    ?outbreak p:P1120 ?deaths.
    ?deaths prov:wasDerivedFrom/pr:P248/wdt:P50 wd:Q7817.
    ?deaths pqv:P585/wikibase:timeValue ?date.
    ?deaths psv:P1120/wikibase:quantityAmount ?count.
    ?deaths psv:P1120/wikibase:quantityAmount ?death_count.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?date ?measureLabel
ORDER BY ASC(?date) DESC(?measure)
 """)
Out[9]:
In [ ]: