query-4b12729b5876664db03a2515cbb86c36

rq turtle/ttl

MPs with identified mythical ancestors SELECT ?mp ?mpLabel ?person ?personLabel ?born ?died ?typeLabel WHERE { ?mp p:P39 ?positionStatement . ?positionStatement ps:P39 wd:Q77685926 . # this person is a member of the current parliament { ?mp (wdt:P25|wdt:P22)* ?person . } # mp's mother or father, or their mother or father, and so on filter not exists { ?person wdt:P31 wd:Q5 } . # the ancestor is not "a human" ?person wdt:P31 ?type . OPTIONAL { ?person wdt:P569 ?born } . OPTIONAL { ?person wdt:P570 ?died } . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

Use at

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#>
# MPs with identified mythical ancestors
SELECT ?mp ?mpLabel ?person ?personLabel ?born ?died ?typeLabel WHERE {
  ?mp p:P39 ?positionStatement .
  ?positionStatement ps:P39 wd:Q77685926 .  # this person is a member of the current parliament
  { ?mp (wdt:P25|wdt:P22)* ?person . } # mp's mother or father, or their mother or father, and so on
  filter not exists { ?person wdt:P31 wd:Q5 } . # the ancestor is not "a human"
  ?person wdt:P31 ?type .
  OPTIONAL { ?person wdt:P569 ?born } .
  OPTIONAL { ?person 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; v5("?born"):::projected v6("?died"):::projected v2("?mp"):::projected v1("?person"):::projected v3("?positionStatement") v4("?type") c13(["en"]):::literal c11(["bd:serviceParam"]):::iri c2(["wd:Q5"]):::iri c5(["wd:Q77685926"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:direct/P31"--> e0c2 e0v1("?person"):::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 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