@Test public void associatedTaxaMixed() { String associatedTaxa = "Ceramium, Chaetomorpha linum| Enteromorpha intestinalis; Ulva angusta, Porphyra perforata, Sargassum muticum, Gigartina spp., Rhodoglossum affine, and Grateloupia sp."; List<Map<String, String>> properties = parseAssociatedTaxa(associatedTaxa); assertThat(properties.size(), is(9)); assertThat(properties.get(0).get(TaxonUtil.TARGET_TAXON_NAME), is("Ceramium")); assertThat(properties.get(0).get(INTERACTION_TYPE_NAME), is("")); assertThat(properties.get(0).get(INTERACTION_TYPE_ID), is(nullValue())); assertThat(properties.get(8).get(TaxonUtil.TARGET_TAXON_NAME), is("and Grateloupia sp.")); assertThat(properties.get(8).get(INTERACTION_TYPE_NAME), is("")); assertThat(properties.get(8).get(INTERACTION_TYPE_ID), is(nullValue())); }
static List<Map<String, String>> parseAssociatedTaxa(String s) { List<Map<String, String>> properties = new ArrayList<>(); String[] parts = StringUtils.split(s, "|;,"); for (String part : parts) { String trimmedPart = StringUtils.trim(part); Matcher matcher = PATTERN_ASSOCIATED_TAXA_IDEA.matcher(trimmedPart); if (matcher.find()) { String genus = StringUtils.trim(matcher.group(1)); String specificEpithet = StringUtils.trim(matcher.group(2)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { Matcher matcher1 = PATTERN_ASSOCIATED_TAXA_EAE.matcher(trimmedPart); if (matcher1.find()) { String genus = StringUtils.trim(matcher1.group(2)); String specificEpithet = StringUtils.trim(matcher1.group(3)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { String[] verbTaxon = StringUtils.splitByWholeSeparator(trimmedPart, ":", 2); if (verbTaxon.length == 2) { addSpecificInteractionForAssociatedTaxon(properties, verbTaxon); } else { addDefaultInteractionForAssociatedTaxon(properties, trimmedPart); } } } } return properties; }
DatasetImporterForDwCA extends DatasetImporterWithListener { static List<Map<String, String>> parseAssociatedTaxa(String s) { List<Map<String, String>> properties = new ArrayList<>(); String[] parts = StringUtils.split(s, "|;,"); for (String part : parts) { String trimmedPart = StringUtils.trim(part); Matcher matcher = PATTERN_ASSOCIATED_TAXA_IDEA.matcher(trimmedPart); if (matcher.find()) { String genus = StringUtils.trim(matcher.group(1)); String specificEpithet = StringUtils.trim(matcher.group(2)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { Matcher matcher1 = PATTERN_ASSOCIATED_TAXA_EAE.matcher(trimmedPart); if (matcher1.find()) { String genus = StringUtils.trim(matcher1.group(2)); String specificEpithet = StringUtils.trim(matcher1.group(3)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { String[] verbTaxon = StringUtils.splitByWholeSeparator(trimmedPart, ":", 2); if (verbTaxon.length == 2) { addSpecificInteractionForAssociatedTaxon(properties, verbTaxon); } else { addDefaultInteractionForAssociatedTaxon(properties, trimmedPart); } } } } return properties; } }
DatasetImporterForDwCA extends DatasetImporterWithListener { static List<Map<String, String>> parseAssociatedTaxa(String s) { List<Map<String, String>> properties = new ArrayList<>(); String[] parts = StringUtils.split(s, "|;,"); for (String part : parts) { String trimmedPart = StringUtils.trim(part); Matcher matcher = PATTERN_ASSOCIATED_TAXA_IDEA.matcher(trimmedPart); if (matcher.find()) { String genus = StringUtils.trim(matcher.group(1)); String specificEpithet = StringUtils.trim(matcher.group(2)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { Matcher matcher1 = PATTERN_ASSOCIATED_TAXA_EAE.matcher(trimmedPart); if (matcher1.find()) { String genus = StringUtils.trim(matcher1.group(2)); String specificEpithet = StringUtils.trim(matcher1.group(3)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { String[] verbTaxon = StringUtils.splitByWholeSeparator(trimmedPart, ":", 2); if (verbTaxon.length == 2) { addSpecificInteractionForAssociatedTaxon(properties, verbTaxon); } else { addDefaultInteractionForAssociatedTaxon(properties, trimmedPart); } } } } return properties; } DatasetImporterForDwCA(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForDwCA extends DatasetImporterWithListener { static List<Map<String, String>> parseAssociatedTaxa(String s) { List<Map<String, String>> properties = new ArrayList<>(); String[] parts = StringUtils.split(s, "|;,"); for (String part : parts) { String trimmedPart = StringUtils.trim(part); Matcher matcher = PATTERN_ASSOCIATED_TAXA_IDEA.matcher(trimmedPart); if (matcher.find()) { String genus = StringUtils.trim(matcher.group(1)); String specificEpithet = StringUtils.trim(matcher.group(2)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { Matcher matcher1 = PATTERN_ASSOCIATED_TAXA_EAE.matcher(trimmedPart); if (matcher1.find()) { String genus = StringUtils.trim(matcher1.group(2)); String specificEpithet = StringUtils.trim(matcher1.group(3)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { String[] verbTaxon = StringUtils.splitByWholeSeparator(trimmedPart, ":", 2); if (verbTaxon.length == 2) { addSpecificInteractionForAssociatedTaxon(properties, verbTaxon); } else { addDefaultInteractionForAssociatedTaxon(properties, trimmedPart); } } } } return properties; } 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 List<Map<String, String>> parseAssociatedTaxa(String s) { List<Map<String, String>> properties = new ArrayList<>(); String[] parts = StringUtils.split(s, "|;,"); for (String part : parts) { String trimmedPart = StringUtils.trim(part); Matcher matcher = PATTERN_ASSOCIATED_TAXA_IDEA.matcher(trimmedPart); if (matcher.find()) { String genus = StringUtils.trim(matcher.group(1)); String specificEpithet = StringUtils.trim(matcher.group(2)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { Matcher matcher1 = PATTERN_ASSOCIATED_TAXA_EAE.matcher(trimmedPart); if (matcher1.find()) { String genus = StringUtils.trim(matcher1.group(2)); String specificEpithet = StringUtils.trim(matcher1.group(3)); addDefaultInteractionForAssociatedTaxon(properties, genus + " " + specificEpithet); } else { String[] verbTaxon = StringUtils.splitByWholeSeparator(trimmedPart, ":", 2); if (verbTaxon.length == 2) { addSpecificInteractionForAssociatedTaxon(properties, verbTaxon); } else { addDefaultInteractionForAssociatedTaxon(properties, trimmedPart); } } } } return properties; } 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; }