Search in sources :

Example 1 with InteractType

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();
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Query(com.hp.hpl.jena.query.Query) StudyImpl(org.eol.globi.domain.StudyImpl) IOException(java.io.IOException) DatasetLocal(org.eol.globi.service.DatasetLocal) QueryExecution(com.hp.hpl.jena.query.QueryExecution) DateTime(org.joda.time.DateTime) Date(java.util.Date) Specimen(org.eol.globi.domain.Specimen) QuerySolution(com.hp.hpl.jena.query.QuerySolution) Model(com.hp.hpl.jena.rdf.model.Model) ResultSet(com.hp.hpl.jena.query.ResultSet) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 2 with InteractType

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;
}
Also used : InteractType(org.eol.globi.domain.InteractType) HashMap(java.util.HashMap)

Example 3 with InteractType

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;
}
Also used : InteractType(org.eol.globi.domain.InteractType) HashMap(java.util.HashMap)

Example 4 with 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));
}
Also used : InteractType(org.eol.globi.domain.InteractType) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Example 5 with InteractType

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()));
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Test(org.junit.Test)

Aggregations

InteractType (org.eol.globi.domain.InteractType)23 Study (org.eol.globi.domain.Study)9 HashMap (java.util.HashMap)8 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)7 IOException (java.io.IOException)7 Specimen (org.eol.globi.domain.Specimen)7 StudyImpl (org.eol.globi.domain.StudyImpl)5 TaxonImpl (org.eol.globi.domain.TaxonImpl)4 Test (org.junit.Test)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 JsonNode (org.codehaus.jackson.JsonNode)3 Node (org.neo4j.graphdb.Node)3 CSVPrint (com.Ostermiller.util.CSVPrint)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 ZipEntry (java.util.zip.ZipEntry)2