Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- better species matching against bie
  • Loading branch information
temi committed Apr 9, 2024
1 parent 5c5e786 commit e68ecec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
18 changes: 10 additions & 8 deletions grails-app/services/au/org/ala/ecodata/MetadataService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -844,14 +844,16 @@ class MetadataService {
data
}

Map autoPopulateSpeciesData(Map data){
if (!data?.guid && (data?.scientificName ?: data?.commonName)) {
def result = speciesReMatchService.searchBie(data.scientificName?: data.commonName, 10)
// only if there is a single match
if (result?.autoCompleteList?.size() == 1) {
data.guid = result?.autoCompleteList[0]?.guid
data.commonName = data.commonName ?: result?.autoCompleteList[0]?.commonName
data.scientificName = data.scientificName ?: result?.autoCompleteList[0]?.name
Map autoPopulateSpeciesData (Map data, int limit = 10) {
String searchName = (data?.scientificName)?.trim()
if (!data?.guid && (searchName)) {
def result = speciesReMatchService.searchBie(searchName, limit)
// find the name that exactly matches the search name
def bestMatch = result?.autoCompleteList?.find { it.matchedNames?.findResult { String name -> name.equalsIgnoreCase(searchName) } }
if (bestMatch) {
data.guid = bestMatch?.guid
data.commonName = data.commonName ?: bestMatch?.commonName
data.scientificName = data.scientificName ?: bestMatch?.name
}
}

Expand Down
8 changes: 8 additions & 0 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,14 @@ class ParatooService {
}

metadataService.autoPopulateSpeciesData(result)
// try again with common name
if ((result.guid == null) && result.commonName) {
def speciesObject = [scientificName: result.commonName]
metadataService.autoPopulateSpeciesData(speciesObject)
result.guid = speciesObject.guid
result.scientificName = result.scientificName ?: speciesObject.scientificName
}

// record is only created if guid is present
result.guid = result.guid ?: "A_GUID"
result
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
then:
outputSpeciesId != null
result == [name: "Acacia glauca Willd.", scientificName: "Acacia glauca Willd.", guid: "A_GUID", commonName: "Acacia glauca", taxonRank: "Species"]
1 * metadataService.autoPopulateSpeciesData(_) >> null
2 * metadataService.autoPopulateSpeciesData(_) >> null

when: // no scientific name
result = service.transformSpeciesName("Frogs [Class] (scientific: )")
Expand All @@ -496,7 +496,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
then:
outputSpeciesId != null
result == [name: "Frogs", scientificName: "", guid: "A_GUID", commonName: "Frogs", taxonRank: "Class"]
1 * metadataService.autoPopulateSpeciesData(_) >> null
2 * metadataService.autoPopulateSpeciesData(_) >> null
}

void "buildRelationshipTree should build relationship tree correctly"() {
Expand Down

0 comments on commit e68ecec

Please sign in to comment.