Skip to content

Commit

Permalink
improved handling of other infraspecific names
Browse files Browse the repository at this point in the history
  • Loading branch information
nleanba committed Oct 30, 2024
1 parent 36d464d commit c80dc94
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 22 deletions.
38 changes: 21 additions & 17 deletions SynonymGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ SELECT DISTINCT ?uri WHERE {
}
${
infrasp
? `?uri dwc:subspecies|dwc:variety|dwc:infraspecificEpithet "${infrasp}" .`
: "FILTER NOT EXISTS { ?uri dwc:subspecies|dwc:variety|dwc:infraspecificEpithet ?infrasp . }"
? `?uri dwc:subSpecies|dwc:variety|dwc:form|dwc:infraspecificEpithet "${infrasp}" .`
: "FILTER NOT EXISTS { ?uri dwc:subSpecies|dwc:variety|dwc:form|dwc:infraspecificEpithet ?infrasp . }"
}
}
LIMIT 500`;
Expand Down Expand Up @@ -242,19 +242,19 @@ SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?species ?infrasp ?name ?authority
}
OPTIONAL {
?tn a dwcFP:TaxonName .
?tn dwc:rank ?rank .
?tn dwc:rank ?trank .
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 ?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 ?infrasp . }
FILTER NOT EXISTS { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
}
} UNION {
FILTER NOT EXISTS { ?col dwc:specificEpithet ?species . }
Expand Down Expand Up @@ -347,11 +347,12 @@ SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?species ?infrasp ?name ?authority
?tn dwc:genus ?genus .
OPTIONAL {
?tn dwc:species ?species .
OPTIONAL { ?tn dwc:subspecies|dwc:variety ?infrasp . }
OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
}
OPTIONAL {
?col dwc:taxonRank ?rank .
?col dwc:taxonRank ?crank .
FILTER(LCASE(?rank) = LCASE(?crank))
OPTIONAL { ?col dwc:scientificNameAuthorship ?colAuth . }
?col dwc:scientificName ?fullName . # Note: contains authority
?col dwc:genericName ?genus .
Expand All @@ -362,10 +363,10 @@ SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?species ?infrasp ?name ?authority
?tn dwc:species ?species .
{
?col dwc:infraspecificEpithet ?infrasp .
?tn dwc:subspecies|dwc:variety ?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 ?infrasp . }
FILTER NOT EXISTS { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
}
} UNION {
FILTER NOT EXISTS { ?col dwc:specificEpithet ?species . }
Expand Down Expand Up @@ -452,11 +453,12 @@ SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?species ?infrasp ?name ?authority
?tn dwc:kingdom ?kingdom .
OPTIONAL {
?tn dwc:species ?species .
OPTIONAL { ?tn dwc:subspecies|dwc:variety ?infrasp . }
OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
}
OPTIONAL {
?col dwc:taxonRank ?rank .
?col dwc:taxonRank ?crank .
FILTER(LCASE(?rank) = LCASE(?crank))
OPTIONAL { ?col dwc:scientificNameAuthorship ?colAuth . }
?col dwc:scientificName ?fullName . # Note: contains authority
?col dwc:genericName ?genus .
Expand All @@ -467,10 +469,10 @@ SELECT DISTINCT ?tn ?tc ?col ?rank ?genus ?species ?infrasp ?name ?authority
?tn dwc:species ?species .
{
?col dwc:infraspecificEpithet ?infrasp .
?tn dwc:subspecies|dwc:variety ?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 ?infrasp . }
FILTER NOT EXISTS { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
}
} UNION {
FILTER NOT EXISTS { ?col dwc:specificEpithet ?species . }
Expand Down Expand Up @@ -562,10 +564,9 @@ LIMIT 500`;
for (const t of json.results.bindings) {
if (t.col) {
const colURI = t.col.value;
console.log(colURI);
if (!authorizedCoLNames.find((e) => e.colURI === colURI)) {
if (this.expanded.has(colURI)) {
console.log("Abbruch: already known", colURI);
console.log("Skipping known", colURI);
return;
}
this.expanded.add(colURI);
Expand Down Expand Up @@ -602,7 +603,7 @@ LIMIT 500`;
cite,
};
} else if (this.expanded.has(t.tc.value)) {
console.log("Abbruch: already known", t.tc.value);
console.log("Skipping known", t.tc.value);
return;
} else {
authorizedTCNames.push({
Expand Down Expand Up @@ -635,6 +636,7 @@ LIMIT 500`;

const name: Name = {
displayName,
rank: json.results.bindings[0].rank!.value,
taxonNameURI,
authorizedNames: [...authorizedCoLNames, ...authorizedTCNames],
justification,
Expand Down Expand Up @@ -1044,6 +1046,8 @@ export type Name = {
// kingdom: string;
/** Human-readable name */
displayName: string;
/** taxonomic rank */
rank: string;

/** vernacular names */
vernacularNames: Promise<vernacularNames>;
Expand Down
2 changes: 2 additions & 0 deletions build_example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as esbuild from "esbuild";
import { denoPlugins } from "@luca/esbuild-deno-loader";

const SERVE = Deno.args.includes("serve");
const BUILD = Deno.args.includes("build");
Expand All @@ -9,6 +10,7 @@ const config: esbuild.BuildOptions = {
sourcemap: true,
bundle: true,
format: "esm",
plugins: [...denoPlugins()],
lineLimit: 120,
minify: BUILD ? true : false,
banner: SERVE
Expand Down
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
]
},
"imports": {
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.11.0",
"esbuild": "npm:esbuild@^0.24.0"
},
"tasks": {
Expand Down
24 changes: 24 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion example/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
box-sizing: border-box;
}

:root {
font-family: Inter, Arial, Helvetica, sans-serif;
}

#root:empty::before {
content: "You should see a list of synonyms here";
}
Expand All @@ -17,11 +21,22 @@ syno-name {
margin: 1rem 0;
}

.rank {
font-size: 0.8rem;
line-height: 1rem;
padding: 0 0.2rem;
margin: 0.2rem 0;
border-radius: 0.2rem;
background: #ededed;
font-weight: normal;
color: #686868;
}

.uri:not(:empty) {
font-size: 0.8rem;
line-height: 1rem;
padding: 0 0.2rem;
margin: 0.2rem;
margin: 0.2rem 0;
border-radius: 0.2rem;
background: #ededed;
font-family: monospace;
Expand Down
15 changes: 11 additions & 4 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SynonymGroup,
type Treatment,
} from "../mod.ts";
import { distinct } from "jsr:@std/collections/distinct";

const params = new URLSearchParams(document.location.search);
const HIDE_COL_ONLY_SYNONYMS = !params.has("show_col");
Expand Down Expand Up @@ -196,6 +197,11 @@ class SynoName extends HTMLElement {
title.append(name_title);
this.append(title);

const rank_badge = document.createElement("span");
rank_badge.classList.add("rank");
rank_badge.innerText = name.rank;
title.append(" ", rank_badge);

if (name.taxonNameURI) {
const name_uri = document.createElement("code");
name_uri.classList.add("taxon", "uri");
Expand All @@ -204,20 +210,21 @@ class SynoName extends HTMLElement {
"",
);
name_uri.title = name.taxonNameURI;
title.append(name_uri);
title.append(" ", name_uri);
}

const justification = document.createElement("abbr");
justification.classList.add("justification");
justification.innerText = "...?";
justify(name).then((just) => justification.title = `This ${just}`);
title.append(justification);
title.append(" ", justification);

const vernacular = document.createElement("code");
const vernacular = document.createElement("div");
vernacular.classList.add("vernacular");
name.vernacularNames.then((names) => {
if (names.size > 0) {
vernacular.innerText = "“" + [...names.values()].join("”, “") + "”";
vernacular.innerText = "“" +
distinct([...names.values()].flat()).join("”, “") + "”";
}
});
this.append(vernacular);
Expand Down

0 comments on commit c80dc94

Please sign in to comment.