Commit a5dbf505 authored by Matija Obreza's avatar Matija Obreza
Browse files

Support for hybrid species (Sorghum x almum) (addresses #12)

parent 642d6ddf
......@@ -40,6 +40,8 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
/** The Constant LOG. */
private final static Logger LOG = LoggerFactory.getLogger(InMemoryTaxonomyDatabase.class);
private static final String HYBRID_SPECIES_PREFIX = "x ";
/** The genus id lookup. */
private Map<Long, String> genusIdLookup = new HashMap<>();
......@@ -207,7 +209,15 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
return false;
}
return getAllGenusSpecies(genus).stream().anyMatch(speciesRow -> species.equals(speciesRow.getSpeciesName()));
final boolean isHybrid = StringUtils.startsWith(species, HYBRID_SPECIES_PREFIX);
return getAllGenusSpecies(genus).stream().anyMatch(speciesRow -> {
if (isHybrid) {
return true == speciesRow.getSpecificHybrid() && StringUtils.equals(species.substring(HYBRID_SPECIES_PREFIX.length()), speciesRow.getSpeciesName());
} else {
return StringUtils.equals(species, speciesRow.getSpeciesName());
}
});
}
/*
......@@ -284,9 +294,17 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
return null;
}
final boolean isHybrid = StringUtils.startsWith(species, HYBRID_SPECIES_PREFIX);
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
.filter(speciesRow -> {
if (isHybrid) {
return true == speciesRow.getSpecificHybrid() && StringUtils.equals(species.substring(HYBRID_SPECIES_PREFIX.length()), speciesRow.getSpeciesName());
} else {
return StringUtils.equals(species, speciesRow.getSpeciesName());
}
})
// debug print
.peek(speciesRow -> LOG.trace("Species authority {}", speciesRow.getSpeciesAuthority()))
// keep first match only
......@@ -403,9 +421,18 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
@Override
public List<SpeciesRow> findSpeciesRow(String genus, String species, String subtaxa) {
final boolean isHybrid = StringUtils.startsWith(species, HYBRID_SPECIES_PREFIX);
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
.filter(speciesRow -> {
if (isHybrid) {
return true == speciesRow.getSpecificHybrid() && StringUtils.equals(species.substring(HYBRID_SPECIES_PREFIX.length()), speciesRow.getSpeciesName());
} else {
return StringUtils.equals(species, speciesRow.getSpeciesName());
}
})
// match subtaxa
.filter(speciesRow -> StringUtils.equals(subtaxa, speciesRow.getSubtaxa()))
// to list
......
......@@ -68,7 +68,7 @@ public class TaxonomyCheckerTest extends DatabaseTest {
// assertThat("Checker must prefer the quadrinomial name when provided", CHECKER.suggestSubtaxa("Cucumis", "melo", "subsp. agrestis var. conomon", 1), contains("subsp.
// agrestis var. conomon"));
}
@Test
public void testVignaUnguiculata() {
if (CHECKER == null) {
......@@ -117,10 +117,44 @@ public class TaxonomyCheckerTest extends DatabaseTest {
return;
}
DATABASE.findSimilarGenus("Anizantha", 5);
}
/**
* Aragoptera Allagoptera;Gonoptera;Ragiopteris;Isoptera;Otoptera
*/
/**
* Sorghum x almum
*/
@Test
public void testSorghumXalmum() {
if (CHECKER == null) {
return;
}
assertThat("Sorghum almum is a valid species", DATABASE.containsSpecies("Sorghum", "almum"), equalTo(true));
assertThat("Sorghum x almum is a valid species", DATABASE.containsSpecies("Sorghum", "x almum"), equalTo(true));
assertThat("Sorghum almum is only one species", DATABASE.findSpeciesRow("Sorghum", "almum", null), hasSize(1));
assertThat("Sorghum x almum is only one species", DATABASE.findSpeciesRow("Sorghum", "x almum", null), hasSize(1));
}
/**
* Sorghum x almum Parodi
*/
@Test
public void testSorghumXalmumParodi() {
if (CHECKER == null) {
return;
}
assertThat("Sorghum x almum is a valid species", DATABASE.containsSpecies("Sorghum", "x almum"), equalTo(true));
assertThat("Parodi is authority for species Sorghum almum", DATABASE.getSpeciesAuthority("Sorghum", "almum"), equalTo("Parodi"));
assertThat("Parodi is authority for species Sorghum x almum", DATABASE.getSpeciesAuthority("Sorghum", "x almum"), equalTo("Parodi"));
assertThat("Parodi is authority for species Sorghum almum", CHECKER.getSpeciesAuthority("Sorghum", "almum"), equalTo("Parodi"));
assertThat("Parodi is authority for species Sorghum x almum", CHECKER.getSpeciesAuthority("Sorghum", "x almum"), equalTo("Parodi"));
}
/**
* GENUS=Sesbania and SPECIES=sesban x goetzei
*/
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment