WDscholia / scholia

Wikidata-based scholarly profiles
https://scholia.toolforge.org
Other
215 stars 77 forks source link

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

Closed larsgw closed 3 months ago

larsgw commented 4 months ago

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
larsgw commented 4 months ago

Panel after changes:

Screenshot_20240227_013319

https://scholia.toolforge.org/taxon/Q50798387#parent-taxa

larsgw commented 4 months ago

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

egonw commented 4 months ago

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?

egonw commented 4 months ago

See also https://github.com/WDscholia/scholia/issues/239

larsgw commented 4 months ago

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