query-a354276e935fefc7812f3c303b0a5500
optional WHERE statement?Hi, using an f-String for replacement in Python, I loop through a list of historical persons trying to get their family information. Unfortunately, my query only gives me information if the person has an entry for her/his father AND an entry for her/his mother AND an entry for one or more child(ren). Since many persons do not have entries for one or the other, I don't receive any information from the Wikidata. How can I make the WHERE statements facultative/optional? I mean like "try; except: continue" . I would like to get something like an empty string, if there is no information in the database. In the example, Tilo Wilmowsky (Q2433711) does not have an entry for his mother.
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 bd: <http://www.bigdata.com/rdf#>
SELECT ?personLabel ?motherLabel ?mother ?fatherLabel ?father ?childLabel ?child
WHERE { VALUES ?person { wd:Q2433711 }
?person wdt:P22 ?father .
?person wdt:P25 ?mother .
?person wdt:P40 ?child .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],de" }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?child"):::projected
v2("?father"):::projected
v3("?mother"):::projected
v1("?person")
c7(["#91;AUTO_LANGUAGE#93;,de"]):::literal
c5(["bd:serviceParam"]):::iri
bind0[/VALUES ?person/]
bind0-->v1
bind00(["wd:Q2433711"])
bind00 --> bind0
v1 --"wdt:P22"--> v2
v1 --"wdt:P25"--> v3
v1 --"wdt:P40"--> v4
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c5 --"wikibase:language"--> c7
end