query-a3d92e73b84ff8191205093f18bcaeaf

rq turtle/ttl

Is it possible to create a hierarchical tree diagram for two known entities?Looking at the template query for "Parent taxons of Blue Whale" I was curious about how it could be used to determine the common path between two species. #Parent taxons of Blue Whale #defaultView:Graph SELECT ?item ?itemLabel ?linkTo ?pic WHERE { wd:Q42196 wdt:P171* ?item . # <---- species ID goes here OPTIONAL { ?item wdt:P171 ?linkTo } # child of OPTIONAL { ?item wdt:P18 ?pic } SERVICE wikibase:label {bd:serviceParam wikibase:language "en" } } https://w.wiki/veRHere the species "Balaenoptera musculus" is given, and it recursively climbs the list of P171 attributes. But let's say I have a query for a cat, "Felis catus" wd:Q20980826 https://w.wiki/56SR these two queries in order to return a single path that terminates at their first common parent? joinCould I I figure this requires: - two queries made in series, then joined by UNION - some calculation that can pare down each query to a single shortest path If this is possible I would love to see an example of how to do so given the commands that are available on wikidata's endpoint. edit:I found a property called "preferred rank" Q71533031 which is used to highlight the preferred parent taxon green on Wikidata web pages. I'm not sure how to incorporate it into the query but this might be enough to "prune" the tree down to a single path. common ancestors, but I can't choose the latest... Probably this could be fixed for showing the graph:allI've managed to get a list of ]reply[20:33, 25 April 2022 (UTC)) talk (Dipsacus fullonum. --mw:Wikibase/Indexing/RDF Dump Format and how to use it in queries in Help:Ranking isn't a property. Read about ranking in (Q71533031)preferred rank PS. , join them, then limit the result to lowest sum of the depths.GAS serviceYes, that is probably possible. I would find the taxon hierarchies with the

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#>
#Common parent taxons of 2 species
# defaultView:Graph
SELECT distinct ?ECA ?ECALabel #?item1 ?item1Label ?item2 ?item2Label ?pic1 ?linkTo1 ?pic2 ?linkTo2
WHERE
{
   {
    SELECT distinct ?item1 WHERE {wd:Q42196 wdt:P171* ?item1.}
  }
   {
     SELECT distinct ?item2 WHERE { wd:Q20980826 wdt:P171* ?item2.}
  }
  ?item1 wdt:P171* ?ECA.
#  OPTIONAL { ?item1 wdt:P171 ?linkTo1 }
#  OPTIONAL { ?item1 wdt:P18 ?pic1 }

  ?item2 wdt:P171* ?ECA.
#  OPTIONAL { ?item2 wdt:P171 ?linkTo2 }
#  OPTIONAL { ?item2 wdt:P18 ?pic2 }
  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; v3("?ECA"):::projected v1("?item1") v2("?item2") c5(["bd:serviceParam"]):::iri c1(["wd:Q42196"]):::iri c3(["wd:Q20980826"]):::iri c7(["en"]):::literal c1 --"wdt:P171"--> v1 c3 --"wdt:P171"--> v2 v1 --"wdt:P171"--> v3 v2 --"wdt:P171"--> v3 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c5 --"wikibase:language"--> c7 end