@Test public void testEnrichMultimedia() { 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); MultiMediaContentIdentification mmci = new MultiMediaContentIdentification(); mmci.setScientificName(scientificName); List<MultiMediaContentIdentification> list = new ArrayList<>(); list.add(mmci); MultiMediaObject mmo = new MultiMediaObject(); mmo.setId("L.1911711_2107143681@BRAHMS"); mmo.setIdentifications(list); List<MultiMediaObject> mmoList = new ArrayList<>(); mmoList.add(mmo); Object obj = ReflectionUtil.callStatic(MultimediaTaxonomicEnricher2.class, "enrichMultimedia", new Class[] {List.class}, new Object[] {mmoList}); List<MultiMediaObject> actualList = (List<MultiMediaObject>) obj; MultiMediaObject actual = actualList.get(0); String expectedId = "L.1911711_2107143681@BRAHMS"; 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 actualName = actual.getIdentifications().get(0).getScientificName(); assertEquals("01", expectedId, actual.getId()); assertEquals("02", taxanomicStatus, actualName.getTaxonomicStatus().toString()); assertEquals("03", expectedScientificNameGroup, actualName.getScientificNameGroup()); assertEquals("04", expectedAuthorshipVerbatim, actualName.getAuthorshipVerbatim()); assertEquals("05", expectedGenus, actualName.getGenusOrMonomial()); assertEquals("06", expectedSpecificEpethet, actualName.getSpecificEpithet()); assertEquals("07", expectedFullScientificName, actualName.getFullScientificName()); }
private static List<MultiMediaObject> enrichMultiMedia(List<MultiMediaObject> mmos) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(mmos); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of mmos"); } 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<>(mmos.size()); List<MultiMediaObject> result = new ArrayList<>(mmos.size()); for (MultiMediaObject mmo : mmos) { boolean enriched = false; if (mmo.getIdentifications() == null) { continue; } for (MultiMediaContentIdentification si : mmo.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(mmo); } } return result; }
MultimediaTaxonomicEnricher { private static List<MultiMediaObject> enrichMultiMedia(List<MultiMediaObject> mmos) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(mmos); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of mmos"); } 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<>(mmos.size()); List<MultiMediaObject> result = new ArrayList<>(mmos.size()); for (MultiMediaObject mmo : mmos) { boolean enriched = false; if (mmo.getIdentifications() == null) { continue; } for (MultiMediaContentIdentification si : mmo.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(mmo); } } return result; } }
MultimediaTaxonomicEnricher { private static List<MultiMediaObject> enrichMultiMedia(List<MultiMediaObject> mmos) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(mmos); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of mmos"); } 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<>(mmos.size()); List<MultiMediaObject> result = new ArrayList<>(mmos.size()); for (MultiMediaObject mmo : mmos) { boolean enriched = false; if (mmo.getIdentifications() == null) { continue; } for (MultiMediaContentIdentification si : mmo.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(mmo); } } return result; }  }
MultimediaTaxonomicEnricher { private static List<MultiMediaObject> enrichMultiMedia(List<MultiMediaObject> mmos) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(mmos); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of mmos"); } 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<>(mmos.size()); List<MultiMediaObject> result = new ArrayList<>(mmos.size()); for (MultiMediaObject mmo : mmos) { boolean enriched = false; if (mmo.getIdentifications() == null) { continue; } for (MultiMediaContentIdentification si : mmo.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(mmo); } } 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); }
MultimediaTaxonomicEnricher { private static List<MultiMediaObject> enrichMultiMedia(List<MultiMediaObject> mmos) { if (logger.isDebugEnabled()) { logger.debug("Creating taxon lookup table"); } HashMap<String, List<Taxon>> taxonLookupTable = createLookupTable(mmos); if (taxonLookupTable == null) { if (logger.isDebugEnabled()) { logger.debug("No taxa found for current batch of mmos"); } 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<>(mmos.size()); List<MultiMediaObject> result = new ArrayList<>(mmos.size()); for (MultiMediaObject mmo : mmos) { boolean enriched = false; if (mmo.getIdentifications() == null) { continue; } for (MultiMediaContentIdentification si : mmo.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(mmo); } } 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);  }