query-4e0b85c2171a1bcab620369bdbb54560
SPARQL query
Use at
- https://query.wikidata.org/sparql
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/>
SELECT ?id ?item ?name ?area ?group ?party ?start WHERE {
?item p:P1214 ?idstatement ; p:P39 ?ps .
?idstatement ps:P1214 ?id FILTER(STRLEN(?id) < 20) .
OPTIONAL { ?idstatement pq:P1810 ?riksdagName }
?ps ps:P39 wd:Q10655178 ; pq:P580 ?startDate .
BIND(SUBSTR(STR(?startDate),1,10) AS ?start)
OPTIONAL { ?ps pq:P582 ?end }
FILTER(!BOUND(?end) || ?end > NOW())
OPTIONAL {
?ps pq:P4100 ?group .
OPTIONAL {
?group wdt:P1813 ?groupShort FILTER(LANG(?groupShort) = "sv")
}
}
BIND(COALESCE(?groupShort, '-') AS ?party)
OPTIONAL {
?ps pq:P768 ?district .
# TODO: ONLY ?districts that are actual constituencies?
?district rdfs:label ?districtLabel FILTER(LANG(?districtLabel) = "sv") .
BIND(REPLACE(STR(?districtLabel), "s? valkrets", "") AS ?area)
}
?item rdfs:label ?svname FILTER(LANG(?svname) = "sv") .
BIND(COALESCE(?riksdagName, ?svname) AS ?name)
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v15("?area"):::projected
v14("?district")
v2("?districtLabel")
v3("?end")
v12("?group"):::projected
v11("?groupShort")
v4("?id"):::projected
v6("?idstatement")
v5("?item"):::projected
v16("?name"):::projected
v13("?party"):::projected
v7("?ps")
v8("?riksdagName")
v10("?start"):::projected
v9("?startDate")
v1("?svname")
c8(["wd:Q10655178"]):::iri
f0[["?svname = 'sv'"]]
f0 --> v1
f1[["(not bound(?end) || ?end > NOW())"]]
f1 --> v3
f2[["string-length(?id) < '20^^xsd:integer'"]]
f2 --> v4
v5 --"p:P1214"--> v6
v5 --"p:P39"--> v7
v6 --"p:statement/P1214"--> v4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P1810".-> v8
end
v7 --"p:statement/P39"--> c8
v7 --"p:qualifier/P580"--> v9
bind3[/"substring(str(?startDate),'1^^xsd:integer','10^^xsd:integer')"/]
v9 --o bind3
bind3 --as--o v10
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P582".-> v3
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P4100".-> v12
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v12 -."p:direct/P1813".-> v11
end
end
bind4[/"?groupShort'-'"/]
v11 --o bind4
bind4 --as--o v13
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P768".-> v14
v14 --"rdfs:label"--> v2
bind5[/"replace(str(?districtLabel),'s? valkrets','')"/]
v2 --o bind5
bind5 --as--o v15
end
v5 --"rdfs:label"--> v1
bind6[/"?riksdagName?svname"/]
v8 --o bind6
v1 --o bind6
bind6 --as--o v16