Commit 642d6ddf authored by Matija Obreza's avatar Matija Obreza
Browse files

Handle unknowns better (fixes #19)

parent 196bd159
......@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -31,6 +32,12 @@ import org.slf4j.LoggerFactory;
*/
public class TaxonomyChecker {
private static final String UNKNOWN_GENUS = "Unknown";
private static final String[] UNKNOWN_GENUS_ALT = { UNKNOWN_GENUS, "Unidentified" };
private static final String UNKNOWN_SPECIES = "sp.";
private static final String[] UNKNOWN_SPECIES_ALT = { UNKNOWN_SPECIES, "spp." };
/** The Constant LOG. */
private final static Logger LOG = LoggerFactory.getLogger(TaxonomyChecker.class);
......@@ -54,8 +61,8 @@ public class TaxonomyChecker {
* @return suggested fixes for genus or empty list when genus is fine or when there are no suggestions.
*/
public List<String> suggestGenus(String genus, int maxSize) {
if (StringUtils.isBlank(genus) || StringUtils.equals("Unknown", genus)) {
return Arrays.asList("Unknown");
if (StringUtils.isBlank(genus) || ArrayUtils.contains(UNKNOWN_GENUS_ALT, genus)) {
return Arrays.asList(UNKNOWN_GENUS);
} else if (database.containsGenus(genus)) {
LOG.trace("Database contains genus={}", genus);
return Arrays.asList(genus);
......@@ -75,6 +82,11 @@ public class TaxonomyChecker {
*/
public List<String> suggestSpecies(String genus, String species, int maxSize) {
LOG.debug("Suggesting species for genus={} species={}", genus, species);
if (StringUtils.isBlank(species) || ArrayUtils.contains(UNKNOWN_GENUS_ALT, genus) || ArrayUtils.contains(UNKNOWN_SPECIES_ALT, species)) {
return Arrays.asList(UNKNOWN_SPECIES);
}
if (database.containsSpecies(genus, species)) {
return Arrays.asList(species);
}
......
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