query-1b03afc2ca5e484521bc5c727307290f

rq turtle/ttl

(P171)parent taxon (P105)taxon rank

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?item ?scientific_name (GROUP_CONCAT(DISTINCT ?common_name; SEPARATOR=", ") AS ?common_English_names)
  ?taxon_id ?genus ?family ?order ?class
WHERE
{

{
  SELECT ?item
  WHERE
  {
    # Select some items for species
    ?item wdt:P31 wd:Q16521 . # ?item is instance of taxan
    ?item wdt:P105 wd:Q7432 . # taxon rank is species
  }
  LIMIT 5
}  ?item wdt:P225 ?scientific_name .
  OPTIONAL
  {
    ?item wdt:P1843 ?common_name .
    FILTER (LANG(?common_name) = 'en')
  }
  OPTIONAL { ?item wdt:P846 ?taxon_id . }

  # Get genus, family, order, class
  ?item wdt:P171+ ?genus .
  ?genus wdt:P105 wd:Q34740 . # taxon rank is genus
  ?genus wdt:P171+ ?family .
  ?family wdt:P105 wd:Q35409. # taxon rank is family
  ?family wdt:P171+ ?order .
  ?order wdt:P105 wd:Q36602 . # taxon rank is order
  OPTIONAL 
  {
    # Not all best rank P171 chains includes a class
    ?order wdt:P171+ ?class .
    ?class wdt:P105 wd:Q37517 . # taxon rank is class
  }
}
GROUP BY ?item ?scientific_name ?taxon_id ?genus ?family ?order ?class

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?class"):::projected v9("?common_English_names") v1("?common_name"):::projected v6("?family"):::projected v5("?genus"):::projected v2("?item"):::projected v7("?order"):::projected v3("?scientific_name"):::projected v4("?taxon_id"):::projected c11(["wd:Q35409"]):::iri c5(["wd:Q7432"]):::iri c10(["wd:Q34740"]):::iri c13(["wd:Q37517"]):::iri c3(["wd:Q16521"]):::iri c12(["wd:Q36602"]):::iri v2 --"wdt:P31"--> c3 v2 --"wdt:P105"--> c5 v2 --"wdt:P225"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P1843".-> v1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P846".-> v4 end v2 --"wdt:P171"--> v5 v5 --"wdt:P105"--> c10 v5 --"wdt:P171"--> v6 v6 --"wdt:P105"--> c11 v6 --"wdt:P171"--> v7 v7 --"wdt:P105"--> c12 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P171".-> v8 v8 --"wdt:P105"--> c13 end bind1[/"?common_name"/] v1 --o bind1 bind1 --as--o v9