Search in sources :

Example 66 with TaxonImpl

use of org.eol.globi.domain.TaxonImpl 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 67 with TaxonImpl

use of org.eol.globi.domain.TaxonImpl 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 68 with TaxonImpl

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

the class StudyImporterForAkin method addPrey.

private void addPrey(Study study, LabeledCSVParser parser, String[] header, String[] line, Specimen specimen, Location location) throws StudyImporterException {
    int firstPreyIndex = findIndexForColumnWithNameThrowOnMissing("Detritus", header);
    for (int i = firstPreyIndex; i < line.length; i++) {
        String preySpeciesName = header[i];
        if (StringUtils.isNotBlank(preySpeciesName)) {
            String preyVolumeString = line[i];
            try {
                if (StringUtils.isNotBlank(preyVolumeString)) {
                    double volume = Double.parseDouble(preyVolumeString);
                    if (volume > 0) {
                        Specimen prey = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesName, null));
                        prey.setLifeStage(parseLifeStage(nodeFactory.getTermLookupService(), preySpeciesName));
                        prey.setVolumeInMilliLiter(volume);
                        prey.caughtIn(location);
                        specimen.ate(prey);
                    }
                }
            } catch (NumberFormatException ex) {
                throw new StudyImporterException("failed to parse volume of prey [" + preySpeciesName + "] in stomach [" + preyVolumeString + "] on line [" + parser.getLastLineNumber() + "]");
            } catch (TermLookupServiceException e) {
                throw new StudyImporterException("failed to parse life stage of prey [" + preySpeciesName + "] in stomach [" + preyVolumeString + "] on line [" + parser.getLastLineNumber() + "]");
            }
        }
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 69 with TaxonImpl

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

Example 70 with TaxonImpl

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

the class StudyImporterForAkin method addSpecimen.

private Specimen addSpecimen(Study study, LabeledCSVParser parser, String[] header, String[] line) throws StudyImporterException, NodeFactoryException {
    Specimen specimen = null;
    int speciesIndex = findIndexForColumnWithNameThrowOnMissing("Fish Species", header);
    String speciesName = line[speciesIndex];
    if (StringUtils.isNotBlank(speciesName)) {
        specimen = nodeFactory.createSpecimen(study, new TaxonImpl(speciesName, null));
        addSpecimenLength(parser, header, line, specimen, study);
        addStomachVolume(parser, header, line, specimen, study);
        addCollectionDate(study, parser, header, line, specimen);
    } else {
        getLogger().warn(study, "found blank species name on line [" + parser.lastLineNumber() + "]");
    }
    return specimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Aggregations

TaxonImpl (org.eol.globi.domain.TaxonImpl)123 Specimen (org.eol.globi.domain.Specimen)59 Test (org.junit.Test)54 Taxon (org.eol.globi.domain.Taxon)42 StudyImpl (org.eol.globi.domain.StudyImpl)34 Study (org.eol.globi.domain.Study)32 Location (org.eol.globi.domain.Location)16 LocationImpl (org.eol.globi.domain.LocationImpl)15 TaxonNode (org.eol.globi.domain.TaxonNode)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 IOException (java.io.IOException)11 TermImpl (org.eol.globi.domain.TermImpl)11 StringWriter (java.io.StringWriter)9 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)7 Map (java.util.Map)5 Node (org.neo4j.graphdb.Node)5 File (java.io.File)4