query-6a6913aef4697f15b61ec66848d0fd8d

rq turtle/ttl

title:Chancellors of the Exchequer and time served in office SELECT ?item ?itemLabel ?start ?end ?image ?link ?partyLabel ?ps_start ?ps_end WHERE { ?item p:P39 ?s. ?s ps:P39 wd:Q531471. ?s pq:P580 ?start. OPTIONAL {?s pq:P582 ?end.} OPTIONAL {?item wdt:P18 ?image.} OPTIONAL {?item wdt:P1417 ?id.} OPTIONAL {?item p:P102 ?ps. ?ps ps:P102 ?party. OPTIONAL {?ps pq:P580 ?ps_start.} OPTIONAL {?ps pq:P582 ?ps_end.} }
BIND(IF(BOUND(?id), URI(CONCAT("https://www.britannica.com/",?id)) , ?item) AS ?link) FILTER(?start > ?ps_start || !BOUND(?ps_start)) FILTER(?start < ?ps_end || !BOUND(?ps_end)) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?start

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
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/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#title:Chancellors of the Exchequer and time served in office
SELECT ?item ?itemLabel ?start ?end ?image ?link ?partyLabel ?ps_start ?ps_end WHERE {
  ?item p:P39 ?s.
  ?s ps:P39 wd:Q531471.
  ?s pq:P580 ?start. 
  OPTIONAL {?s pq:P582 ?end.}
  OPTIONAL {?item wdt:P18 ?image.}
  OPTIONAL {?item wdt:P1417 ?id.}
  OPTIONAL {?item p:P102 ?ps.
            ?ps ps:P102 ?party. 
            OPTIONAL {?ps pq:P580 ?ps_start.} 
            OPTIONAL {?ps pq:P582 ?ps_end.}
           }      
  BIND(IF(BOUND(?id), URI(CONCAT("https://www.britannica.com/",?id)) , ?item) AS ?link)
  FILTER(?start > ?ps_start || !BOUND(?ps_start))
  FILTER(?start < ?ps_end || !BOUND(?ps_end))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?start

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?end"):::projected v8("?id") v7("?image"):::projected v4("?item"):::projected v11("?link"):::projected v10("?party") v9("?ps") v2("?ps_end"):::projected v3("?ps_start"):::projected v5("?s") v1("?start"):::projected c3(["wd:Q531471"]):::iri c11(["bd:serviceParam"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["(?start < ?ps_end || not bound(?ps_end))"]] f0 --> v1 f0 --> v2 f1[["(?start > ?ps_start || not bound(?ps_start))"]] f1 --> v1 f1 --> v3 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> c3 v5 --"p:qualifier/P580"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:qualifier/P582".-> v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P18".-> v7 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P1417".-> v8 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:P102".-> v9 v9 --"p:statement/P102"--> v10 subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:qualifier/P580".-> v3 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:qualifier/P582".-> v2 end end bind2[/"if(bound(?id),concat('https://www.britannica.com/',?id),?item)"/] v8 --o bind2 v4 --o bind2 bind2 --as--o v11 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end