@Test public void testEnrichSpecimens() { ScientificName scientificName = new ScientificName(); scientificName.setFullScientificName("Bombus affinis Cresson, 1863"); scientificName.setScientificNameGroup("bombus affinis"); scientificName.setAuthorshipVerbatim("Cresson, 1863"); scientificName.setGenusOrMonomial("Larus"); scientificName.setSpecificEpithet("affinis"); scientificName.setInfraspecificEpithet(""); scientificName.setTaxonomicStatus(TaxonomicStatus.ACCEPTED_NAME); SpecimenIdentification identification = new SpecimenIdentification(); identification.setScientificName(scientificName); Specimen specimen = new Specimen(); specimen.addIndentification(identification); List<Specimen> specimens = new ArrayList<>(); specimens.add(specimen); Object obj = ReflectionUtil.callStatic(SpecimenTaxonomicEnricher2.class, "enrichSpecimens", new Class[] {List.class}, new Object[] {specimens}); List<Specimen> expectedSpecimens = (List<Specimen>) obj; Specimen actual = expectedSpecimens.get(0); String taxanomicStatus = "accepted name"; String expectedScientificNameGroup = "bombus affinis"; String expectedAuthorshipVerbatim = "Cresson, 1863"; String expectedFullScientificName = "Bombus affinis Cresson, 1863"; String expectedGenus = "Larus"; String expectedSpecificEpethet = "affinis"; ScientificName name = actual.getIdentifications().get(0).getScientificName(); assertEquals("01", taxanomicStatus, name.getTaxonomicStatus().toString()); assertEquals("02", expectedScientificNameGroup, name.getScientificNameGroup()); assertEquals("03", expectedAuthorshipVerbatim, name.getAuthorshipVerbatim()); assertEquals("04", expectedFullScientificName, name.getFullScientificName()); assertEquals("05", expectedGenus, name.getGenusOrMonomial()); assertEquals("06", expectedSpecificEpethet, name.getSpecificEpithet()); }
private static List<Specimen> enrichSpecimens(List<Specimen> specimens) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(specimens); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of specimens"); } return Collections.emptyList(); } if (logger.isDebugEnabled()) { logger.debug("Lookup table created. {} unique name group(s) found in Taxon index", taxonLookupTable.size()); } HashMap<String, List<TaxonomicEnrichment>> cache = new HashMap<>(specimens.size()); List<Specimen> result = new ArrayList<>(specimens.size()); for (Specimen specimen : specimens) { boolean enriched = false; if (specimen.getIdentifications() == null) { continue; } for (TaxonomicIdentification si : specimen.getIdentifications()) { String nameGroup = si.getScientificName().getScientificNameGroup(); List<TaxonomicEnrichment> enrichments = cache.get(nameGroup); if (enrichments == null) { List<Taxon> taxa = taxonLookupTable.get(nameGroup); if (taxa == null) { cache.put(nameGroup, NONE); } else { enrichments = createEnrichments(taxa); cache.put(nameGroup, enrichments); if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } } else if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } if (enriched) { result.add(specimen); } } return result; }
SpecimenTaxonomicEnricher { private static List<Specimen> enrichSpecimens(List<Specimen> specimens) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(specimens); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of specimens"); } return Collections.emptyList(); } if (logger.isDebugEnabled()) { logger.debug("Lookup table created. {} unique name group(s) found in Taxon index", taxonLookupTable.size()); } HashMap<String, List<TaxonomicEnrichment>> cache = new HashMap<>(specimens.size()); List<Specimen> result = new ArrayList<>(specimens.size()); for (Specimen specimen : specimens) { boolean enriched = false; if (specimen.getIdentifications() == null) { continue; } for (TaxonomicIdentification si : specimen.getIdentifications()) { String nameGroup = si.getScientificName().getScientificNameGroup(); List<TaxonomicEnrichment> enrichments = cache.get(nameGroup); if (enrichments == null) { List<Taxon> taxa = taxonLookupTable.get(nameGroup); if (taxa == null) { cache.put(nameGroup, NONE); } else { enrichments = createEnrichments(taxa); cache.put(nameGroup, enrichments); if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } } else if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } if (enriched) { result.add(specimen); } } return result; } }
SpecimenTaxonomicEnricher { private static List<Specimen> enrichSpecimens(List<Specimen> specimens) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(specimens); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of specimens"); } return Collections.emptyList(); } if (logger.isDebugEnabled()) { logger.debug("Lookup table created. {} unique name group(s) found in Taxon index", taxonLookupTable.size()); } HashMap<String, List<TaxonomicEnrichment>> cache = new HashMap<>(specimens.size()); List<Specimen> result = new ArrayList<>(specimens.size()); for (Specimen specimen : specimens) { boolean enriched = false; if (specimen.getIdentifications() == null) { continue; } for (TaxonomicIdentification si : specimen.getIdentifications()) { String nameGroup = si.getScientificName().getScientificNameGroup(); List<TaxonomicEnrichment> enrichments = cache.get(nameGroup); if (enrichments == null) { List<Taxon> taxa = taxonLookupTable.get(nameGroup); if (taxa == null) { cache.put(nameGroup, NONE); } else { enrichments = createEnrichments(taxa); cache.put(nameGroup, enrichments); if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } } else if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } if (enriched) { result.add(specimen); } } return result; }  }
SpecimenTaxonomicEnricher { private static List<Specimen> enrichSpecimens(List<Specimen> specimens) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(specimens); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of specimens"); } return Collections.emptyList(); } if (logger.isDebugEnabled()) { logger.debug("Lookup table created. {} unique name group(s) found in Taxon index", taxonLookupTable.size()); } HashMap<String, List<TaxonomicEnrichment>> cache = new HashMap<>(specimens.size()); List<Specimen> result = new ArrayList<>(specimens.size()); for (Specimen specimen : specimens) { boolean enriched = false; if (specimen.getIdentifications() == null) { continue; } for (TaxonomicIdentification si : specimen.getIdentifications()) { String nameGroup = si.getScientificName().getScientificNameGroup(); List<TaxonomicEnrichment> enrichments = cache.get(nameGroup); if (enrichments == null) { List<Taxon> taxa = taxonLookupTable.get(nameGroup); if (taxa == null) { cache.put(nameGroup, NONE); } else { enrichments = createEnrichments(taxa); cache.put(nameGroup, enrichments); if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } } else if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } if (enriched) { result.add(specimen); } } return result; }  static void main(String[] args); void enrich(); void configureWithSystemProperties(); int getReadBatchSize(); void setReadBatchSize(int readBatchSize); int getWriteBatchSize(); void setWriteBatchSize(int writeBatchSize); int getScrollTimeout(); void setScrollTimeout(int scrollTimeout); }
SpecimenTaxonomicEnricher { private static List<Specimen> enrichSpecimens(List<Specimen> specimens) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(specimens); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of specimens"); } return Collections.emptyList(); } if (logger.isDebugEnabled()) { logger.debug("Lookup table created. {} unique name group(s) found in Taxon index", taxonLookupTable.size()); } HashMap<String, List<TaxonomicEnrichment>> cache = new HashMap<>(specimens.size()); List<Specimen> result = new ArrayList<>(specimens.size()); for (Specimen specimen : specimens) { boolean enriched = false; if (specimen.getIdentifications() == null) { continue; } for (TaxonomicIdentification si : specimen.getIdentifications()) { String nameGroup = si.getScientificName().getScientificNameGroup(); List<TaxonomicEnrichment> enrichments = cache.get(nameGroup); if (enrichments == null) { List<Taxon> taxa = taxonLookupTable.get(nameGroup); if (taxa == null) { cache.put(nameGroup, NONE); } else { enrichments = createEnrichments(taxa); cache.put(nameGroup, enrichments); if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } } else if (enrichments != NONE) { si.setTaxonomicEnrichments(enrichments); enriched = true; } } if (enriched) { result.add(specimen); } } return result; }  static void main(String[] args); void enrich(); void configureWithSystemProperties(); int getReadBatchSize(); void setReadBatchSize(int readBatchSize); int getWriteBatchSize(); void setWriteBatchSize(int writeBatchSize); int getScrollTimeout(); void setScrollTimeout(int scrollTimeout);  }