@Test public void hasAssociatedTaxa() throws IOException, URISyntaxException { URI sampleArchive = getClass().getResource("AEC-DBCNet_DwC-A20160308-sample.zip").toURI(); Archive archive = DwCAUtil.archiveFor(sampleArchive, "target/tmp"); AtomicBoolean foundLink = new AtomicBoolean(false); importAssociatedTaxaExtension(archive, new InteractionListener() { @Override public void newLink(Map<String, String> link) throws StudyImporterException { assertThat(link.get(TaxonUtil.SOURCE_TAXON_NAME), is("Andrena wilkella")); assertThat(link.get(DatasetImporterForTSV.SOURCE_SEX_NAME), is("Female")); assertThat(link.get(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME), is("Adult")); assertThat(link.get(TaxonUtil.TARGET_TAXON_NAME), is("Melilotus officinalis")); assertThat(link.get(INTERACTION_TYPE_NAME), is("associated with")); assertThat(link.get(INTERACTION_TYPE_ID), is("http: assertThat(link.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("LabelObservation")); assertThat(link.get(DatasetImporterForTSV.DECIMAL_LATITUDE), is("42.40000")); assertThat(link.get(DatasetImporterForTSV.DECIMAL_LONGITUDE), is("-76.50000")); assertThat(link.get(DatasetImporterForTSV.LOCALITY_NAME), is("Tompkins County")); assertThat(link.get(DatasetImporterForTSV.SOURCE_OCCURRENCE_ID), is("urn:uuid:859e1708-d8e1-11e2-99a2-0026552be7ea")); assertThat(link.get(DatasetImporterForTSV.SOURCE_COLLECTION_CODE), is(nullValue())); assertThat(link.get(DatasetImporterForTSV.SOURCE_COLLECTION_ID), is(nullValue())); assertThat(link.get(DatasetImporterForTSV.SOURCE_INSTITUTION_CODE), is("CUIC")); assertThat(link.get(DatasetImporterForTSV.SOURCE_CATALOG_NUMBER), is("CUIC_ENT 00014070")); assertThat(link.get(DatasetImporterForTSV.REFERENCE_CITATION), is("Digital Bee Collections Network, 2014 (and updates). Version: 2016-03-08. National Science Foundation grant DBI 0956388")); foundLink.set(true); } }); assertTrue(foundLink.get()); }
static void importAssociatedTaxaExtension(Archive archive, InteractionListener interactionListener) { if (hasAssociatedTaxaExtension(archive)) { ArchiveFile extension = archive.getExtension(new ExtensionProperty(EXTENSION_ASSOCIATED_TAXA)); ArchiveFile core = archive.getCore(); DB db = DBMaker .newMemoryDirectDB() .compressionEnable() .transactionDisable() .make(); final HTreeMap<String, Map<String, String>> associationsMap = db .createHashMap("assocMap") .make(); for (Record record : extension) { Map<String, String> props = new TreeMap<>(); termsToMap(record, props); associationsMap.put(record.id(), props); } for (Record coreRecord : core) { String id = coreRecord.id(); if (associationsMap.containsKey(id)) { try { Map<String, String> targetProperties = associationsMap.get(id); TreeMap<String, String> interaction = new TreeMap<>(); mapAssociationProperties(targetProperties, interaction); mapCoreProperties(coreRecord, interaction); interactionListener.newLink(interaction); } catch (StudyImporterException e) { } } } } }
DatasetImporterForDwCA extends DatasetImporterWithListener { static void importAssociatedTaxaExtension(Archive archive, InteractionListener interactionListener) { if (hasAssociatedTaxaExtension(archive)) { ArchiveFile extension = archive.getExtension(new ExtensionProperty(EXTENSION_ASSOCIATED_TAXA)); ArchiveFile core = archive.getCore(); DB db = DBMaker .newMemoryDirectDB() .compressionEnable() .transactionDisable() .make(); final HTreeMap<String, Map<String, String>> associationsMap = db .createHashMap("assocMap") .make(); for (Record record : extension) { Map<String, String> props = new TreeMap<>(); termsToMap(record, props); associationsMap.put(record.id(), props); } for (Record coreRecord : core) { String id = coreRecord.id(); if (associationsMap.containsKey(id)) { try { Map<String, String> targetProperties = associationsMap.get(id); TreeMap<String, String> interaction = new TreeMap<>(); mapAssociationProperties(targetProperties, interaction); mapCoreProperties(coreRecord, interaction); interactionListener.newLink(interaction); } catch (StudyImporterException e) { } } } } } }
DatasetImporterForDwCA extends DatasetImporterWithListener { static void importAssociatedTaxaExtension(Archive archive, InteractionListener interactionListener) { if (hasAssociatedTaxaExtension(archive)) { ArchiveFile extension = archive.getExtension(new ExtensionProperty(EXTENSION_ASSOCIATED_TAXA)); ArchiveFile core = archive.getCore(); DB db = DBMaker .newMemoryDirectDB() .compressionEnable() .transactionDisable() .make(); final HTreeMap<String, Map<String, String>> associationsMap = db .createHashMap("assocMap") .make(); for (Record record : extension) { Map<String, String> props = new TreeMap<>(); termsToMap(record, props); associationsMap.put(record.id(), props); } for (Record coreRecord : core) { String id = coreRecord.id(); if (associationsMap.containsKey(id)) { try { Map<String, String> targetProperties = associationsMap.get(id); TreeMap<String, String> interaction = new TreeMap<>(); mapAssociationProperties(targetProperties, interaction); mapCoreProperties(coreRecord, interaction); interactionListener.newLink(interaction); } catch (StudyImporterException e) { } } } } } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForDwCA extends DatasetImporterWithListener { static void importAssociatedTaxaExtension(Archive archive, InteractionListener interactionListener) { if (hasAssociatedTaxaExtension(archive)) { ArchiveFile extension = archive.getExtension(new ExtensionProperty(EXTENSION_ASSOCIATED_TAXA)); ArchiveFile core = archive.getCore(); DB db = DBMaker .newMemoryDirectDB() .compressionEnable() .transactionDisable() .make(); final HTreeMap<String, Map<String, String>> associationsMap = db .createHashMap("assocMap") .make(); for (Record record : extension) { Map<String, String> props = new TreeMap<>(); termsToMap(record, props); associationsMap.put(record.id(), props); } for (Record coreRecord : core) { String id = coreRecord.id(); if (associationsMap.containsKey(id)) { try { Map<String, String> targetProperties = associationsMap.get(id); TreeMap<String, String> interaction = new TreeMap<>(); mapAssociationProperties(targetProperties, interaction); mapCoreProperties(coreRecord, interaction); interactionListener.newLink(interaction); } catch (StudyImporterException e) { } } } } } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); int importCore(Archive archive, InteractionListener interactionListener); void handleRecord(InteractionListener interactionListener, Record rec); static void addRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static Map<String, String> parseRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(String occurrenceRemarks); void addUSNMStyleHostOccurrenceRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static void mapCoreProperties(Record rec, Map<String, String> interactionProperties); static void mapLocationAndReferenceInfo(Record rec, Map<String, String> interactionProperties); static void mapSourceProperties(Record rec, Map<String, String> interactionProperties); static void mapIfAvailable(Record rec, Map<String, String> interactionProperties, String key, Term term); static void mapIfAvailable(Map<String, String> interactionProperties, String key, String value); static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks); static Map<String, String> parseJsonChunk(String candidateJsonChunk); }
DatasetImporterForDwCA extends DatasetImporterWithListener { static void importAssociatedTaxaExtension(Archive archive, InteractionListener interactionListener) { if (hasAssociatedTaxaExtension(archive)) { ArchiveFile extension = archive.getExtension(new ExtensionProperty(EXTENSION_ASSOCIATED_TAXA)); ArchiveFile core = archive.getCore(); DB db = DBMaker .newMemoryDirectDB() .compressionEnable() .transactionDisable() .make(); final HTreeMap<String, Map<String, String>> associationsMap = db .createHashMap("assocMap") .make(); for (Record record : extension) { Map<String, String> props = new TreeMap<>(); termsToMap(record, props); associationsMap.put(record.id(), props); } for (Record coreRecord : core) { String id = coreRecord.id(); if (associationsMap.containsKey(id)) { try { Map<String, String> targetProperties = associationsMap.get(id); TreeMap<String, String> interaction = new TreeMap<>(); mapAssociationProperties(targetProperties, interaction); mapCoreProperties(coreRecord, interaction); interactionListener.newLink(interaction); } catch (StudyImporterException e) { } } } } } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); int importCore(Archive archive, InteractionListener interactionListener); void handleRecord(InteractionListener interactionListener, Record rec); static void addRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static Map<String, String> parseRoyalSaskatchewanMuseumOwlPelletCollectionStyleRemarks(String occurrenceRemarks); void addUSNMStyleHostOccurrenceRemarks(List<Map<String, String>> interactionCandidates, String occurrenceRemarks); static void mapCoreProperties(Record rec, Map<String, String> interactionProperties); static void mapLocationAndReferenceInfo(Record rec, Map<String, String> interactionProperties); static void mapSourceProperties(Record rec, Map<String, String> interactionProperties); static void mapIfAvailable(Record rec, Map<String, String> interactionProperties, String key, Term term); static void mapIfAvailable(Map<String, String> interactionProperties, String key, String value); static Map<String, String> parseUSNMStyleHostOccurrenceRemarks(String occurrenceRemarks); static Map<String, String> parseJsonChunk(String candidateJsonChunk); static final String EXTENSION_ASSOCIATED_TAXA; static final String EXTENSION_RESOURCE_RELATIONSHIP; static final String EXTENSION_TAXON; static final Pattern EX_NOTATION; static final Pattern REARED_EX_NOTATION; static final Pattern PATTERN_ASSOCIATED_TAXA_IDEA; static final Pattern PATTERN_ASSOCIATED_TAXA_EAE; }