Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes for ITIS id matching and removal of wildcard prefix
Datasets config
Fix for parameter ordering
Removing the call to matchByUsageKey from matchByExternalKey - which was bypassing prefix matching
index metadata generation fix for docker
Include breakdown for all ranks
IUCN
#1350
Include atomised name to avoid pipelines and other services reparsing the name
#1350
  • Loading branch information
djtfmartin committed Nov 4, 2024
1 parent 5aa3e90 commit 6db3805
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void run(ApplicationArguments args) {
}

private void initialiseWebapp() {
Optional<APIMetadata> metadata = matchingService.getAPIMetadata(false);
Optional<APIMetadata> metadata = matchingService.getAPIMetadata(true);
if (metadata.isEmpty()) {
log.error("No main index found. Cannot start web services");
return;
Expand Down Expand Up @@ -136,7 +136,8 @@ private void runIndexingIfRequired(ApplicationArguments args) throws Exception {
indexingService.indexIdentifiers(id);
}

log.info("Indexing completed");
matchingService.getAPIMetadata(true);
log.info("Indexing ready");
}

private ExecutionMode getMode(ApplicationArguments args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.stream.Collectors;
import life.catalogue.matching.model.*;
import life.catalogue.matching.service.MatchingService;
import life.catalogue.matching.util.IUCNUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -112,9 +113,13 @@ public NameUsageMatch matchOldPaths(
HttpServletRequest response) {
return matchV2(
usageKey,
taxonID,taxonConceptID,scientificNameID,
scientificName2, scientificName,
authorship, authorship2,
taxonID,
taxonConceptID,
scientificNameID,
scientificName2,
scientificName,
authorship,
authorship2,
genericName,
specificEpithet,
infraspecificEpithet,
Expand Down Expand Up @@ -677,15 +682,15 @@ public Map<String, Object> iucnRedListV1(@PathVariable(value = "usageKey", requi
return Map.of();
}
NameUsageMatch.Status status = statusList.get(0);
String formatted = formatIucn(status.getStatus());
String formatted = IUCNUtils.formatIucn(status.getStatus());
if (formatted == null || formatted.isEmpty()) {
return Map.of();
}

String scientificName = match.getAcceptedUsage() != null ? match.getAcceptedUsage().getCanonicalName() : match.getUsage().getCanonicalName();

try {
IUCN iucn = IUCN.valueOf(formatted); // throws IllegalArgumentException if not found
IUCNUtils.IUCN iucn = IUCNUtils.IUCN.valueOf(formatted); // throws IllegalArgumentException if not found
watch.stop();
log("v1/species/iucnRedListCategory", usageKey, watch);
return Map.of(
Expand All @@ -695,7 +700,7 @@ public Map<String, Object> iucnRedListV1(@PathVariable(value = "usageKey", requi
"taxonomicStatus", NameUsageMatchV1.TaxonomicStatusV1.convert(
match.getDiagnostics().getStatus()),
"iucnTaxonID", status.getSourceId(),
"code", iucn.code
"code", iucn.getCode()
);
} catch (IllegalArgumentException e) {
log.error("IUCN category not found: {}", formatted, e);
Expand Down Expand Up @@ -757,37 +762,6 @@ private static void addIfNotNull(StringJoiner joiner, Object value) {
}
}

String formatIucn(String original){
if (original == null) {
return null;
}
// Trim the string
String trimmed = original.trim();
// Convert to uppercase
String uppercased = trimmed.toUpperCase();
// Replace any whitespace with a single underscore
return uppercased.replaceAll("\\s+", "_");
}

enum IUCN {
EXTINCT("EX"),
EXTINCT_IN_THE_WILD("EW"),
CRITICALLY_ENDANGERED ("CR"),
ENDANGERED ("EN"),
VULNERABLE ("VU"),
NEAR_THREATENED ("NT"),
CONSERVATION_DEPENDENT ("CD"),
LEAST_CONCERN ("LC"),
DATA_DEFICIENT ("DD"),
NOT_EVALUATED ("NE");

private final String code;

IUCN(String code) {
this.code = code;
}
}

@Data
@Builder
@NoArgsConstructor
Expand Down
Loading

0 comments on commit 6db3805

Please sign in to comment.