query-9f0f92e44e0204cef2ac85928eda1b71

rq turtle/ttl

График от момента во времени

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/>
# number of living people who have walked on the moon, over time

#defaultView:LineChart
SELECT ?date (COUNT(DISTINCT ?item) AS ?count)
WHERE {
  # inject the current time as another date, so that the chart continues until the present day
  {  {
  # get all the dates where the number of living people who have walked on the moon changed
  # (person walked on the moon or person died)
  SELECT DISTINCT ?date WHERE {
    {
      # person walked on the moon
      ?item p:P793 [
        ps:P793 wd:Q42882411;
        pq:P580 ?date_
      ].
    } UNION {
      # person died
      ?item p:P793/ps:P793 wd:Q42882411;
            wdt:P570 ?date_.
    }
    # for each date, inject a second date, one day before,
    # so that we get a straight line until that date and then a steep climb/drop for the real change,
    # instead of a diagonal slope over the entire preceding period
    VALUES ?toggle { true false }
    BIND(IF(?toggle, ?date_, ?date_ - "P1D"^^xsd:duration) AS ?date)
  }
} } UNION { BIND(NOW() AS ?date) }
  # main query: find all living people who have walked on the moon at each date
  ?item p:P793 [
    ps:P793 wd:Q42882411;
    pq:P580 ?walkdate
  ].
  FILTER(?date >= ?walkdate) # must have walked on the moon already
  OPTIONAL { ?item wdt:P570 ?died. }
  FILTER(!BOUND(?died)|| ?date < ?died) # must not yet have died
}
GROUP BY ?date
ORDER BY ?date

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?count") v7("?date"):::projected v4("?date_") v2("?died") v5("?item"):::projected v6("?toggle") v3("?walkdate") a1((" ")) a2((" ")) a3((" ")) c2(["wd:Q42882411"]):::iri f0[["(not bound(?died) || ?date < ?died)"]] f0 --> v2 f0 --> v7 f1[["?date >= ?walkdate"]] f1 --> v7 f1 --> v3 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; bind2[/"NOW()"/] bind2 --as--o v7 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v5 --"p:P793"--> a2 a2 --"p:statement/P793"--> c2 v5 --"p:direct/P570"--> v4 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; a1 --"p:statement/P793"--> c2 a1 --"p:qualifier/P580"--> v4 v5 --"p:P793"--> a1 end union1r <== or ==> union1l end bind3[/VALUES ?toggle/] bind3-->v6 bind30(["true^^xsd:boolean"]) bind30 --> bind3 bind31(["false^^xsd:boolean"]) bind31 --> bind3 bind4[/"if(?toggle,?date_,?date_ - 'P1D^^xsd:duration')"/] v6 --o bind4 v4 --o bind4 bind4 --as--o v7 end union0r <== or ==> union0l end a3 --"p:statement/P793"--> c2 a3 --"p:qualifier/P580"--> v3 v5 --"p:P793"--> a3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:direct/P570".-> v2 end bind6[/"count(?item)"/] v5 --o bind6 bind6 --as--o v7