From 46d1d35d269de7fe857c04ea7f772c9d8f84cd89 Mon Sep 17 00:00:00 2001
From: nleanba <25827850+nleanba@users.noreply.github.com>
Date: Fri, 8 Nov 2024 14:14:13 +0100
Subject: [PATCH] handle kingdoms
---
Queries.ts | 34 ++++++++++++++--------------------
SparqlEndpoint.ts | 1 -
SynonymGroup.ts | 7 +++++--
example/index.css | 8 --------
example/index.ts | 5 ++++-
5 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/Queries.ts b/Queries.ts
index d52d3af..b81381a 100644
--- a/Queries.ts
+++ b/Queries.ts
@@ -8,7 +8,7 @@ PREFIX dwc:
PREFIX dwcFP:
PREFIX cito:
PREFIX trt:
-SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?subgenus ?species ?infrasp ?name ?authority
+SELECT DISTINCT ?kingdom ?tn ?tc ?col ?rank ?genus ?subgenus ?species ?infrasp ?name ?authority
(group_concat(DISTINCT ?tcauth;separator=" / ") AS ?tcAuth)
(group_concat(DISTINCT ?aug;separator="|") as ?augs)
(group_concat(DISTINCT ?def;separator="|") as ?defs)
@@ -23,7 +23,7 @@ SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?subgenus ?species ?infrasp ?name ?aut
* As its own variable to ensure consistency in the resturned bindings.
*/
const postamble =
- `GROUP BY ?tn ?tc ?col ?rank ?genus ?subgenus ?species ?infrasp ?name ?authority`;
+ `GROUP BY ?kingdom ?tn ?tc ?col ?rank ?genus ?subgenus ?species ?infrasp ?name ?authority`;
// For unclear reasons, the queries breaks if the limit is removed.
@@ -38,7 +38,8 @@ BIND(<${colUri}> as ?col)
?col dwc:taxonRank ?rank .
?col dwc:scientificName ?name .
?col dwc:genericName ?genus .
- # TODO # ?col dwc:parent* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?kingdom .
+ OPTIONAL { ?col (dwc:parent|dwc:acceptedName)* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?colkingdom . }
+ BIND(COALESCE(?colkingdom, "") AS ?kingdom)
OPTIONAL {
?col dwc:specificEpithet ?species .
OPTIONAL { ?col dwc:infraspecificEpithet ?infrasp . }
@@ -49,22 +50,13 @@ BIND(<${colUri}> as ?col)
?tn dwc:rank ?trank ;
a dwcFP:TaxonName .
FILTER(LCASE(?rank) = LCASE(?trank))
- ?tn dwc:genus ?genus .
?tn dwc:kingdom ?kingdom .
- {
- ?col dwc:specificEpithet ?species .
- ?tn dwc:species ?species .
- {
- ?col dwc:infraspecificEpithet ?infrasp .
- ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp .
- } UNION {
- FILTER NOT EXISTS { ?col dwc:infraspecificEpithet ?infrasp . }
- FILTER NOT EXISTS { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
- }
- } UNION {
- FILTER NOT EXISTS { ?col dwc:specificEpithet ?species . }
- FILTER NOT EXISTS { ?tn dwc:species ?species . }
- }
+ ?tn dwc:genus ?genus .
+
+ OPTIONAL { ?tn dwc:species ?tnspecies . }
+ FILTER(?species = COALESCE(?tnspecies, ""))
+ OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?tninfrasp . }
+ FILTER(?infrasp = COALESCE(?tninfrasp, ""))
OPTIONAL {
?trtnt trt:treatsTaxonName ?tn ; trt:publishedIn/dc:date ?trtndate .
@@ -130,7 +122,8 @@ export const getNameFromTC = (tcUri: string) =>
?col dwc:taxonRank ?rank .
?col dwc:scientificName ?name . # Note: contains authority
?col dwc:genericName ?genus .
- # TODO # ?col dwc:parent* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?kingdom .
+ OPTIONAL { ?col (dwc:parent|dwc:acceptedName)* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?colkingdom . }
+ FILTER(?kingdom = COALESCE(?colkingdom, ""))
OPTIONAL { ?col dwc:specificEpithet ?colspecies . }
FILTER(?species = COALESCE(?colspecies, ""))
@@ -194,7 +187,8 @@ export const getNameFromTN = (tnUri: string) =>
?col dwc:taxonRank ?rank .
?col dwc:scientificName ?name . # Note: contains authority
?col dwc:genericName ?genus .
- # TODO # ?col dwc:parent* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?kingdom .
+ OPTIONAL { ?col (dwc:parent|dwc:acceptedName)* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?colkingdom . }
+ FILTER(?kingdom = COALESCE(?colkingdom, ""))
OPTIONAL { ?col dwc:specificEpithet ?colspecies . }
FILTER(?species = COALESCE(?colspecies, ""))
diff --git a/SparqlEndpoint.ts b/SparqlEndpoint.ts
index b3ba699..39627d1 100644
--- a/SparqlEndpoint.ts
+++ b/SparqlEndpoint.ts
@@ -1,4 +1,3 @@
-// deno-lint-ignore-file no-unused-labels
async function sleep(ms: number): Promise {
const p = new Promise((resolve) => {
setTimeout(resolve, ms);
diff --git a/SynonymGroup.ts b/SynonymGroup.ts
index 21db4b6..23bf2be 100644
--- a/SynonymGroup.ts
+++ b/SynonymGroup.ts
@@ -408,6 +408,7 @@ LIMIT 500`;
treats.forEach((t) => treatmentPromises.push(t));
const name: Name = {
+ kingdom: json.results.bindings[0].kingdom!.value,
displayName,
rank: json.results.bindings[0].rank!.value,
taxonNameURI,
@@ -830,8 +831,10 @@ SELECT DISTINCT ?url ?description WHERE {
* Each `Name` is uniquely determined by its human-readable latin name (for taxa ranking below genus, this is a multi-part name — binomial or trinomial) and kingdom.
*/
export type Name = {
- /** taxonomic kingdom */
- // kingdom: string;
+ /** taxonomic kingdom
+ *
+ * may be empty for some CoL-taxa with missing ancestors */
+ kingdom: string;
/** Human-readable name */
displayName: string;
/** taxonomic rank */
diff --git a/example/index.css b/example/index.css
index 81e8e5b..5a53c40 100644
--- a/example/index.css
+++ b/example/index.css
@@ -114,10 +114,6 @@ syno-treatment,
max-height: 0;
overflow: hidden;
transition: all 200ms;
-
- & img {
- display: none;
- }
}
&.expanded {
@@ -131,10 +127,6 @@ syno-treatment,
.hidden {
max-height: 200rem;
overflow: auto;
-
- & img {
- display: unset;
- }
}
}
}
diff --git a/example/index.ts b/example/index.ts
index ee1f6c3..4a5aee4 100644
--- a/example/index.ts
+++ b/example/index.ts
@@ -333,7 +333,10 @@ class SynoName extends HTMLElement {
const rank_badge = document.createElement("span");
rank_badge.classList.add("rank");
rank_badge.innerText = name.rank;
- title.append(" ", rank_badge);
+ const kingdom_badge = document.createElement("span");
+ kingdom_badge.classList.add("rank");
+ kingdom_badge.innerText = name.kingdom || "Missing Kingdom";
+ title.append(" ", kingdom_badge, " ", rank_badge);
if (name.taxonNameURI) {
const name_uri = document.createElement("a");