query-f5fc6823b1c160f0ddf9af4e5edd4711
Presidents with identified mythical ancestors
SELECT distinct ?person ?personLabel ?ancestor ?ancestorLabel ?born ?died ?typeLabel WHERE {
?person p:P39 ?positionStatement . ?positionStatement ps:P39 wd:Q11696 . # this person was President of the USA { ?person (wdt:P25|wdt:P22)* ?ancestor . } # their mother or father, or their mother or father, and so on filter not exists { ?ancestor wdt:P31 wd:Q5 } . # the ancestor is not "a human" ?ancestor wdt:P31 ?type . ?person wdt:P31 wd:Q5 . # the original person must be a human, ie not fictional OPTIONAL { ?ancestor wdt:P569 ?born } . OPTIONAL { ?ancestor wdt:P570 ?died } . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Presidents with identified mythical ancestors
SELECT distinct ?person ?personLabel ?ancestor ?ancestorLabel ?born ?died ?typeLabel WHERE {
?person p:P39 ?positionStatement .
?positionStatement ps:P39 wd:Q11696 . # this person was President of the USA
{ ?person (wdt:P25|wdt:P22)* ?ancestor . } # their mother or father, or their mother or father, and so on
filter not exists { ?ancestor wdt:P31 wd:Q5 } . # the ancestor is not "a human"
?ancestor wdt:P31 ?type .
?person wdt:P31 wd:Q5 . # the original person must be a human, ie not fictional
OPTIONAL { ?ancestor wdt:P569 ?born } .
OPTIONAL { ?ancestor wdt:P570 ?died } .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?ancestor"):::projected
v5("?born"):::projected
v6("?died"):::projected
v2("?person"):::projected
v3("?positionStatement")
v4("?type")
c13(["en"]):::literal
c11(["bd:serviceParam"]):::iri
c2(["wd:Q5"]):::iri
c5(["wd:Q11696"]):::iri
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"p:direct/P31"--> e0c2
e0v1("?ancestor"):::projected
e0c2(["wd:Q5"]):::iri
end
f0--EXISTS--> f0e0
f0 --> v1
f0 --> c1
f0 --> c2
v1 --"p:direct/P31"--> c2
v2 --"p:P39"--> v3
v3 --"p:statement/P39"--> c5
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v2 --"p:direct/P22"--> v1
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v2 --"p:direct/P25"--> v1
end
union0r <== or ==> union0l
end
v1 --"p:direct/P31"--> v4
v2 --"p:direct/P31"--> c2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P569".-> v5
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P570".-> v6
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c11 --"wikibase:language"--> c13
end