Search in sources :

Example 21 with Location

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

the class StudyImporterForSzoboszlaiIT method importAll.

@Test
public void importAll() throws StudyImporterException, IOException {
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Szoboszlai AI, Thayer JA, Wood SA, Sydeman WJ, Koehn LE (2015) Data from: Forage species in predator diets: synthesis of data from the California Current. Dryad Digital Repository. http://dx.doi.org/10.5061/dryad.nv5d2\",\n" + "  \"doi\": \"http://dx.doi.org/10.5061/dryad.nv5d2\",\n" + "  \"format\": \"szoboszlai\",\n" + "  \"resources\": {\n" + "    \"links\": \"http://datadryad.org/bitstream/handle/10255/dryad.94536/CCPDDlinkdata_v1.csv\",\n" + "    \"shapes\": \"http://datadryad.org/bitstream/handle/10255/dryad.94535/CCPDDlocationdata_v1.zip\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetImpl("someRepo", URI.create("http://example.com"));
    dataset.setConfig(config);
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    StudyImporterForSzoboszlai importer = new StudyImporterForSzoboszlai(parserFactory, nodeFactory);
    importer.setDataset(dataset);
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(not(0)));
    Study firstStudy = allStudies.get(0);
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(firstStudy);
    for (Relationship specimen : specimens) {
        Specimen specimenNode = new SpecimenNode(specimen.getEndNode());
        Location sampleLocation = specimenNode.getSampleLocation();
        assertThat(sampleLocation, is(notNullValue()));
        assertThat(sampleLocation.getLatitude(), is(notNullValue()));
        assertThat(sampleLocation.getLongitude(), is(notNullValue()));
    }
    assertThat(taxonIndex.findTaxonByName("Thunnus thynnus"), is(notNullValue()));
    assertThat(nodeFactory.findLocation(new LocationImpl(34.00824202376044, -120.72716166720323, null, null)), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) SpecimenNode(org.eol.globi.domain.SpecimenNode) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 22 with Location

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

the class StudyImporterForBrose method addInteractionForConsumer.

private void addInteractionForConsumer(LabeledCSVParser parser, Study localStudy, String predatorName) throws NodeFactoryException, StudyImporterException {
    Location location = null;
    String locationString = parser.getValueByLabel("Geographic location");
    LatLng latLng = LOC_MAP.get(StringUtils.trim(locationString));
    if (latLng == null) {
        getLogger().warn(localStudy, "failed to find location for [" + locationString + "]");
    } else {
        location = nodeFactory.getOrCreateLocation(new LocationImpl(latLng.getLat(), latLng.getLng(), null, null));
        String habitat = StringUtils.join(parser.getValueByLabel("General habitat"), " ", parser.getValueByLabel("Specific habitat"));
        String habitatId = "BROSE:" + habitat.replaceAll("\\W", "_");
        nodeFactory.getOrCreateEnvironments(location, habitatId, habitat);
    }
    Specimen consumer = nodeFactory.createSpecimen(localStudy, new TaxonImpl(predatorName, null));
    consumer.caughtIn(location);
    addLifeStage(parser, consumer, "Lifestage consumer");
    String name = getName(parser, "Taxonomy resource", "Common name(s) resource");
    if (StringUtils.isBlank(name) || StringUtils.length(name) < 2) {
        String message = "found (near) empty prey name on line [" + parser.lastLineNumber() + "] + [" + name + "]";
        LOG.warn(message);
        getLogger().warn(localStudy, message);
    } else {
        Specimen resource = nodeFactory.createSpecimen(localStudy, new TaxonImpl(name, null));
        resource.caughtIn(location);
        addLifeStage(parser, resource, "Lifestage - resource");
        String interactionType = parser.getValueByLabel("Type of feeding interaction");
        Map<String, InteractType> typeMapping = new HashMap<String, InteractType>() {

            {
                put("predacious", InteractType.PREYS_UPON);
                put("predator", InteractType.PREYS_UPON);
                put("herbivorous", InteractType.ATE);
                put("parasitoid", InteractType.PARASITE_OF);
                put("parasitic", InteractType.PARASITE_OF);
                put("bacterivorous", InteractType.ATE);
                put("omnivore", InteractType.ATE);
                put("detritivorous", InteractType.ATE);
                put("pathogen", InteractType.PATHOGEN_OF);
            }
        };
        InteractType interactType = typeMapping.get(interactionType);
        if (interactType == null) {
            throw new StudyImporterException("found unsupported interaction type [" + interactionType + "]");
        }
        consumer.interactsWith(resource, interactType);
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Specimen(org.eol.globi.domain.Specimen) HashMap(java.util.HashMap) TaxonImpl(org.eol.globi.domain.TaxonImpl) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Example 23 with Location

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

the class StudyImporterForBaremore method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    Study study;
    try {
        LabeledCSVParser parser = parserFactory.createParser(DATA_SOURCE, CharsetConstant.UTF8);
        String[] line;
        study = nodeFactory.getOrCreateStudy(new StudyImpl("Baremore 2010", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, "doi:10.3354/ab00214", ExternalIdUtil.toCitation("Ivy E. Baremore", "Prey Selection By The Atlantic Angel Shark Squatina Dumeril In The Northeastern Gulf Of Mexico.", "2010")));
        Location collectionLocation = nodeFactory.getOrCreateLocation(new LocationImpl(29.219302, -87.06665, null, null));
        Map<Integer, Specimen> specimenMap = new HashMap<Integer, Specimen>();
        while ((line = parser.getLine()) != null) {
            Integer sharkId = Integer.parseInt(line[0]);
            String collectionDateString = line[1];
            if (isBlank(collectionDateString)) {
                getLogger().warn(study, "line [" + parser.getLastLineNumber() + "] in [" + DATA_SOURCE + "]: missing collection date");
            } else {
                Specimen predatorSpecimen = specimenMap.get(sharkId);
                if (predatorSpecimen == null) {
                    predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Squatina dumeril", null));
                    predatorSpecimen.caughtIn(collectionLocation);
                    addLifeStage(parser, predatorSpecimen);
                    addCollectionDate(collectionDateString, predatorSpecimen);
                }
                specimenMap.put(sharkId, predatorSpecimen);
                String totalLengthInCm = line[3];
                try {
                    Double lengthInMm = Double.parseDouble(totalLengthInCm) * 10.0;
                    predatorSpecimen.setLengthInMm(lengthInMm);
                } catch (NumberFormatException ex) {
                    throw new StudyImporterException("failed to parse length [" + totalLengthInCm);
                }
                String preySpeciesDescription = line[7];
                if (StringUtils.isBlank(preySpeciesDescription)) {
                    getLogger().info(study, "found blank prey species description [" + preySpeciesDescription + "] on line [" + parser.lastLineNumber() + "]");
                } else {
                    Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesDescription, null));
                    preySpecimen.caughtIn(collectionLocation);
                    predatorSpecimen.ate(preySpecimen);
                    nodeFactory.setUnixEpochProperty(preySpecimen, nodeFactory.getUnixEpochProperty(predatorSpecimen));
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to parse labels", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) 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 24 with Location

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

the class StudyImporterForBlewett method buildLocationTimeMaps.

private void buildLocationTimeMaps(Map<String, Location> collectionLocationMap, Map<String, Date> collectionTimeMap, Study study) throws IOException, StudyImporterException {
    LabeledCSVParser locationParser = parserFactory.createParser("blewett/SnookDietData2000_02_Charlotte_Harbor_FL_Blewett_date_and_abiotic.csv", CharsetConstant.UTF8);
    String[] line;
    while ((line = locationParser.getLine()) != null) {
        if (line.length < 3) {
            getLogger().warn(study, "line:" + locationParser.getLastLineNumber() + " [" + StringUtils.join(line, ",") + "] has missing location information");
        }
        String collectionCode = locationParser.getValueByLabel(COLLECTION_NO);
        if (StringUtils.isBlank(collectionCode)) {
            getLogger().warn(study, "blank location code for line: [" + locationParser.getLastLineNumber() + "]");
        }
        String latitude = locationParser.getValueByLabel("Latitude");
        if (StringUtils.isBlank(latitude)) {
            getLogger().warn(study, "blank value for lattitude for line: [" + locationParser.getLastLineNumber() + "]");
        }
        String longitude = locationParser.getValueByLabel("Longitude");
        if (StringUtils.isBlank(longitude)) {
            getLogger().warn(study, "blank value for longitude for line: [" + locationParser.getLastLineNumber() + "]");
        }
        Location location;
        try {
            location = nodeFactory.getOrCreateLocation(new LocationImpl(Double.parseDouble(latitude), Double.parseDouble(longitude), 0.0, null));
        } catch (NodeFactoryException e) {
            throw new StudyImporterException("failed to create location", e);
        }
        collectionLocationMap.put(collectionCode, location);
        String timeString = locationParser.getValueByLabel("Time");
        if (StringUtils.isBlank(timeString)) {
            getLogger().warn(study, "blank value for time for line: [" + locationParser.getLastLineNumber() + "]");
        }
        String dateString = locationParser.getValueByLabel("Date");
        if (StringUtils.isBlank(dateString)) {
            getLogger().warn(study, "blank value for date for line: [" + locationParser.getLastLineNumber() + "]");
        }
        String dateTimeString = dateString + " " + timeString;
        try {
            Date dateTime = parseDateString(dateTimeString);
            collectionTimeMap.put(collectionCode, dateTime);
        } catch (ParseException e) {
            throw new StudyImporterException("failed to parse date time [" + dateTimeString + "] for collection [" + collectionCode + "] on line [" + locationParser.getLastLineNumber() + "]");
        }
    }
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) ParseException(java.text.ParseException) Date(java.util.Date) Location(org.eol.globi.domain.Location)

Example 25 with Location

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

the class StudyImporterForBarnes method addInteractionForPredator.

private void addInteractionForPredator(LabeledCSVParser parser, Study localStudy, String predatorName) throws NodeFactoryException, StudyImporterException {
    Specimen predator = nodeFactory.createSpecimen(localStudy, new TaxonImpl(predatorName, null));
    addLifeStage(parser, predator);
    Double latitude = LocationUtil.parseDegrees(parser.getValueByLabel("Latitude"));
    Double longitude = LocationUtil.parseDegrees(parser.getValueByLabel("Longitude"));
    String depth = parser.getValueByLabel("Depth");
    Double altitudeInMeters = -1.0 * Double.parseDouble(depth);
    Location location = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitudeInMeters, null));
    predator.caughtIn(location);
    String preyName = parser.getValueByLabel("Prey");
    if (StringUtils.isBlank(preyName)) {
        getLogger().warn(localStudy, "found empty prey name on line [" + parser.lastLineNumber() + "]");
    } else {
        Specimen prey = nodeFactory.createSpecimen(localStudy, new TaxonImpl(preyName, null));
        prey.caughtIn(location);
        predator.ate(prey);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Aggregations

Location (org.eol.globi.domain.Location)44 LocationImpl (org.eol.globi.domain.LocationImpl)32 Specimen (org.eol.globi.domain.Specimen)31 Study (org.eol.globi.domain.Study)24 StudyImpl (org.eol.globi.domain.StudyImpl)16 TaxonImpl (org.eol.globi.domain.TaxonImpl)16 Date (java.util.Date)14 IOException (java.io.IOException)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 HashMap (java.util.HashMap)8 LatLng (org.eol.globi.geo.LatLng)8 TermImpl (org.eol.globi.domain.TermImpl)6 Test (org.junit.Test)6 Relationship (org.neo4j.graphdb.Relationship)6 SpecimenNode (org.eol.globi.domain.SpecimenNode)5 ArrayList (java.util.ArrayList)4 Taxon (org.eol.globi.domain.Taxon)4 Node (org.neo4j.graphdb.Node)3 List (java.util.List)2 Map (java.util.Map)2