Search in sources :

Example 1 with LocationImpl

use of org.eol.globi.domain.LocationImpl 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 LocationImpl

use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForRobledo method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String description = "García-Robledo C, Erickson DL, Staines CL, Erwin TL, Kress WJ. Tropical Plant–Herbivore Networks: Reconstructing Species Interactions Using DNA Barcodes Heil M, editor. PLoS ONE [Internet]. 2013 January 8;8(1):e52967. Available from: http://dx.doi.org/10.1371/journal.pone.0052967";
    String doi = "http://dx.doi.org/10.1371/journal.pone.0052967";
    Study study1 = new StudyImpl("García-Robledo et al 2013", description, doi, description);
    Study study = nodeFactory.getOrCreateStudy(study1);
    Map<String, String> abrLookup = buildPlantLookup();
    // spatial location from: http://www.ots.ac.cr/index.php?option=com_content&task=view&id=163&Itemid=348
    Double latitude = LocationUtil.parseDegrees("10°26'N");
    Double longitude = LocationUtil.parseDegrees("83°59'W");
    Location location;
    try {
        location = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, 35.0, null));
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create location", e);
    }
    // TODO: need to map date range of collections
    String studyResource = "robledo/table_s1_extract.csv";
    try {
        LabeledCSVParser parser = parserFactory.createParser(studyResource, CharsetConstant.UTF8);
        while (parser.getLine() != null) {
            String beetleName = parser.getValueByLabel("Herbivore species");
            String beetleScientificName = completeBeetleName(beetleName);
            Specimen predator = nodeFactory.createSpecimen(study, new TaxonImpl(beetleScientificName, null));
            predator.caughtIn(location);
            for (String plantAbbreviation : abrLookup.keySet()) {
                String plantScientificName = abrLookup.get(plantAbbreviation);
                String valueByLabel = parser.getValueByLabel(plantAbbreviation);
                try {
                    int interactionCode = Integer.parseInt(valueByLabel);
                    if (interactionCode > 0) {
                        Specimen plant = nodeFactory.createSpecimen(study, new TaxonImpl(plantScientificName, null));
                        plant.caughtIn(location);
                        predator.ate(plant);
                    }
                } catch (NumberFormatException ex) {
                    getLogger().warn(study, "malformed or no value [" + valueByLabel + "] found for [" + plantScientificName + "(" + plantAbbreviation + ")" + "] and beetle [" + beetleScientificName + "] could be found in [" + studyResource + ":" + parser.lastLineNumber() + "]");
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("problem reading [" + studyResource + "]", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("cannot create specimens from [" + studyResource + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 3 with LocationImpl

use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForWebOfLife method parseLocation.

public Location parseLocation(LabeledCSVParser parser) throws StudyImporterException {
    Location networkLocation = null;
    final String latitude = parser.getValueByLabel("Latitude");
    final String longitude = parser.getValueByLabel("Longitude");
    if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) {
        try {
            final double lat = Double.parseDouble(latitude);
            final double lng = Double.parseDouble(longitude);
            networkLocation = nodeFactory.getOrCreateLocation(new LocationImpl(lat, lng, null, null));
        } catch (NumberFormatException ex) {
            throw new StudyImporterException("found invalid lat,lng pair: [" + latitude + "], [" + longitude + "] on line [" + parser.lastLineNumber() + "] in [references.csv]");
        }
    }
    return networkLocation;
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 4 with LocationImpl

use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForRoopnarine method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String suffix = ".csv";
    String prefix = "roopnarine/857470.item.";
    String trophicGuildLookup = prefix + 4 + suffix;
    final Map<Integer, List<String>> trophicGuildNumberToSpeciesMap = buildGuildLookup(trophicGuildLookup);
    Map<String, LatLng> resourceLocation = resourceLocationMap(suffix, prefix);
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Roopnarine et al 2013", "Roopnarine, P.D. & Hertog, R., 2013. Detailed Food Web Networks of Three Greater Antillean Coral Reef Systems: The Cayman Islands, Cuba, and Jamaica. DatasetImpl Papers in Ecology, 2013, pp.1–9. Available at: http://dx.doi.org/10.7167/2013/857470.", "http://dx.doi.org/10.7167/2013/857470", null));
    for (Map.Entry<String, LatLng> resourceLatLngEntry : resourceLocation.entrySet()) {
        LatLng latLng = resourceLatLngEntry.getValue();
        Location location;
        try {
            location = nodeFactory.getOrCreateLocation(new LocationImpl(latLng.getLat(), latLng.getLng(), 0.0, null));
        } catch (NodeFactoryException e) {
            throw new StudyImporterException("failed to create location", e);
        }
        String studyResource = resourceLatLngEntry.getKey();
        getLogger().info(study, "import of [" + studyResource + "] started...");
        List<Specimen> predatorSpecimen = importTrophicInteractions(trophicGuildLookup, trophicGuildNumberToSpeciesMap, studyResource, study, location);
        getLogger().info(study, "import of [" + studyResource + "] done.");
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(org.eol.globi.geo.LatLng) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.eol.globi.domain.Location)

Example 5 with LocationImpl

use of org.eol.globi.domain.LocationImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForSPIRE method importValidLink.

private void importValidLink(Map<String, String> properties) throws NodeFactoryException {
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl(properties.get(StudyConstant.TITLE), SOURCE_SPIRE, null, properties.get(StudyConstant.DESCRIPTION)));
    try {
        Specimen predator = createSpecimen(properties.get(PREDATOR_NAME), study);
        String locality = properties.get(LOCALITY_ORIGINAL);
        LatLng latLng = getGeoNamesService().findLatLng(locality);
        if (latLng == null) {
            getLogger().warn(study, "failed to find location for county [" + locality + "]");
        } else {
            Location location = nodeFactory.getOrCreateLocation(new LocationImpl(latLng.getLat(), latLng.getLng(), null, null));
            predator.caughtIn(location);
            String habitat = properties.get(OF_HABITAT);
            if (StringUtils.isNotBlank(habitat)) {
                addEnvironment(location, "SPIRE:" + habitat, habitat);
            }
        }
        Specimen prey = createSpecimen(properties.get(PREY_NAME), study);
        predator.ate(prey);
    } catch (NodeFactoryException e) {
        getLogger().warn(study, "failed to import trophic link with properties [" + properties + "]: " + e.getMessage());
    } catch (IOException e) {
        getLogger().warn(study, "failed to import trophic link with properties [" + properties + "]: " + e.getMessage());
    }
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) IOException(java.io.IOException) Location(org.eol.globi.domain.Location)

Aggregations

LocationImpl (org.eol.globi.domain.LocationImpl)40 Location (org.eol.globi.domain.Location)32 Specimen (org.eol.globi.domain.Specimen)22 Study (org.eol.globi.domain.Study)20 TaxonImpl (org.eol.globi.domain.TaxonImpl)15 StudyImpl (org.eol.globi.domain.StudyImpl)13 IOException (java.io.IOException)10 LatLng (org.eol.globi.geo.LatLng)9 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)8 Date (java.util.Date)8 Relationship (org.neo4j.graphdb.Relationship)7 HashMap (java.util.HashMap)6 Taxon (org.eol.globi.domain.Taxon)6 TermImpl (org.eol.globi.domain.TermImpl)6 Test (org.junit.Test)6 Node (org.neo4j.graphdb.Node)6 ArrayList (java.util.ArrayList)5 SpecimenNode (org.eol.globi.domain.SpecimenNode)3 List (java.util.List)2 Map (java.util.Map)2