query-2c084cce9a8c3fd8e7960b86d81e989f
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 prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?name ?constituency ?party ?gender ?birth_date ?source WHERE {
?item p:P39 ?mem .
?mem ps:P39 wd:Q17599130; pq:P2937 wd:Q46952785 .
FILTER NOT EXISTS { ?mem pq:P582 [] }
OPTIONAL { ?item p:P973/pq:P1810 ?name2 }
OPTIONAL { ?item wdt:P21 ?genderItem }
OPTIONAL { ?item wdt:P569 ?DoB . BIND(SUBSTR(STR(?DoB), 1, 10) AS ?birth_date) }
OPTIONAL { ?mem pq:P4100|pq:P102 ?group }
OPTIONAL { ?group wdt:P1813 ?shortparty . FILTER(LANG(?shortparty) = 'en')}
OPTIONAL { ?mem pq:P768 ?area }
OPTIONAL { ?mem prov:wasDerivedFrom [ pr:P854 ?source ] }
FILTER(STRSTARTS(str(?source),"http://www.parliament.go.tz/administrations/"))
?item rdfs:label ?name3 . FILTER(LANG(?name3) = 'en') .
BIND(COALESCE(?name2, ?name3) AS ?name) .
BIND(COALESCE(?shortparty, ?groupname) AS ?party) .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?area rdfs:label ?constituency .
?group rdfs:label ?groupname .
?genderItem rdfs:label ?gender .
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?DoB")
v11("?area")
v9("?birth_date"):::projected
v14("?constituency"):::projected
v16("?gender"):::projected
v7("?genderItem")
v10("?group")
v15("?groupname")
v5("?item"):::projected
v4("?mem")
v12("?name"):::projected
v6("?name2")
v1("?name3")
v13("?party"):::projected
v3("?shortparty")
v2("?source"):::projected
a1((" "))
a2((" "))
a3((" "))
c1(["en"]):::literal
c21(["bd:serviceParam"]):::iri
c6(["wd:Q17599130"]):::iri
c8(["wd:Q46952785"]):::iri
f0[["?name3 = 'en'"]]
f0 --> v1
f1[["starts-with(str(?source),'http://www.parliament.go.tz/administrations/')"]]
f1 --> v2
f2[["not "]]
subgraph f2e0["Exists Clause"]
e0v1 --"p:qualifier/P582"--> e0a1
e0v1("?mem"):::projected
e0a1((" ")):::projected
end
f2--EXISTS--> f2e0
f2 --> v4
f2 --> c3
f2 --> a1
v4 --"p:qualifier/P582"--> a1
v5 --"p:P39"--> v4
v4 --"p:statement/P39"--> c6
v4 --"p:qualifier/P2937"--> c8
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:P973".-> a2
a2 --"p:qualifier/P1810"--> v6
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P21".-> v7
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P569".-> v8
bind3[/"substring(str(?DoB),'1^^xsd:integer','10^^xsd:integer')"/]
v8 --o bind3
bind3 --as--o v9
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v4 -."p:qualifier/P102".-> v10
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v4 --"p:qualifier/P4100"--> v10
end
union0r <== or ==> union0l
end
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v10 -."p:direct/P1813".-> v3
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P768".-> v11
end
subgraph optional6["(optional)"]
style optional6 fill:#bbf,stroke-dasharray: 5 5;
a3 -."p:reference/P854".-> v2
v4 --"prov:wasDerivedFrom"--> a3
end
v5 --"rdfs:label"--> v1
bind4[/"?name2?name3"/]
v6 --o bind4
v1 --o bind4
bind4 --as--o v12
bind5[/"?shortparty?groupname"/]
v3 --o bind5
v15 --o bind5
bind5 --as--o v13
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c21 --"wikibase:language"--> c1
v11 --"rdfs:label"--> v14
v10 --"rdfs:label"--> v15
v7 --"rdfs:label"--> v16
end