use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForJSONLD method importStudy.
@Override
public void importStudy() throws StudyImporterException {
Model model;
try {
model = buildModel();
} catch (IOException e) {
throw new StudyImporterException("failed to import [" + getResourceURI() + "]", e);
}
Query query;
try {
query = QueryFactory.create(IOUtils.toString(new DatasetLocal().getResource("find-jsonld-interactions.rq"), CharsetConstant.UTF8));
} catch (IOException e) {
throw new StudyImporterException("failed to find sparql query", e);
}
QueryExecution exec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = exec.execSelect();
while (results.hasNext()) {
QuerySolution solution = results.nextSolution();
String subj = solution.get("subj").asResource().getURI();
String creationDate = solution.get("creationDate").asLiteral().getString();
String authorURI = solution.get("author").toString();
String author;
try {
author = nodeFactory.getAuthorResolver().findFullName(authorURI);
} catch (IOException e) {
throw new StudyImporterException("failed to resolve author URI [" + authorURI + "]");
}
final String source1 = author + ". " + new DateTime(parseDate(creationDate)).getYear() + ". " + CitationUtil.createLastAccessedString(getResourceURI().toString());
Study study = nodeFactory.getOrCreateStudy(new StudyImpl(getResourceURI() + subj, source1, null, subj));
study.setExternalId(subj);
Specimen source = createSpecimen(solution, study, "subjTaxon");
Specimen target = createSpecimen(solution, study, "targetTaxon");
String interactType = solution.get("p").asResource().getLocalName();
InteractType interactType1 = InteractType.typeOf(StringUtils.replace(interactType, "RO_", "RO:"));
if (interactType1 == null) {
throw new StudyImporterException("failed to map interaction type [" + interactType + "]");
}
String collTime = solution.get("collTime").asLiteral().getString();
Date date = parseDate(collTime);
nodeFactory.setUnixEpochProperty(source, date);
nodeFactory.setUnixEpochProperty(target, date);
Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(solution.get("collLat").asLiteral().getDouble(), solution.get("collLng").asLiteral().getDouble(), null, null));
target.caughtIn(loc);
source.caughtIn(loc);
source.interactsWith(target, interactType1);
}
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to import jsonld data in [" + getResourceURI() + "]", e);
} finally {
exec.close();
}
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForWebOfLife method parseInteractionType.
public InteractType parseInteractionType(LabeledCSVParser parser) throws StudyImporterException {
final String interactionTypeString = parser.getValueByLabel("Type of interactions");
final Map<String, InteractType> interactionTypeMap = new HashMap<String, InteractType>() {
{
put("Pollination", InteractType.POLLINATED_BY);
put("Seed Dispersal", InteractType.HAS_DISPERAL_VECTOR);
put("Host-Parasite", InteractType.HAS_PARASITE);
put("Plant-Herbivore", InteractType.EATEN_BY);
}
};
final InteractType interactType1 = interactionTypeMap.get(interactionTypeString);
if (interactType1 == null) {
LOG.warn("found unsupported interaction type [" + interactionTypeString + "]");
}
return interactType1 == null ? InteractType.INTERACTS_WITH : interactType1;
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForSeltmann method parseInteractType.
private InteractType parseInteractType(LabeledCSVParser occurrence, Map<String, String> assoc) throws StudyImporterException {
String interactionURI = assoc.get("aec:associatedRelationshipURI");
InteractType interactType;
if (StringUtils.isBlank(interactionURI)) {
interactType = InteractType.INTERACTS_WITH;
} else {
final Map<String, InteractType> assocInteractMap = new HashMap<String, InteractType>() {
{
// interaction types that could probably be more specific (e.g. found inside, found on, emerged from)
put("http://purl.obolibrary.org/obo/RO_0002220", InteractType.INTERACTS_WITH);
put("http://purl.obolibrary.org/obo/RO_0001025", InteractType.INTERACTS_WITH);
put("http://eol.org/schema/terms/emergedFrom", InteractType.INTERACTS_WITH);
}
};
interactType = InteractType.typeOf(interactionURI);
interactType = interactType == null ? assocInteractMap.get(interactionURI) : interactType;
if (interactType == null) {
throw new StudyImporterException("found unsupported interactionURI: [" + interactionURI + "] related to" + getLineMsg(occurrence));
}
}
return interactType;
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalistTest method loadInteractionMap.
@Test
public void loadInteractionMap() throws IOException {
String resourceName = StudyImporterForINaturalist.TYPE_MAP_URI_DEFAULT;
LabeledCSVParser labeledCSVParser = importer.parserFactory.createParser(resourceName, CharsetConstant.UTF8);
Map<Integer, InteractType> typeMap = StudyImporterForINaturalist.buildTypeMap(resourceName, labeledCSVParser);
assertThat(typeMap.get(13), is(InteractType.ATE));
assertThat(typeMap.get(1685), is(InteractType.ATE));
assertThat(typeMap.get(839), is(InteractType.PREYS_UPON));
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalistTest method importTestResponseWithTaxonId.
@Test
public void importTestResponseWithTaxonId() throws IOException, StudyImporterException {
importer.parseJSON(getClass().getResourceAsStream("inaturalist/response_with_taxon_ids.json"), new ArrayList<Integer>() {
{
}
}, new HashMap<Integer, InteractType>() {
{
put(47, InteractType.HAS_HOST);
}
});
resolveNames();
assertThat(NodeUtil.findAllStudies(getGraphDb()).size(), is(10));
Study anotherStudy = nodeFactory.findStudy("INAT:2366807");
assertThat(anotherStudy, is(notNullValue()));
assertThat(anotherStudy.getExternalId(), is("https://www.inaturalist.org/observations/2366807"));
assertThat(taxonIndex.findTaxonById("GBIF:2959023"), is(nullValue()));
assertThat(taxonIndex.findTaxonById("GBIF:7246356"), is(nullValue()));
assertThat(taxonIndex.findTaxonById("INAT_TAXON:406089"), is(notNullValue()));
assertThat(taxonIndex.findTaxonById("INAT_TAXON:480390"), is(notNullValue()));
}
Aggregations