use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class InteractionListenerIndexingTest method indexOnTargetOccurrenceIdOnly.
@Test
public void indexOnTargetOccurrenceIdOnly() throws StudyImporterException {
TreeMap<Pair<String, String>, Map<String, String>> interactionsWithUnresolvedOccurrenceIds = new TreeMap<>();
InteractionListener listener = new InteractionListenerIndexing(interactionsWithUnresolvedOccurrenceIds);
listener.on(new TreeMap<String, String>() {
{
put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "target123");
put(TaxonUtil.SOURCE_TAXON_NAME, "sourceName123");
}
});
assertThat(interactionsWithUnresolvedOccurrenceIds.size(), Is.is(0));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importInteractionsFromResourceRelationships.
private static void importInteractionsFromResourceRelationships(InteractionListener interactionListener, ArchiveFile resourceExtension, Map<String, Map<String, Map<String, String>>> termTypeIdPropMap, List<DwcTerm> termTypes) {
for (Record record : resourceExtension) {
Map<String, String> props = new TreeMap<>();
appendResourceType(props, resourceExtension.getRowType());
String sourceId = record.value(DwcTerm.resourceID);
String relationship = record.value(DwcTerm.relationshipOfResource);
Optional<Term> relationshipOfResourceIDTerm = record.terms().stream().filter(x -> StringUtils.equals(x.simpleName(), "relationshipOfResourceID")).findFirst();
String relationshipTypeIdValue = relationshipOfResourceIDTerm.map(record::value).orElse(null);
String targetId = record.value(DwcTerm.relatedResourceID);
if (StringUtils.isNotBlank(sourceId)) {
appendVerbatimResourceRelationsValues(record, props);
String relationshipAccordingTo = record.value(DwcTerm.relationshipAccordingTo);
if (StringUtils.isNotBlank(relationshipAccordingTo)) {
props.putIfAbsent(REFERENCE_CITATION, relationshipAccordingTo);
}
putIfAbsentAndNotBlank(props, INTERACTION_TYPE_NAME, relationship);
putIfAbsentAndNotBlank(props, INTERACTION_TYPE_ID, relationshipTypeIdValue);
putIfAbsentAndNotBlank(props, DatasetImporterForMetaTable.EVENT_DATE, record.value(DwcTerm.relationshipEstablishedDate));
for (DwcTerm termType : termTypes) {
String key = termType.qualifiedName();
if (StringUtils.isNoneBlank(key) && termTypeIdPropMap.containsKey(key)) {
Map<String, Map<String, String>> propMap = termTypeIdPropMap.get(termType.qualifiedName());
populatePropertiesAssociatedWithId(props, sourceId, true, propMap.get(sourceId), labelPairFor(termType));
extractNameFromRelationshipRemarks(record).ifPresent(name -> props.put(TARGET_TAXON_NAME, name));
populatePropertiesAssociatedWithId(props, targetId, false, propMap.get(targetId), labelPairFor(termType));
}
}
try {
interactionListener.on(props);
} catch (StudyImporterException e) {
//
}
}
}
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForSaproxylic method toInteractions.
public void toInteractions(ResultSet results) throws StudyImporterException {
final InteractionListener listener = getInteractionListener();
while (results.hasNext()) {
QuerySolution next = results.next();
Iterator<String> nameIter = next.varNames();
Map<String, String> props = new TreeMap<>();
while (nameIter.hasNext()) {
String key = nameIter.next();
RDFNode rdfNode = next.get(key);
if (rdfNode.isURIResource()) {
props.put(key, next.getResource(key).getURI());
} else {
props.put(key, next.getLiteral(key).getString());
}
}
props.put(DatasetImporterForTSV.DATASET_CITATION, getDataset().getCitation());
listener.on(props);
}
}
Aggregations