Skip to content

Commit

Permalink
Expanding the possible distinct matches for tdwg/bdq#284
Browse files Browse the repository at this point in the history
  • Loading branch information
chicoreus committed Jul 29, 2024
1 parent 0ccace7 commit 55ed25e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -1960,9 +1960,39 @@ public static DQResponse<AmendmentValue> amendmentSexStandardized(
Map<String, String> 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<String, String> 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<String> 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<String, String> 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);
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/filteredpush/qc/metadata/DwCMetadataDQTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 55ed25e

Please sign in to comment.