query-60fefa4f9b2d4a64e7c0aea80d379a85
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.}
# It is faster not to use ?start and ?end here. The next lines will avoid timeout:
OPTIONAL { ?s pq:P582 ?pos_end.}
?s pq:P580 ?pos_start
# Check that party membership did not start after end of postion:
FILTER (IF(BOUND(?ps_start) && BOUND(?pos_end), ?ps_start < ?pos_end, true))
# Check that party membership did not end before start of postion;
FILTER (IF(BOUND(?ps_end), ?ps_end > ?pos_start, true))
} BIND(IF(BOUND(?id), URI(CONCAT("https://www.britannica.com/",?id)) , ?item) AS ?link) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?start
Use at
- https://query.wikidata.org/sparql
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.}
# It is faster not to use ?start and ?end here. The next lines will avoid timeout:
OPTIONAL { ?s pq:P582 ?pos_end.}
?s pq:P580 ?pos_start
# Check that party membership did not start after end of postion:
FILTER (IF(BOUND(?ps_start) && BOUND(?pos_end), ?ps_start < ?pos_end, true))
# Check that party membership did not end before start of postion;
FILTER (IF(BOUND(?ps_end), ?ps_end > ?pos_start, true))
}
BIND(IF(BOUND(?id), URI(CONCAT("https://www.britannica.com/",?id)) , ?item) AS ?link)
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;
v8("?end"):::projected
v10("?id")
v9("?image"):::projected
v6("?item"):::projected
v13("?link"):::projected
v12("?party")
v3("?pos_end")
v5("?pos_start")
v11("?ps")
v4("?ps_end"):::projected
v2("?ps_start"):::projected
v7("?s")
v1("?start"):::projected
c4(["wd:Q531471"]):::iri
c12(["bd:serviceParam"]):::iri
c14(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v6 --"p:P39"--> v7
v7 --"p:statement/P39"--> c4
v7 --"p:qualifier/P580"--> v1
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P582".-> v8
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:direct/P18".-> v9
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:direct/P1417".-> v10
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:P102".-> v11
v11 --"p:statement/P102"--> v12
v7 --"p:qualifier/P580"--> v5
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v11 -."p:qualifier/P580".-> v2
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v11 -."p:qualifier/P582".-> v4
end
subgraph optional6["(optional)"]
style optional6 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P582".-> v3
end
end
bind0[/"if(bound(?id),concat('https://www.britannica.com/',?id),?item)"/]
v10 --o bind0
v6 --o bind0
bind0 --as--o v13
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c12 --"wikibase:language"--> c14
end