query-d76530e553f8242e7e0b6d5e77fef830
All former municipalities of Switzerland should have a qualifier statement
(e.g. start date when they became "former")
SELECT * WITH { # select all ?item P31 Q685309 that have a qualifier pq582 SELECT ?item WHERE { hint:Query hint:optimizer "None" . ?item wdt:P31 wd:Q685309 . ?item p:P31 ?statement . ## I need to filter this only to statements that apply to wd:Q685309 (not any in P31) and those that are P582 ?statement ps:P31 wd:Q70208 . ?statement pq:P582 ?end_time .
# Filter to qualifiers
?statement ?pq_qual ?pq_obj .
?qual wikibase:qualifier ?pq_qual .
}
} as %muni
WHERE
{
?item wdt:P31 wd:Q685309 .
MINUS { include %muni } # subtract those with qualifier from all Q685309
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de" }
}
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#>
# All former municipalities of Switzerland *should* have a qualifier statement
# (e.g. start date when they became "former")
SELECT *
WHERE
{
?item wdt:P31 wd:Q685309 .
MINUS {
{
# select all ?item P31 Q685309 that have a qualifier pq582
SELECT ?item WHERE {
?item wdt:P31 wd:Q685309 .
?item p:P31 ?statement .
## I need to filter this only to statements that apply to wd:Q685309 (not any in P31) and those that are P582
?statement ps:P31 wd:Q70208 .
?statement pq:P582 ?end_time .
# Filter to qualifiers
?statement ?pq_qual ?pq_obj .
?qual wikibase:qualifier ?pq_qual .
}
}} # subtract those with qualifier from all Q685309
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de" }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?end_time")
v1("?item"):::projected
v5("?pq_obj")
v4("?pq_qual")
v6("?qual")
v2("?statement")
c2(["wd:Q685309"]):::iri
c9(["bd:serviceParam"]):::iri
c5(["wd:Q70208"]):::iri
c11(["#91;AUTO_LANGUAGE#93;,en,de"]):::literal
v1 --"p:direct/P31"--> c2
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v1 --"p:direct/P31"--> c2
v1 --"p:P31"--> v2
v2 --"p:statement/P31"--> c5
v2 --"p:qualifier/P582"--> v3
v2 -->v4--> v5
v6 --"wikibase:qualifier"--> v4
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end