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
    • findSimilarGenus

      public List<String> findSimilarGenus(String genus, int maxSize)
      Description copied from interface: TaxonomyDatabase
      Return a list of genera close to the specified genus.
      Specified by:
      findSimilarGenus in interface TaxonomyDatabase
      Parameters:
      genus - genus
      maxSize - TODO
      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(String genus)
      Gets the all genus species.
      Parameters:
      genus - the genus
      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
    • findSimilarSpecies

      public List<String> findSimilarSpecies(String genus, String species, 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
      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 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
    • 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
    • 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 - current subtaxa
      maxSize - maximum number of suggestions to return
      Returns:
      list of suggestions, ordered by preference, never null
    • getSubtaxaAuthority

      public 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
      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
    • 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