Class InMemoryTaxonomyDatabase

java.lang.Object
org.genesys.taxonomy.checker.InMemoryTaxonomyDatabase
All Implemented Interfaces:
TaxonomyDatabase
Direct Known Subclasses:
CachingInMemoryTaxonomyDatabase

public class InMemoryTaxonomyDatabase extends Object implements TaxonomyDatabase
List based in-memory "database". NOT THREAD-SAFE!
  • Field Details

    • NONMATCH_MARGIN

      public static final double NONMATCH_MARGIN
      Percentage margin from best score. Matches with scores below bestScore * margin are ignored.
      See Also:
  • Constructor Details

    • InMemoryTaxonomyDatabase

      public InMemoryTaxonomyDatabase()
  • Method Details

    • registerGenus

      public void registerGenus(Long genusId, String genus)
      Add a genus to the database.
      Parameters:
      genusId - the genus id
      genus - the genus
    • registerSpecies

      public void registerSpecies(org.genesys.taxonomy.gringlobal.model.IGrinSpecies speciesRow) throws TaxonomyException
      Add species to the database.
      Parameters:
      speciesRow - the species row
      Throws:
      TaxonomyException - the taxonomy exception
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • containsGenus

      public boolean containsGenus(String genus)
      Case insensitive search for genus.
      Specified by:
      containsGenus in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      Returns:
      true, if successful
    • findSimilarGenera

      public List<String> findSimilarGenera(String genus, int maxSize)
      Find similar genera. Unlike findSimilarGenus(String, int), this method will look for similar names regardless of input.
      Parameters:
      genus - base search name
      maxSize - max matches to return
      Returns:
      List of names
    • findSimilarGenus

      public List<String> findSimilarGenus(String genus, int maxSize)
      If genus is registered return empty list, otherwise search for similar genera.
      Specified by:
      findSimilarGenus in interface TaxonomyDatabase
      Parameters:
      genus - base search name
      maxSize - max matches to return
      Returns:
      list of suggestions, ordered by preference (best first), never null.
    • print

      public static <T> void print(Suggestion<T> suggestion)
      Prints the.
      Type Parameters:
      T - the generic type
      Parameters:
      suggestion - the suggestion
    • print

      public static void print(Object suggestion)
      Prints the.
      Parameters:
      suggestion - the suggestion
    • getAllGenusSpecies

      protected List<org.genesys.taxonomy.gringlobal.model.IGrinSpecies> getAllGenusSpecies(@NonNull @NonNull String genus)
      Get all species for one genus
      Parameters:
      genus - genus name
      Returns:
      list of species, never null
    • getAllGenusSpecies

      protected List<org.genesys.taxonomy.gringlobal.model.IGrinSpecies> getAllGenusSpecies(@NonNull @NonNull List<String> genera)
      Gets the all species for specified genera.
      Parameters:
      genera - the list of genera
      Returns:
      the all genus species
    • containsSpecies

      public boolean containsSpecies(String genus, String species)
      Description copied from interface: TaxonomyDatabase
      Does the database contain at least one record that exactly matches specified genus and species?.
      Specified by:
      containsSpecies in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      Returns:
      true if there is at least one record
    • containsSpecies

      public boolean containsSpecies(String genus, String species, String spAuthor)
      Description copied from interface: TaxonomyDatabase
      Does the database contain at least one record that exactly matches specified genus and species?.
      Specified by:
      containsSpecies in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      spAuthor - species authority
      Returns:
      true if there is at least one record
    • findSimilar

      public List<TaxonomyChecker.Taxon> findSimilar(String genus, String species, String spAuthor, String subtaxa, String subtAuthor, int maxSize)
      Description copied from interface: TaxonomyDatabase
      Suggest a list of matches.
      Specified by:
      findSimilar in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      spAuthor - species authority
      subtaxa - subtaxa to check
      subtAuthor - species authority at the lowest classification level
      maxSize - maximum number of suggestions to return
      Returns:
      list of suggestions, ordered by preference, never null
    • findSimilarSpecies

      public List<String> findSimilarSpecies(String genus, String species, String spAuthor, int maxSize)
      Description copied from interface: TaxonomyDatabase
      Return a list of species close to the specified genus and species.
      Specified by:
      findSimilarSpecies in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - species
      spAuthor - species authority
      maxSize - maximum number of suggestions to return
      Returns:
      list of suggestions, ordered by preference (best first), never null.
    • similarityScore

      public double similarityScore(String original, String candidate)
      similarityScore returns a string similarity value in the range [0, 1.0] (where 1.0 is full match).
      Specified by:
      similarityScore in interface TaxonomyDatabase
      Parameters:
      original - the original
      candidate - the candidate
      Returns:
      the score between 0 and 1.0 where 0 is no similarity and 1.0 is full match
    • getSpeciesAuthority

      public List<String> getSpeciesAuthority(String genus, String species)
      Description copied from interface: TaxonomyDatabase
      Return the species authority for the specified species within genus.
      Specified by:
      getSpeciesAuthority in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      Returns:
      the authority or null
    • getSpeciesAuthority

      public List<String> getSpeciesAuthority(String genus, String species, String spAuthor)
      Description copied from interface: TaxonomyDatabase
      Return the species authority for the specified species within genus.
      Specified by:
      getSpeciesAuthority in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      spAuthor - species authority
      Returns:
      the authority or null
    • containsSubtaxa

      public boolean containsSubtaxa(String genus, String species, String subtaxa)
      Description copied from interface: TaxonomyDatabase
      Does the database contain at least one record that exactly matches specified genus, species and subtaxa?.
      Specified by:
      containsSubtaxa in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      subtaxa - subtaxa to check
      Returns:
      true if there is at least one record
    • containsSubtaxa

      public boolean containsSubtaxa(String genus, String species, String spAuthor, String subtaxa, String subtAuthor)
      Description copied from interface: TaxonomyDatabase
      Does the database contain at least one record that exactly matches specified genus, species and subtaxa?.
      Specified by:
      containsSubtaxa in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      spAuthor - species authority
      subtaxa - subtaxa to check
      subtAuthor - species authority at the lowest classification level
      Returns:
      true if there is at least one record
    • findSimilarSubtaxa

      public List<String> findSimilarSubtaxa(String genus, String species, String subtaxa, int maxSize)
      Description copied from interface: TaxonomyDatabase
      Suggest a list of subtaxa
      Specified by:
      findSimilarSubtaxa in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      subtaxa - subtaxa to check
      maxSize - maximum number of suggestions to return
      Returns:
      list of suggestions, ordered by preference, never null
    • findSimilarSubtaxa

      public List<String> findSimilarSubtaxa(String genus, String species, String spAuthor, String subtaxa, String subtAuthor, int maxSize)
      Description copied from interface: TaxonomyDatabase
      Suggest a list of subtaxa
      Specified by:
      findSimilarSubtaxa in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      spAuthor - species authority
      subtaxa - subtaxa to check
      subtAuthor - species authority at the lowest classification level
      maxSize - maximum number of suggestions to return
      Returns:
      list of suggestions, ordered by preference, never null
    • getSubtaxaAuthority

      public List<String> getSubtaxaAuthority(String genus, String species, String subtaxa)
      Description copied from interface: TaxonomyDatabase
      Return the authority for the specified subtaxa
      Specified by:
      getSubtaxaAuthority in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      subtaxa - subtaxa to check
      Returns:
      the authority or null
    • getSubtaxaAuthority

      public List<String> getSubtaxaAuthority(String genus, String species, String spAuthor, String subtaxa, String subtAuthor)
      Description copied from interface: TaxonomyDatabase
      Return the authority for the specified subtaxa
      Specified by:
      getSubtaxaAuthority in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      spAuthor - species authority
      subtaxa - subtaxa to check
      subtAuthor - species authority at the lowest classification level
      Returns:
      the authority or null
    • listSpecies

      public List<org.genesys.taxonomy.gringlobal.model.IGrinSpecies> listSpecies(String genus, String species, int maxSize)
      Description copied from interface: TaxonomyDatabase
      Return all subtaxa for genus and species
      Specified by:
      listSpecies in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      maxSize - maximum number of rows to return
      Returns:
      list of species matching genus and species name
    • findSpeciesRow

      public List<org.genesys.taxonomy.gringlobal.model.IGrinSpecies> findSpeciesRow(String genus, String species, String subtaxa)
      Description copied from interface: TaxonomyDatabase
      Find SpeciesRows matching the definition
      Specified by:
      findSpeciesRow in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      subtaxa - the MCPD subtaxa
      Returns:
      list of matching SpeciesRows
    • findSpeciesRows

      public List<org.genesys.taxonomy.gringlobal.model.IGrinSpecies> findSpeciesRows(String genus, String species, String spAuthor, String subtaxa, String subtAuthor)
      Description copied from interface: TaxonomyDatabase
      Find SpeciesRows matching the definition
      Specified by:
      findSpeciesRows in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      spAuthor - species authority
      subtaxa - the MCPD subtaxa
      subtAuthor - species authority at the lowest classification level
      Returns:
      list of matching SpeciesRows
    • getTaxon

      public TaxonomyChecker.Taxon getTaxon(String genus, String species, String spAuthor, String subtaxa, String subtAuthor)
      Description copied from interface: TaxonomyDatabase
      Get exact match.
      Specified by:
      getTaxon in interface TaxonomyDatabase
      Parameters:
      genus - valid genus
      species - valid species
      spAuthor - species authority
      subtaxa - subtaxa to check
      subtAuthor - species authority at the lowest classification level
      Returns:
      One exactly matching record
    • findTaxa

      public List<TaxonomyChecker.Taxon> findTaxa(String genus, String species, String spAuthor, String subtaxa, String subtAuthor, int maxSize)
      Specified by:
      findTaxa in interface TaxonomyDatabase
      Parameters:
      genus - the genus
      species - the species
      spAuthor - species authority
      subtaxa - the MCPD subtaxa
      subtAuthor - species authority at the lowest classification level
      maxSize - maximum rows to return
      Returns:
      list of taxa
    • getSpeciesRow

      public org.genesys.taxonomy.gringlobal.model.IGrinSpecies getSpeciesRow(long speciesId)
      Description copied from interface: TaxonomyDatabase
      Get species by speciesId
      Specified by:
      getSpeciesRow in interface TaxonomyDatabase
      Parameters:
      speciesId - duh
      Returns:
      SpeciesRow or null if not found
    • getGenus

      public String getGenus(long genusId)
      Description copied from interface: TaxonomyDatabase
      Get genus by genusId
      Specified by:
      getGenus in interface TaxonomyDatabase
      Parameters:
      genusId - duh
      Returns:
      genus name or null