query-0c6284ed37b70b0ae821c12351fbff6c

rq turtle/ttl

Now I want to introduce one more abbreviation that SPARQL offers. So if you’ll humor me for one more hypothetical scenario… , which points from parent to child and is gender-independent. With this information, can you write a query that returns Bach’s grandchildren? P:P40children. (Hypothetically.) There’s one complication here: a grandchild may be related to Bach via the mother or the father. That’s two different properties, which is inconvenient. Instead, let’s flip the relation around: Wikidata also has a “child” property, grandSuppose we’re not actually interested in Bach’s children. (Who knows, perhaps that’s actually true for you!) But we are interested in his Here’s my solution:

Use at

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 ?grandChild ?grandChildLabel
WHERE
{
  wd:Q1339 wdt:P40 ?dziecko.
  ?dziecko wdt:P40 ?grandChild.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?dziecko") v2("?grandChild"):::projected c1(["wd:Q1339"]):::iri c4(["bd:serviceParam"]):::iri c6(["#91;AUTO_LANGUAGE#93;"]):::literal c1 --"wdt:P40"--> v1 v1 --"wdt:P40"--> v2 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c4 --"wikibase:language"--> c6 end