From 55ed25efe5eb6e29365e7dfce86c4cd8e81db044 Mon Sep 17 00:00:00 2001 From: chicoreus Date: Sun, 28 Jul 2024 21:56:34 -0400 Subject: [PATCH] Expanding the possible distinct matches for tdwg/bdq#284 --- .../qc/metadata/DwCMetadataDQ.java | 34 +++++++++++++++++-- .../qc/metadata/DwCMetadataDQTest.java | 14 ++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java b/src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java index b13bf15..e28f8bd 100644 --- a/src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java +++ b/src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java @@ -1960,9 +1960,39 @@ public static DQResponse amendmentSexStandardized( Map values = new HashMap<>(); values.put("dwc:sex", match) ; result.setValue(new AmendmentValue(values)); + } else if (MetadataSingleton.getInstance().getSexValues().containsKey(sex.trim().toLowerCase().replace(".",""))) { + String match = MetadataSingleton.getInstance().getSexValues().get(sex.trim().toLowerCase()); + result.setResultState(ResultState.AMENDED); + Map values = new HashMap<>(); + values.put("dwc:sex", match) ; + result.setValue(new AmendmentValue(values)); } else { - result.addComment("Provided value of dwc:sex [" + sex + "] unable to be conformed to the the sourceAuthority"); - result.setResultState(ResultState.NOT_AMENDED); + Iterator i = MetadataSingleton.getInstance().getSexTerms().keySet().iterator(); + boolean matched = false; + String matchKey = ""; + while (i.hasNext()) { + String aValue = i.next(); + logger.debug(aValue); + if (aValue.toLowerCase().startsWith(sex.trim().toLowerCase())) { + if (!matched) { + matched = true; + matchKey = MetadataSingleton.getInstance().getSexValues().get(aValue); + } else { + // non-unique match. + matchKey = ""; + } + } + } + if (matched && matchKey.length()>0) { + result.addComment("Provided value of dwc:sex [" + sex + "] conformed to the the sourceAuthority"); + result.setResultState(ResultState.AMENDED); + Map values = new HashMap<>(); + values.put("dwc:sex", matchKey) ; + result.setValue(new AmendmentValue(values)); + } else { + result.addComment("Provided value of dwc:sex [" + sex + "] unable to be conformed to the the sourceAuthority"); + result.setResultState(ResultState.NOT_AMENDED); + } } } } diff --git a/src/test/java/org/filteredpush/qc/metadata/DwCMetadataDQTest.java b/src/test/java/org/filteredpush/qc/metadata/DwCMetadataDQTest.java index b8c6d29..1a516d4 100644 --- a/src/test/java/org/filteredpush/qc/metadata/DwCMetadataDQTest.java +++ b/src/test/java/org/filteredpush/qc/metadata/DwCMetadataDQTest.java @@ -897,6 +897,20 @@ public void testAmendmentSexStandardized() { assertNotNull(result.getComment()); } } + + sex = "m"; // could match male or mixed + result = DwCMetadataDQ.amendmentSexStandardized(sex, null); + logger.debug(result.getComment()); + assertEquals(ResultState.NOT_AMENDED.getLabel(), result.getResultState().getLabel()); + assertNull(result.getValue()); + assertNotNull(result.getComment()); + + sex = "f"; + result = DwCMetadataDQ.amendmentSexStandardized(sex, null); + logger.debug(result.getComment()); + assertEquals(ResultState.AMENDED.getLabel(), result.getResultState().getLabel()); + assertEquals("Female",result.getValue().getObject().get("dwc:sex")); + assertNotNull(result.getComment()); } /**