query-0e25d0206bf403e3f2d394d7450dd77f
Timeout with UNION and OPTIONALI have a query like this:
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 schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?person ?personLabel ?givenName ?occupation
WHERE {
{
SELECT ?person
WHERE
{
{
{ ?person wdt:P31/wdt:P279* wd:Q5. }
UNION
{ ?hasSitelink schema:about ?person; schema:isPartOf <https://de.wikipedia.org/>. }
}
?person wdt:P509 wd:Q175111.
}
}
OPTIONAL { ?person wdt:P735 ?givenNameItem. }
OPTIONAL { ?person wdt:P106 ?occupationItem. }
# ... more OPTIONAL patterns of this kind would go here ...
SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en". ?person rdfs:label ?personLabel. ?givenNameItem rdfs:label ?givenName. ?occupationItem rdfs:label ?occupation. }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?givenName"):::projected
v3("?givenNameItem")
v2("?hasSitelink")
v7("?occupation"):::projected
v4("?occupationItem")
v1("?person"):::projected
v5("?personLabel"):::projected
a1((" "))
c6([https://de.wikipedia.org/]):::iri
c8(["wd:Q175111"]):::iri
c12(["bd:serviceParam"]):::iri
c3(["wd:Q5"]):::iri
c14(["de,en"]):::literal
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v2 --"schema:about"--> v1
v2 --"schema:isPartOf"--> c6
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v1 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c3
end
union0r <== or ==> union0l
end
v1 --"wdt:P509"--> c8
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P735".-> v3
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P106".-> v4
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c12 --"wikibase:language"--> c14
v1 --"rdfs:label"--> v5
v3 --"rdfs:label"--> v6
v4 --"rdfs:label"--> v7
end