query-383dcd77cf007d70ef28e8a6cc4f4f78

rq turtle/ttl

.on Mastodon and on TwitterOriginally posted

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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/>
#defaultView:LineChart
SELECT ?date ?age ?layer WHERE {
  {
    ?usPresident wdt:P31 wd:Q5;
                 p:P39 [
                   ps:P39 wd:Q11696;
                   pq:P580 ?usPresidentStart
                 ];
                 wdt:P569 ?usPresidentDob.
    BIND(xsd:integer((?usPresidentStart - ?usPresidentDob) / 365.2425) AS ?usPresidentAge)
    BIND(?usPresidentStart AS ?date)
    BIND(?usPresidentAge AS ?age)
    BIND("US president"@en AS ?layer)
  } UNION {
    ?ukPrimeMinister wdt:P31 wd:Q5;
                     p:P39 [
                       ps:P39 wd:Q14211;
                       pq:P580 ?ukPrimeMinisterStart
                     ];
                     wdt:P569 ?ukPrimeMinisterDob.
    BIND(xsd:integer((?ukPrimeMinisterStart - ?ukPrimeMinisterDob) / 365.2425) AS ?ukPrimeMinisterAge)
    BIND(?ukPrimeMinisterStart AS ?date)
    BIND(?ukPrimeMinisterAge AS ?age)
    BIND("UK Prime Minister"@en AS ?layer)
  } UNION {
    wd:Q21 p:P4442 [
      ps:P4442 ?englandMeanAge;
      pq:P585 ?englandMeanAgeTime
    ].
    BIND(?englandMeanAgeTime AS ?date)
    BIND(?englandMeanAge AS ?age)
    BIND("England"@en AS ?layer)
  }
  # FILTER(?date >= "1989"^^xsd:dateTime)
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v14("?age"):::projected v14("?date"):::projected v12("?englandMeanAge") v13("?englandMeanAgeTime") v14("?layer"):::projected v8("?ukPrimeMinister") v11("?ukPrimeMinisterAge") v10("?ukPrimeMinisterDob") v9("?ukPrimeMinisterStart") v1("?usPresident") v4("?usPresidentAge") v3("?usPresidentDob") v2("?usPresidentStart") a1((" ")) a2((" ")) a3((" ")) c8(["wd:Q14211"]):::iri c2(["wd:Q5"]):::iri c11(["wd:Q21"]):::iri c4(["wd:Q11696"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; a3 --"p:statement/P4442"--> v12 a3 --"p:qualifier/P585"--> v13 c11 --"p:P4442"--> a3 bind0[/"?englandMeanAgeTime"/] v13 --o bind0 bind0 --as--o v14 bind1[/"?englandMeanAge"/] v12 --o bind1 bind1 --as--o v14 bind2[/"sEngland^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'"/] bind2 --as--o v14 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v8 --"p:direct/P31"--> c2 a2 --"p:statement/P39"--> c8 a2 --"p:qualifier/P580"--> v9 v8 --"p:P39"--> a2 v8 --"p:direct/P569"--> v10 bind3[/"http://www.w3.org/2001/XMLSchema#integer(?ukPrimeMinisterStart - ?ukPrimeMinisterDob / '365.2425^^xsd:decimal')"/] v9 --o bind3 v10 --o bind3 bind3 --as--o v11 bind4[/"?ukPrimeMinisterStart"/] v9 --o bind4 bind4 --as--o v14 bind5[/"?ukPrimeMinisterAge"/] v11 --o bind5 bind5 --as--o v14 bind6[/"sUK Prime Minister^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'"/] bind6 --as--o v14 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c2 a1 --"p:statement/P39"--> c4 a1 --"p:qualifier/P580"--> v2 v1 --"p:P39"--> a1 v1 --"p:direct/P569"--> v3 bind7[/"http://www.w3.org/2001/XMLSchema#integer(?usPresidentStart - ?usPresidentDob / '365.2425^^xsd:decimal')"/] v2 --o bind7 v3 --o bind7 bind7 --as--o v4 bind8[/"?usPresidentStart"/] v2 --o bind8 bind8 --as--o v14 bind9[/"?usPresidentAge"/] v4 --o bind9 bind9 --as--o v14 bind10[/"sUS president^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'"/] bind10 --as--o v14 end union0r <== or ==> union0l end