Skip to content

Commit

Permalink
Expanding the capability of implementations of tdwg/bdq#269, tdwg/bdq…
Browse files Browse the repository at this point in the history
…#276 and tdwg/bdq#278 to recognized variants of controlled vocabulary terms.
  • Loading branch information
chicoreus committed Aug 21, 2024
1 parent 807f585 commit ef990b3
Showing 1 changed file with 101 additions and 6 deletions.
107 changes: 101 additions & 6 deletions src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -1462,8 +1462,40 @@ public static DQResponse<AmendmentValue> amendmentEstablishmentmeansStandardized
values.put("dwc:establishmentMeans", match) ;
result.setValue(new AmendmentValue(values));
} else {
result.addComment("Provided value of dwc:establishmentMeans [" + establishmentMeans + "] unable to be conformed to the the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);

// try a broader net
Iterator<String> i = MetadataSingleton.getInstance().getEstablishmentMeansTerms().keySet().iterator();
boolean matched = false;
String matchKey = "";
while (i.hasNext()) {
String aValue = i.next();
// Try for unique match of abbreviation to first few letters of term, or if a longer string, a substring in the term
String trimValue = establishmentMeans.trim().toLowerCase().replace(".", "");
if (
(aValue.toLowerCase().startsWith(trimValue) && establishmentMeans.endsWith(".") )
||
(trimValue.length()>4 && aValue.toLowerCase().contains(trimValue))
) {
if (!matched) {
matched = true;
matchKey = MetadataSingleton.getInstance().getEstablishmentMeansValues().get(aValue);
} else {
// non-unique match.
matchKey = "";
}
}
}
if (matched && matchKey.length()>0) {
result.addComment("Provided value of dwc:establishmentMeans [" + establishmentMeans + "] conformed to the the sourceAuthority");
result.setResultState(ResultState.AMENDED);
Map<String, String> values = new HashMap<>();
values.put("dwc:establishmentMeans", matchKey) ;
result.setValue(new AmendmentValue(values));
} else {
result.addComment("Provided value of dwc:establishmentMeans [" + establishmentMeans + "] unable to be conformed to the the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);
}

}
}
}
Expand Down Expand Up @@ -1689,8 +1721,39 @@ public static DQResponse<AmendmentValue> amendmentDegreeofestablishmentStandardi
result.setValue(new AmendmentValue(values));
result.addComment("Provided value of dwc:degreeOfEstablishment [" + degreeOfEstablishment + "] conformed to the sourceAuthority");
} else {
result.addComment("Provided value of dwc:degreeOfEstablishment [" + degreeOfEstablishment + "] unable to be conformed to the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);
// try a broader net
Iterator<String> i = MetadataSingleton.getInstance().getDegreeOfEstablishmentTerms().keySet().iterator();
boolean matched = false;
String matchKey = "";
while (i.hasNext()) {
String aValue = i.next();
// Try for unique match of abbreviation to first few letters of term, or if a longer string, a substring in the term
String trimValue = degreeOfEstablishment.trim().toLowerCase().replace(".", "");
if (
(aValue.toLowerCase().startsWith(trimValue) && degreeOfEstablishment.endsWith(".") )
||
(trimValue.length()>4 && aValue.toLowerCase().contains(trimValue))
) {
if (!matched) {
matched = true;
matchKey = MetadataSingleton.getInstance().getDegreeOfEstablishmentValues().get(aValue);
} else {
// non-unique match.
matchKey = "";
}
}
}
if (matched && matchKey.length()>0) {
result.addComment("Provided value of dwc:degreeOfEstablshment [" + degreeOfEstablishment + "] conformed to the the sourceAuthority");
result.setResultState(ResultState.AMENDED);
Map<String, String> values = new HashMap<>();
values.put("dwc:degreeOfEstablishment", matchKey) ;
result.setValue(new AmendmentValue(values));
} else {
result.addComment("Provided value of dwc:degreeOfEstablishment [" + degreeOfEstablishment + "] unable to be conformed to the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);
}

}
}
}
Expand Down Expand Up @@ -1832,8 +1895,40 @@ public static DQResponse<AmendmentValue> amendmentPathwayStandardized(
values.put("dwc:pathway", match) ;
result.setValue(new AmendmentValue(values));
} else {
result.addComment("Provided value of dwc:pathway [" + pathway + "] unable to be conformed to the the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);

// try a broader net
Iterator<String> i = MetadataSingleton.getInstance().getPathwayTerms().keySet().iterator();
boolean matched = false;
String matchKey = "";
while (i.hasNext()) {
String aValue = i.next();
// Try for unique match of abbreviation to first few letters of term, or if a longer string, a substring in the term
String trimValue = pathway.trim().toLowerCase().replace(".", "");
if (
(aValue.toLowerCase().startsWith(trimValue) && pathway.endsWith(".") )
||
(trimValue.length()>4 && aValue.toLowerCase().contains(trimValue))
) {
if (!matched) {
matched = true;
matchKey = MetadataSingleton.getInstance().getPathwayValues().get(aValue);
} else {
// non-unique match.
matchKey = "";
}
}
}
if (matched && matchKey.length()>0) {
result.addComment("Provided value of dwc:pathway [" + pathway + "] conformed to the the sourceAuthority");
result.setResultState(ResultState.AMENDED);
Map<String, String> values = new HashMap<>();
values.put("dwc:pathway", matchKey) ;
result.setValue(new AmendmentValue(values));
} else {
result.addComment("Provided value of dwc:pathway [" + pathway + "] unable to be conformed to the the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);
}

}
}
}
Expand Down

0 comments on commit ef990b3

Please sign in to comment.