Commit 83f039c5 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fixed #18: include speciesId when SUBTEXT is actually blank

parent 083ccced
......@@ -286,7 +286,7 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> species.equals(speciesRow.getSpeciesName()))
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
// debug print
.peek(speciesRow -> LOG.trace("Species authority {}", speciesRow.getSpeciesAuthority()))
// keep first match only
......@@ -310,9 +310,9 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
return getAllGenusSpecies(genus).stream()
// keep matching speciesRows within genues
.filter(speciesRow -> species.equals(speciesRow.getSpeciesName()))
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
// return true if one row has exact match on SUBTAXA
.anyMatch(speciesRow -> subtaxa.equals(speciesRow.getSubtaxa()));
.anyMatch(speciesRow -> StringUtils.equals(subtaxa, speciesRow.getSubtaxa()));
}
/*
......@@ -376,9 +376,9 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> species.equals(speciesRow.getSpeciesName()))
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
// keep rows with matching subtaxa
.filter(speciesRow -> subtaxa.equals(speciesRow.getSubtaxa()))
.filter(speciesRow -> StringUtils.equals(subtaxa, speciesRow.getSubtaxa()))
// debug print
.peek(speciesRow -> LOG.trace("Subtaxa authority {}", speciesRow.getSubtaxaAuthority()))
// keep first match only
......@@ -396,7 +396,7 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
public List<SpeciesRow> listSpecies(String genus, String species, int maxSize) {
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> species.equals(speciesRow.getSpeciesName()))
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
// limit results to maxSize
.limit(maxSize).collect(Collectors.toList());
}
......@@ -405,9 +405,9 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
public List<SpeciesRow> findSpeciesRow(String genus, String species, String subtaxa) {
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> species.equals(speciesRow.getSpeciesName()))
.filter(speciesRow -> StringUtils.equals(species, speciesRow.getSpeciesName()))
// match subtaxa
.filter(speciesRow -> subtaxa.equals(speciesRow.getSubtaxa()))
.filter(speciesRow -> StringUtils.equals(subtaxa, speciesRow.getSubtaxa()))
// to list
.collect(Collectors.toList());
}
......
......@@ -19,11 +19,13 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.genesys2.gringlobal.taxonomy.component.BestScore;
import org.genesys2.gringlobal.taxonomy.component.InMemoryTaxonomyDatabase;
import org.genesys2.gringlobal.taxonomy.component.StringSimilarity;
import org.genesys2.gringlobal.taxonomy.component.TaxonomyChecker;
import org.genesys2.gringlobal.taxonomy.model.SpeciesRow;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -66,6 +68,15 @@ 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) {
return;
}
List<SpeciesRow> unguiculatas = DATABASE.findSpeciesRow("Vigna", "unguiculata", null);
assertThat("Vigna unguiculata exists", unguiculatas, hasSize(1));
}
/**
* Anthirrhinum gives Antirrhinum;Acanthorrhinum;Anarrhinum
......
......@@ -391,7 +391,7 @@ public class GGTC {
}
if (outputHeaders.indexOf(HEADER_GRINTAX_SPECIESID) >= 0) {
List<SpeciesRow> speciesRows = taxonomyDatabase.findSpeciesRow(genus, species, StringUtils.defaultIfBlank(subtaxa, ""));
List<SpeciesRow> speciesRows = taxonomyDatabase.findSpeciesRow(genus, species, StringUtils.defaultIfBlank(subtaxa, null));
if (speciesRows.size() == 1) {
SpeciesRow speciesRow = speciesRows.get(0);
outputLine[outputHeaders.indexOf(HEADER_GRINTAX_SPECIESID)] = speciesRow.getSpeciesId().toString();
......
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