Skip to content

Commit

Permalink
Merge pull request #43 from DiSSCo/feature/additional-abcd-mapping
Browse files Browse the repository at this point in the history
Add additional mapping ABCD
  • Loading branch information
samleeflang authored Oct 18, 2023
2 parents 8355b14 + 4081818 commit 2e92f98
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class BioCaseService implements WebClientService {
private static final List<String> allowedBasisOfRecord = List.of("PRESERVEDSPECIMEN", "FOSSIL",
"OTHER", "ROCK", "MINERAL", "METEORITE", "FOSSILSPECIMEN", "LIVINGSPECIMEN", "MATERIALSAMPLE",
"FOSSIL SPECIMEN", "ROCKSPECIMEN", "ROCK SPECIMEN", "MINERALSPECIMEN", "MINERAL SPECIMEN",
"METEORITESPECIMEN", "METEORITE SPECIMEN");
"METEORITESPECIMEN", "METEORITE SPECIMEN", "HERBARIUM SHEET", "HERBARIUMSHEET", "DRIED");

private final ObjectMapper mapper;
private final WebClientProperties webClientProperties;
Expand Down Expand Up @@ -203,7 +203,7 @@ private void processUnit(DataSet dataset, Unit unit)
}
} else {
log.info("Record with record basis: {} and id: {} is ignored ", unit.getRecordBasis(),
unit.getUnitGUID());
unit.getUnitID());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ private String getNormalisedPhysicalSpecimenId(OdsPhysicalSpecimenIdType physica
|| physicalSpecimenIdType.equals(OdsPhysicalSpecimenIdType.RESOLVABLE)) {
return physicalSpecimenId;
} else {
var minifiedSourceSystemId = sourceSystemId.substring(sourceSystemId.indexOf('/') + 1);
var minifiedSourceSystemId = sourceSystemId.substring(sourceSystemId.lastIndexOf('/') + 1);
return physicalSpecimenId + ":" + minifiedSourceSystemId;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ private static List<String> identifierTerms() {
list.add("abcd:unitIDNumeric");
list.add("abcd:unitGUID");
list.add("abcd:recordURI");
// For now just look at the two first accession numbers as a shortcut
list.add("abcd:specimenUnit/accessions/accessionDateAndAccessionCatalogueAndAccessionNumber/0/value");
list.add("abcd:specimenUnit/accessions/accessionDateAndAccessionCatalogueAndAccessionNumber/1/value");
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class BasisOfRecord extends Term {

public static final String TERM = DWC_PREFIX + "basisOfRecord";

private static final List<String> PRESERVED_SPECIMEN_ALTERNATIVES = List.of("HERBARIUM SHEET",
"HERBARIUMSHEET", "DRIED");
private final List<String> dwcaTerms = List.of(TERM);
private final List<String> abcdTerms = List.of("abcd:recordBasis");

Expand All @@ -18,7 +19,11 @@ public String retrieveFromDWCA(JsonNode unit) {

@Override
public String retrieveFromABCD(JsonNode unit) {
return super.searchJsonForTerm(unit, abcdTerms);
var result = super.searchJsonForTerm(unit, abcdTerms);
if (result != null && PRESERVED_SPECIMEN_ALTERNATIVES.contains(result.toUpperCase())) {
return "Preserved specimen";
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Preparations extends Term {

public static final String TERM = DWC_PREFIX + "preparations";
private final List<String> dwcaTerms = List.of("dwc:preparations");
private final List<String> abcdTerms = List.of("abcd:kindOfUnit/0/value");
private final List<String> abcdTerms = List.of("abcd:kindOfUnit/0/value", "abcd:specimenUnit/preparations/preparation/0/preparationType/value");

@Override
public String retrieveFromDWCA(JsonNode unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class IdentifiedBy extends Term {

public static final String TERM = DWC_PREFIX + "identifiedBy";

private final List<String> dwcaTerms = List.of(TERM);
private final List<String> dwcaTerms = List.of(TERM, "dwc:identifiedByID");

private final List<String> abcdTerms = List.of("identifiers/identifier/0/personName/fullName");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class Genus extends AbstractTaxonomy {

private final List<String> dwcaTerms = List.of(TERM);
private final List<String> abcdTerms = List.of(
"result/taxonIdentified/scientificName/nameAtomised/botanical/genusOrMonomial");
"result/taxonIdentified/scientificName/nameAtomised/botanical/genusOrMonomial",
"result/taxonIdentified/scientificName/nameAtomised/zoological/genusOrMonomial");

@Override
public String retrieveFromDWCA(JsonNode unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class ScientificName extends AbstractTaxonomy {
private final List<String> dwcaTerms = List.of("dwc:scientificName");
private final List<String> abcdTerms = List.of(
"result/taxonIdentified/scientificName/fullScientificNameString",
"result/mineralRockIdentified/classifiedName/fullScientificNameString");
"result/mineralRockIdentified/classifiedName/fullScientificNameString",
"result/taxonIdentified/informalNameString/value",
"result/taxonIdentified/scientificName/nameAtomised/zoological/namedIndividual");

@Override
public String retrieveFromDWCA(JsonNode unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
import static eu.dissco.core.translator.TestUtils.MAPPER;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class BasisOfRecordTest {

private final BasisOfRecord basisOfRecord = new BasisOfRecord();

public static Stream<Arguments> prepareABCDRecordBasis() {
return Stream.of(
Arguments.of("PreservedSpecimen", "PreservedSpecimen"),
Arguments.of("RockSpecimen", "RockSpecimen"),
Arguments.of("HerbariumSheet", "Preserved specimen"),
Arguments.of("Dried", "Preserved specimen"),
Arguments.of(null, null)
);
}

@Test
void testRetrieveFromDWCA() {
// Given
Expand All @@ -25,32 +39,21 @@ void testRetrieveFromDWCA() {
assertThat(result).isEqualTo("LivingSpecimen");
}

@Test
void testRetrieveFromDWCANotLiving() {
// Given
var unit = MAPPER.createObjectNode();
unit.put("dwc:basisOfRecord", "PreservedSpecimen");

// When
var result = basisOfRecord.retrieveFromDWCA(unit);

// Then
assertThat(result).isEqualTo("PreservedSpecimen");
}

@Test
void testRetrieveFromABCD() {
@ParameterizedTest
@MethodSource("prepareABCDRecordBasis")
void testRetrieveFromABCD(String recordBasis, String expected) {
// Given
var unit = MAPPER.createObjectNode();
unit.put("abcd:recordBasis", "RockSpecimen");
unit.put("abcd:recordBasis", recordBasis);

// When
var result = basisOfRecord.retrieveFromABCD(unit);

// Then
assertThat(result).isEqualTo("RockSpecimen");
assertThat(result).isEqualTo(expected);
}


@Test
void testGetTerm() {
// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ void testRetrieveFromABCD() {
assertThat(result).isEqualTo("Arrabidaea");
}

@Test
void testRetrieveFromABCDZoology() {
// Given
var unit = MAPPER.createObjectNode();
unit.put(
"result/taxonIdentified/scientificName/nameAtomised/zoological/genusOrMonomial",
"Alchemilla");

// When
var result = genus.retrieveFromABCD(unit);

// Then
assertThat(result).isEqualTo("Alchemilla");
}

@Test
void testGetTerm() {
// When
Expand Down

0 comments on commit 2e92f98

Please sign in to comment.