query-25cf0aac4cd84e8dbc5a9282e4e6b6a3

rq turtle/ttl

Person queryHi, I'm trying to extract all the date information for a person/artist in a single query (birth, death, floruit, work period start, work period end). To simplify things in the example below I'm just trying to get the date of birth of Pythagoras and all the subsidiary qualifiers and values. It is returning what I want, the highest ranked birth date, but I can't believe the query is correct. In particular I have two lines populating the same variable (from a mis-edit)! ?item wdt:P569 ?bi_date. ?bi ps:P569 ?bi_date. If I remove the 2nd of the two lines the query returns 9 rows not 1. Same if I assign the results of the 2nd line to new variable or remove the 1st line not the 2nd - 9 rows not 1. Any help gratefully received.

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT
  ?item ?itemLabel
  ?bi_date ?bi_precision ?bi_rank ?bi_earliest ?bi_earliest_precision ?bi_latest ?bi_latest_precision ?bi_circaLabel ?bi_refineLabel
WHERE
{
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }

  ?item wdt:P31 wd:Q5.
  VALUES ?item { wd:Q10261 }

  # date of birth
  OPTIONAL {
    ?item wdt:P569 ?bi_date.
    ?item p:P569 ?bi.
    ?bi ps:P569 ?bi_date.
    ?bi wikibase:rank ?bi_rank.
    ?bi psv:P569 [ wikibase:timePrecision ?bi_precision ].
    OPTIONAL { ?bi pq:P1319 ?bi_earliest.
              ?bi pqv:P1319 [ wikibase:timePrecision ?bi_earliest_precision ].
             }
    OPTIONAL { ?bi pq:P1326 ?bi_latest.
              ?bi pqv:P1326 [ wikibase:timePrecision ?bi_latest_precision ].
             }
    OPTIONAL { ?bi pq:P1480 ?bi_circa. }
    OPTIONAL { ?bi pq:P4241 ?bi_refine. }
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?bi") v10("?bi_circa") v2("?bi_date"):::projected v6("?bi_earliest"):::projected v7("?bi_earliest_precision"):::projected v8("?bi_latest"):::projected v9("?bi_latest_precision"):::projected v5("?bi_precision"):::projected v4("?bi_rank"):::projected v11("?bi_refine") v2("?item"):::projected a1((" ")) a2((" ")) a3((" ")) c2(["bd:serviceParam"]):::iri c6(["wd:Q5"]):::iri c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v2 --"p:direct/P31"--> c6 bind0[/VALUES ?item/] bind0-->v2 bind00(["wd:Q10261"]) bind00 --> bind0 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P569".-> v2 v2 --"p:P569"--> v3 v3 --"p:statement/P569"--> v2 v3 --"wikibase:rank"--> v4 a1 --"wikibase:timePrecision"--> v5 v3 --"p:statement/value/P569"--> a1 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P1319".-> v6 a2 --"wikibase:timePrecision"--> v7 v3 --"p:qualifier/value/P1319"--> a2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P1326".-> v8 a3 --"wikibase:timePrecision"--> v9 v3 --"p:qualifier/value/P1326"--> a3 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P1480".-> v10 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P4241".-> v11 end end