WDscholia/scholia

"Parent Taxa" panel in `taxon` aspect: sort by "distance"

Closed this issue · 5 comments

Is your feature request related to a problem? Please describe.
The "Parent Taxa" panel is difficult to grasp at times, because the results are not sorted. (genus-family-order works, but not subgenus or class.)

Describe the solution you'd like
Something like this seems to work, but it adds an additional column.

diff --git a/scholia/app/templates/taxon_parent-taxa.sparql b/scholia/app/templates/taxon_parent-taxa.sparql
index b54de38f..a11c0045 100644
--- a/scholia/app/templates/taxon_parent-taxa.sparql
+++ b/scholia/app/templates/taxon_parent-taxa.sparql
@@ -1,10 +1,12 @@
 PREFIX target: <http://www.wikidata.org/entity/{{ q }}>
 
 SELECT
+  (COUNT(?middle) AS ?distance)
   (GROUP_CONCAT(DISTINCT ?rank_label_; separator=", ") AS ?rank)
   ?parent ?parentLabel ?parentDescription
 {
-  target: wdt:P171+ ?parent .
+  target: wdt:P171* ?middle .
+  ?middle wdt:P171+ ?parent .
   ?parent wdt:P105 ?rank .
   OPTIONAL {
     ?rank rdfs:label ?rank_label_ . FILTER (LANG(?rank_label_) = 'en')
@@ -12,3 +14,4 @@ SELECT
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
 }
 GROUP BY ?parent ?parentLabel ?parentDescription
+ORDER BY ?distance

It's of course also visible in the graph panel below, but that's not immediately readable either.

Sounds good to me! I tried similar things in the past, but never got it fast enough. Not sure what changed.

Can you convert this into a PR?

See also #239

Can we hide certain SPARQL output columns from datatables automatically? E.g. if they start with an underscore?