Skip to content

Commit

Permalink
fixed queries to be usable with lindas
Browse files Browse the repository at this point in the history
  • Loading branch information
nleanba committed Nov 5, 2024
1 parent 936a99c commit 9663f68
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 58 deletions.
84 changes: 33 additions & 51 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 ?species ?infrasp ?name ?authority
SELECT DISTINCT ?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 ?species ?infrasp ?name ?authority
* As its own variable to ensure consistency in the resturned bindings.
*/
const postamble =
`GROUP BY ?tn ?tc ?col ?rank ?genus ?species ?infrasp ?name ?authority`;
`GROUP BY ?tn ?tc ?col ?rank ?genus ?subgenus ?species ?infrasp ?name ?authority`;

// For unclear reasons, the queries breaks if the limit is removed.

Expand All @@ -36,14 +36,14 @@ export const getNameFromCol = (colUri: string) =>
`${preamble} WHERE {
BIND(<${colUri}> as ?col)
?col dwc:taxonRank ?rank .
OPTIONAL { ?col dwc:scientificNameAuthorship ?colAuth . } BIND(COALESCE(?colAuth, "") as ?authority)
?col dwc:scientificName ?name .
?col dwc:genericName ?genus .
# TODO # ?col dwc:parent* ?p . ?p dwc:rank "kingdom" ; dwc:taxonName ?kingdom .
OPTIONAL {
?col dwc:specificEpithet ?species .
OPTIONAL { ?col dwc:infraspecificEpithet ?infrasp . }
}
OPTIONAL { ?col dwc:scientificNameAuthorship ?authority . }
OPTIONAL {
?tn dwc:rank ?trank ;
Expand Down Expand Up @@ -113,40 +113,31 @@ export const getNameFromTC = (tcUri: string) =>
a dwcFP:TaxonConcept .
?tn a dwcFP:TaxonName .
?tn dwc:rank ?rank .
?tn dwc:rank ?tnrank .
?tn dwc:kingdom ?kingdom .
?tn dwc:genus ?genus .
OPTIONAL { ?tn dwc:subGenus ?subgenus . }
OPTIONAL {
?tn dwc:species ?species .
OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
?tn dwc:species ?tnspecies .
OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?tninfrasp . }
}
BIND(LCASE(?tnrank) AS ?rank)
BIND(COALESCE(?tnspecies, "") AS ?species)
BIND(COALESCE(?tninfrasp, "") AS ?infrasp)
OPTIONAL {
?col dwc:taxonRank ?crank .
FILTER(LCASE(?rank) = LCASE(?crank))
OPTIONAL { ?col dwc:scientificNameAuthorship ?colAuth . }
?col dwc:scientificName ?fullName . # Note: contains authority
?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 .
{
?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 . }
}
OPTIONAL { ?col dwc:specificEpithet ?colspecies . }
FILTER(?species = COALESCE(?colspecies, ""))
OPTIONAL { ?col dwc:infraspecificEpithet ?colinfrasp . }
FILTER(?infrasp = COALESCE(?colinfrasp, ""))
OPTIONAL { ?col dwc:scientificNameAuthorship ?authority . }
}
BIND(COALESCE(?fullName, CONCAT(?genus, COALESCE(CONCAT(" (",?subgenus,")"), ""), COALESCE(CONCAT(" ",?species), ""), COALESCE(CONCAT(" ", ?infrasp), ""))) as ?name)
BIND(COALESCE(?colAuth, "") as ?authority)
OPTIONAL {
?trtnt trt:treatsTaxonName ?tn ; trt:publishedIn/dc:date ?trtndate .
Expand Down Expand Up @@ -186,40 +177,31 @@ export const getNameFromTN = (tnUri: string) =>
`${preamble} WHERE {
BIND(<${tnUri}> as ?tn)
?tn a dwcFP:TaxonName .
?tn dwc:rank ?rank .
?tn dwc:rank ?tnrank .
?tn dwc:genus ?genus .
?tn dwc:kingdom ?kingdom .
OPTIONAL { ?tn dwc:subGenus ?subgenus . }
OPTIONAL {
?tn dwc:species ?species .
OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?infrasp . }
?tn dwc:species ?tnspecies .
OPTIONAL { ?tn dwc:subSpecies|dwc:variety|dwc:form ?tninfrasp . }
}
BIND(LCASE(?tnrank) AS ?rank)
BIND(COALESCE(?tnspecies, "") AS ?species)
BIND(COALESCE(?tninfrasp, "") AS ?infrasp)
OPTIONAL {
?col dwc:taxonRank ?crank .
FILTER(LCASE(?rank) = LCASE(?crank))
OPTIONAL { ?col dwc:scientificNameAuthorship ?colAuth . }
?col dwc:scientificName ?fullName . # Note: contains authority
?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 .
{
?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 . }
}
OPTIONAL { ?col dwc:specificEpithet ?colspecies . }
FILTER(?species = COALESCE(?colspecies, ""))
OPTIONAL { ?col dwc:infraspecificEpithet ?colinfrasp . }
FILTER(?infrasp = COALESCE(?colinfrasp, ""))
OPTIONAL { ?col dwc:scientificNameAuthorship ?authority . }
}
BIND(COALESCE(?fullName, CONCAT(?genus, COALESCE(CONCAT(" (",?subgenus,")"), ""), COALESCE(CONCAT(" ",?species), ""), COALESCE(CONCAT(" ", ?infrasp), ""))) as ?name)
BIND(COALESCE(?colAuth, "") as ?authority)
OPTIONAL {
?trtnt trt:treatsTaxonName ?tn ; trt:publishedIn/dc:date ?trtndate .
Expand Down
44 changes: 37 additions & 7 deletions SynonymGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,41 @@ LIMIT 500`;
): Promise<void> {
const treatmentPromises: Treatment[] = [];

const displayName: string = json.results.bindings[0].name!.value
.replace(
json.results.bindings[0].authority?.value ?? "",
"",
).trim();
const abbreviateRank = (rank: string) => {
switch (rank) {
case "variety":
return "var.";
case "subspecies":
return "subsp.";
case "form":
return "f.";
default:
return rank;
}
};

const displayName: string = (json.results.bindings[0].name
? (
json.results.bindings[0].authority
? json.results.bindings[0].name.value
.replace(
json.results.bindings[0].authority.value,
"",
)
: json.results.bindings[0].name.value
)
: json.results.bindings[0].genus!.value +
(json.results.bindings[0].subgenus?.value
? ` (${json.results.bindings[0].subgenus.value})`
: "") +
(json.results.bindings[0].species?.value
? ` ${json.results.bindings[0].species.value}`
: "") +
(json.results.bindings[0].infrasp?.value
? ` ${abbreviateRank(json.results.bindings[0].rank!.value)} ${
json.results.bindings[0].infrasp.value
}`
: "")).trim();

// Case where the CoL-taxon has no authority. There should only be one of these.
let unathorizedCol: string | undefined;
Expand Down Expand Up @@ -469,11 +499,11 @@ SELECT DISTINCT ?current ?current_status (GROUP_CONCAT(DISTINCT ?dpr; separator=
{
?col dwc:acceptedName ?current .
?dpr dwc:acceptedName ?current .
?current dwc:taxonomicStatus ?current_status .
OPTIONAL { ?current dwc:taxonomicStatus ?current_status . }
} UNION {
?col dwc:taxonomicStatus ?current_status .
OPTIONAL { ?dpr dwc:acceptedName ?col . }
FILTER NOT EXISTS { ?col dwc:acceptedName ?current . }
FILTER NOT EXISTS { ?col dwc:acceptedName ?_ . }
BIND(?col AS ?current)
}
}
Expand Down

0 comments on commit 9663f68

Please sign in to comment.