Skip to content

Commit

Permalink
handle kingdoms
Browse files Browse the repository at this point in the history
  • Loading branch information
nleanba committed Nov 8, 2024
1 parent 9663f68 commit 46d1d35
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 32 deletions.
34 changes: 14 additions & 20 deletions Queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PREFIX dwc: <http://rs.tdwg.org/dwc/terms/>
PREFIX dwcFP: <http://filteredpush.org/ontologies/oa/dwcFP#>
PREFIX cito: <http://purl.org/spar/cito/>
PREFIX trt: <http://plazi.org/vocab/treatment#>
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)
Expand All @@ -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.

Expand All @@ -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 . }
Expand All @@ -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 .
Expand Down Expand Up @@ -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, ""))
Expand Down Expand Up @@ -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, ""))
Expand Down
1 change: 0 additions & 1 deletion SparqlEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// deno-lint-ignore-file no-unused-labels
async function sleep(ms: number): Promise<void> {
const p = new Promise<void>((resolve) => {
setTimeout(resolve, ms);
Expand Down
7 changes: 5 additions & 2 deletions SynonymGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down
8 changes: 0 additions & 8 deletions example/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ syno-treatment,
max-height: 0;
overflow: hidden;
transition: all 200ms;

& img {
display: none;
}
}

&.expanded {
Expand All @@ -131,10 +127,6 @@ syno-treatment,
.hidden {
max-height: 200rem;
overflow: auto;

& img {
display: unset;
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 46d1d35

Please sign in to comment.