query-d8c398e4e81f40012eaefa2f7c808a40
SPARQL query
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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#>
SELECT DISTINCT ?id (STRAFTER(STR(?item), STR(wd:)) AS ?wikidata)
WHERE {
?item p:P39 ?mem .
?mem ps:P39 wd:Q18558478 ; pq:P2937 wd:Q5487948 .
OPTIONAL { ?mem pq:P768 ?district }
OPTIONAL { ?mem pq:P4100 ?group }
OPTIONAL { ?item wdt:P1229 ?id }
FILTER NOT EXISTS { ?mem pq:P582 [] } # only current members
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?item rdfs:label ?name .
}
}
Query found at
- https://www.wikidata.org/wiki/Wikidata:WikiProject_every_politician/Italy/Deputies/prompts/OpenPolis
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?district")
v4("?group")
v5("?id"):::projected
v2("?item"):::projected
v1("?mem")
v6("?name")
v7("?wikidata")
a1((" "))
c4(["wd:Q18558478"]):::iri
c13(["en"]):::literal
c11(["bd:serviceParam"]):::iri
c6(["wd:Q5487948"]):::iri
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"p:qualifier/P582"--> e0a1
e0v1("?mem"):::projected
e0a1((" ")):::projected
end
f0--EXISTS--> f0e0
f0 --> v1
f0 --> c1
f0 --> a1
v1 --"p:qualifier/P582"--> a1
v2 --"p:P39"--> v1
v1 --"p:statement/P39"--> c4
v1 --"p:qualifier/P2937"--> c6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:qualifier/P768".-> v3
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:qualifier/P4100".-> v4
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:direct/P1229".-> v5
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c11 --"wikibase:language"--> c13
v2 --"rdfs:label"--> v6
end
bind1[/"substring-after(str(?item),str('wd:'))"/]
v2 --o bind1
bind1 --as--o v7