Skip to content

Commit

Permalink
updated authorty for Animalia
Browse files Browse the repository at this point in the history
  • Loading branch information
nleanba committed Sep 13, 2024
1 parent 4248d9b commit 8e54ef2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/gg2rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,17 +562,26 @@ export function gg2rdf(

authority = normalizeAuthority(authority);
if (baseAuthority) {
// ensures the baseAuthority is not present twice
authority = authority.replaceAll(
new RegExp(`\\(?${baseAuthority}\\)?[,:;\\s]*`, "g"),
"",
);
}
}
if (baseAuthority && authority) {
s.addProperty(
"dwc:scientificNameAuthorship",
STR(baseAuthority + " " + authority),
);
// Animalia has baseAuthority only in this case, all other Kingdoms get both.
if (getKingdom(cTaxon) === "Animalia") {
s.addProperty(
"dwc:scientificNameAuthorship",
STR(baseAuthority),
);
} else {
s.addProperty(
"dwc:scientificNameAuthorship",
STR(baseAuthority + " " + authority),
);
}
} else if (baseAuthority) {
s.addProperty(
"dwc:scientificNameAuthorship",
Expand Down Expand Up @@ -1241,13 +1250,19 @@ export function gg2rdf(
);
}

/** Get kingdom of taxonName
*
* If `taxonName.getAttribute("kingdom")` is falsy (e.g. null or empty), returns "Animalia".
*/
function getKingdom(taxonName: Element) {
return taxonName.getAttribute("kingdom") || "Animalia";
}

/** returns plain uri
*
* replaces <xsl:call-template name="taxonConceptBaseURI"> */
function taxonConceptBaseURI({ kingdom }: { kingdom: string }) {
return `http://taxon-concept.plazi.org/id/${
kingdom ? partialURI(kingdom) : "Animalia"
}`;
return `http://taxon-concept.plazi.org/id/${kingdom}`;
}

/** returns valid turtle uri
Expand All @@ -1260,7 +1275,7 @@ export function gg2rdf(
},
) {
return URI(
taxonConceptBaseURI({ kingdom: taxonName.getAttribute("kingdom") }) +
taxonConceptBaseURI({ kingdom: getKingdom(taxonName) }) +
taxonNameForURI(taxonName) + taxonAuthority,
);
}
Expand Down

0 comments on commit 8e54ef2

Please sign in to comment.