query-d3afa9508b88937787b272215b6219cf

rq turtle/ttl

Number of virtual twins at a given milestone

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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/>
# by Jura1, 2021-11-04
#title:Number of virtual twins (pair with the same dates of birth and death) in Wikidata at a given milestone, from [[d:Wikidata:WikiProject Virtual Twins]]
#defaultView:AreaChart
SELECT ?date ?cumulativecount 
{

    {   SELECT ?milestonep (COUNT(?item) as ?cumulativecount)
        WHERE
        {
          { SELECT ?item { {
    ?item p:P1889 [ pq:P1013 wd:Q20978290 ; ps:P1889 ?item2 ]
    FILTER( xsd:integer(strafter(str(?item),"Q")) >  xsd:integer(strafter(str(?item2),"Q"))  )         
  } }   }
          BIND( xsd:integer( substr(str(?item), 33)) as ?qid)
          wd:Q38074555 p:P1114 ?milestonep .
          ?milestonep ps:P1114 ?milestone .
          FILTER( ?milestone > ?qid ) 
        }
        GROUP BY ?milestonep
    }          
    ?milestonep pq:P585 ?date
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?cumulativecount"):::projected v7("?date"):::projected v3("?item") v4("?item2") v1("?milestone") v5("?milestonep") v5("?qid") a1((" ")) c3(["wd:Q20978290"]):::iri c6(["wd:Q38074555"]):::iri f0[["?milestone > ?qid"]] f0 --> v1 f0 --> v5 f1[["http://www.w3.org/2001/XMLSchema#integer(substring-after(str(?item),'Q')) > http://www.w3.org/2001/XMLSchema#integer(substring-after(str(?item2),'Q'))"]] f1 --> v3 f1 --> v4 a1 --"p:qualifier/P1013"--> c3 a1 --"p:statement/P1889"--> v4 v3 --"p:P1889"--> a1 bind2[/"http://www.w3.org/2001/XMLSchema#integer(substring(str(?item),'33^^xsd:integer'))"/] v3 --o bind2 bind2 --as--o v5 c6 --"p:P1114"--> v5 v5 --"p:statement/P1114"--> v1 bind4[/"count(?item)"/] v3 --o bind4 bind4 --as--o v6 v5 --"p:qualifier/P585"--> v7