use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForVertNetTest method parseAssociatedOccurrences2.
@Ignore
@Test
public void parseAssociatedOccurrences2() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode1 = mapper.readTree(IOUtils.toString(new GZIPInputStream(getClass().getResourceAsStream("vertnet/response_associated_occurrences.json.gz"))));
JsonNode recs = jsonNode1.get("recs");
StringWriter linkOs = new StringWriter();
CSVPrint linkPrinter = CSVTSVUtil.createCSVPrint(linkOs);
linkPrinter.print(new String[] { "source", "interaction_type", "target" });
linkPrinter.setAutoFlush(true);
StringWriter nodeOs = new StringWriter();
CSVPrint nodePrinter = CSVTSVUtil.createCSVPrint(nodeOs);
String[] nodeFields = { "individualid", "decimallongitude", "decimallatitude", "year", "month", "day", "basisofrecord", "scientificname", "dataset_citation" };
nodePrinter.print(nodeFields);
nodePrinter.setAutoFlush(true);
for (JsonNode rec : recs) {
String specimenId = getOrNull(rec, "individualid");
String associatedOcc = getOrNull(rec, "associatedoccurrences");
if (StringUtils.isNotBlank(specimenId) && StringUtils.isNotBlank(associatedOcc)) {
Map<String, InteractType> associatedoccurrences = parseAssOcc(associatedOcc);
for (Map.Entry<String, InteractType> entry : associatedoccurrences.entrySet()) {
linkPrinter.println();
linkPrinter.print(specimenId);
linkPrinter.print(entry.getValue().toString());
linkPrinter.print(entry.getKey());
}
nodePrinter.println();
for (String field : nodeFields) {
String value = getOrNull(rec, field);
nodePrinter.print(StringUtils.isBlank(value) ? "" : value);
}
}
}
linkPrinter.flush();
linkPrinter.close();
assertThat(linkOs.toString(), is("source,interaction_type,target" + "\nhttp://arctos.database.museum/guid/CUMV:Amph:16004,EATEN_BY,http://arctos.database.museum/guid/CUMV:Rept:4988" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:34623,ATE,http://arctos.database.museum/guid/DMNS:Mamm:13142" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:34623,ATE,http://arctos.database.museum/guid/DMNS:Mamm:13143" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:34728,ATE,DZTM::Denver:Zoology:Tissue:Mammal:2285" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:34728,ATE,http://arctos.database.museum/guid/DMNS:Mamm:13685"));
assertThat(nodeOs.toString(), is("individualid,decimallongitude,decimallatitude,year,month,day,basisofrecord,scientificname,dataset_citation" + "\nindividualID,180,-90,2014,10,10,basisOfRecord,scientificName,test citation" + "\nhttp://arctos.database.museum/guid/CUMV:Amph:16004,-76.45442,42.4566,1953,09,27,PreservedSpecimen,Rana sylvatica," + "\nhttp://arctos.database.museum/guid/DMNS:Bird:21686,-106.434158,38.709448,1940,07,27,PreservedSpecimen,Lagopus leucurus,Denver Museum of Nature & Science Bird Collection" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:21688,-106.434158,38.709448,1940,07,27,PreservedSpecimen,Lagopus leucurus,Denver Museum of Nature & Science Bird Collection" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:21689,-106.434158,38.709448,1940,07,27,PreservedSpecimen,Lagopus leucurus,Denver Museum of Nature & Science Bird Collection" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:26722,-105.02222,39.38528,1943,06,24,PreservedSpecimen,Chordeiles minor,Denver Museum of Nature & Science Bird Collection" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:26724,-105.02222,39.38528,1943,06,24,PreservedSpecimen,Chordeiles minor,Denver Museum of Nature & Science Bird Collection" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:34623,-104.738965,39.461082,2012,04,30,PreservedSpecimen,Asio otus,Denver Museum of Nature & Science Bird Collection" + "\nhttp://arctos.database.museum/guid/DMNS:Bird:34728,-105.096498,40.454918,2012,08,10,PreservedSpecimen,Buteo swainsoni,Denver Museum of Nature & Science Bird Collection"));
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForHechinger method addLink.
private void addLink(Study study, Map<Integer, Term> stageForNode, Map<Integer, String> taxonForNode, LabeledCSVParser links, Location location) throws StudyImporterException, NodeFactoryException {
Integer consumerNodeID = Integer.parseInt(links.getValueByLabel("ConsumerNodeID"));
Integer resourceNodeID = Integer.parseInt(links.getValueByLabel("ResourceNodeID"));
String linkType = links.getValueByLabel("LinkType");
InteractType interactType = interactionMapping.get(StringUtils.trim(StringUtils.lowerCase(linkType)));
if (interactType == null) {
throw new StudyImporterException("failed to map interaction type [" + linkType + "] in line [" + links.lastLineNumber() + "]");
}
Specimen consumer = nodeFactory.createSpecimen(study, new TaxonImpl(taxonForNode.get(consumerNodeID), null));
consumer.setLifeStage(stageForNode.get(consumerNodeID));
consumer.setExternalId(getNamespace() + ":NodeID:" + consumerNodeID);
consumer.caughtIn(location);
String resourceName = taxonForNode.get(resourceNodeID);
Specimen resource = nodeFactory.createSpecimen(study, new TaxonImpl(resourceName, null));
resource.setLifeStage(stageForNode.get(resourceNodeID));
resource.setExternalId(getNamespace() + ":NodeID:" + resourceNodeID);
resource.caughtIn(location);
consumer.interactsWith(resource, interactType);
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class InteractionListenerImpl method expand.
private List<Map<String, String>> expand(Map<String, String> properties, String associatedTaxa) {
List<Map<String, String>> expandedList;
expandedList = new ArrayList<>();
String[] associatedPairs = associatedTaxa.split("\\|");
for (String associatedPair : associatedPairs) {
String[] typeAndTarget = associatedPair.split(":");
if (typeAndTarget.length > 1) {
String typeName = typeAndTarget[0];
String targetTaxon = typeAndTarget[1];
HashMap<String, String> expanded = new HashMap<>(properties);
expanded.put(TARGET_TAXON_NAME, StringUtils.trim(targetTaxon));
expanded.put(INTERACTION_TYPE_NAME, StringUtils.trim(typeName));
InteractType interactType = StudyImporterForMetaTable.generateInteractionType(expanded);
if (interactType != null) {
expanded.put(INTERACTION_TYPE_NAME, interactType.getLabel());
expanded.put(INTERACTION_TYPE_ID, interactType.getIRI());
} else {
getLogger().warn(studyFromLink(expanded), "unsupported interaction type for name [" + typeName + "]");
}
expandedList.add(expanded);
}
}
return expandedList;
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForKelpForest method importStudy.
@Override
public void importStudy() throws StudyImporterException {
try {
String source = "Beas-Luna, R., Novak, M., Carr, M. H., Tinker, M. T., Black, A., Caselle, J. E., … Iles, A. (2014). An Online Database for Informing Ecological Network Models: http://kelpforest.ucsc.edu. PLoS ONE, 9(10), e109356. doi:10.1371/journal.pone.0109356";
Study study = nodeFactory.getOrCreateStudy(new StudyImpl(source, source, "doi:10.1371/journal.pone.0109356", source));
LabeledCSVParser parser = parserFactory.createParser(NODES, "UTF-8");
String[] line;
Map<String, Long> nameToId = new HashMap<String, Long>();
while ((line = parser.getLine()) != null) {
if (line.length > 2) {
String name = parser.getValueByLabel("working_name");
String itisId = parser.getValueByLabel("itis_id");
Long id = StringUtils.isBlank(itisId) ? null : Long.parseLong(itisId);
id = (id != null && id > 0L) ? id : null;
nameToId.put(name, id);
}
}
Map<String, InteractType> typeToType = new HashMap<String, InteractType>() {
{
put("trophic", InteractType.ATE);
put("parasitic", InteractType.PARASITE_OF);
}
};
parser = parserFactory.createParser(LINKS, "UTF-8");
while ((line = parser.getLine()) != null) {
if (line.length > 2) {
String interactionType = parser.getValueByLabel("type");
InteractType interactType = typeToType.get(interactionType);
if (null == interactType) {
LOG.warn("ignoring type [" + interactionType + "] on line: [" + (parser.getLastLineNumber() + 1) + "]");
} else {
Specimen sourceSpecimen = createSpecimen(parser, nameToId, "node_1_working_name", "node1_stage", study);
Specimen targetSpecimen = createSpecimen(parser, nameToId, "node_2_working_name", "node2_stage", study);
sourceSpecimen.interactsWith(targetSpecimen, interactType);
}
}
}
} catch (IOException | NodeFactoryException e) {
throw new StudyImporterException("failed to import", e);
}
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalist method retrieveDataParseResults.
private int retrieveDataParseResults() throws StudyImporterException {
List<Integer> typesIgnored;
try {
typesIgnored = buildTypesIgnored(parserFactory.createParser(getTypeIgnoredURI(), CharsetConstant.UTF8));
} catch (IOException e) {
throw new StudyImporterException("failed to load ignored interaction types from [" + getTypeIgnoredURI() + "]");
}
Map<Integer, InteractType> typeMap;
try {
LabeledCSVParser labeledCSVParser = parserFactory.createParser(getTypeMapURI(), CharsetConstant.UTF8);
typeMap = buildTypeMap(getTypeMapURI(), labeledCSVParser);
} catch (IOException e) {
throw new StudyImporterException("failed to load interaction mapping from [" + getTypeMapURI() + "]");
}
int totalInteractions = 0;
int previousResultCount = 0;
int pageNumber = 1;
do {
String uri = INATURALIST_URL + "/observation_field_values.json?type=taxon&page=" + pageNumber + "&per_page=100&quality_grade=research";
try {
previousResultCount = parseJSON(getDataset().getResource(uri), typesIgnored, typeMap);
pageNumber++;
totalInteractions += previousResultCount;
} catch (IOException | StudyImporterException e) {
throw new StudyImporterException("failed to import iNaturalist at [" + uri + "]", e);
}
} while (previousResultCount > 0);
return totalInteractions;
}
Aggregations