Search in sources :

Example 6 with LocationImpl

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

the class StudyImporterForSimons method getOrCreateSampleLocation.

private Location getOrCreateSampleLocation(LabeledCSVParser csvParser, Map<String, String> columnToNormalizedTermMapper) throws StudyImporterException {
    Double northing = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(NORTHING));
    Double easting = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(EASTING));
    Double latitude = null;
    Double longitude = null;
    if (easting != null && northing != null) {
        UTMRef utmRef = new UTMRef(easting, northing, 'R', 16);
        LatLng latLng = utmRef.toLatLng();
        latitude = latLng.getLat();
        longitude = latLng.getLng();
    }
    Double depth = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(DEPTH));
    Double altitude = depth == null ? null : -depth;
    try {
        return nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitude, null));
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create location", e);
    }
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) UTMRef(uk.me.jstott.jcoord.UTMRef) LatLng(uk.me.jstott.jcoord.LatLng)

Example 7 with LocationImpl

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

the class StudyImporterForGoMexSI2IT method assertThatSomeDataIsImported.

private static void assertThatSomeDataIsImported(NodeFactory nodeFactory, TaxonIndex taxonIndex) throws StudyImporterException, NodeFactoryException {
    Study study = nodeFactory.findStudy("Divita et al 1983");
    assertSpecimenProperties(((NodeBacked) study).getUnderlyingNode().getGraphDatabase());
    assertNotNull(study);
    assertThat(study.getTitle(), is("Divita et al 1983"));
    assertThat(study.getExternalId(), is(ExternalIdUtil.urlForExternalId("GAME:2689")));
    assertThat(study.getCitation(), is("Regina Divita, Mischelle Creel, Peter Sheridan. 1983. Foods of coastal fishes during brown shrimp Penaeus aztecus, migration from Texas estuaries (June - July 1981)."));
    assertNotNull(nodeFactory.findStudy("Beaumariage 1973"));
    assertNotNull(nodeFactory.findStudy("Baughman, 1943"));
    assertNotNull(taxonIndex.findTaxonByName("Chloroscombrus chrysurus"));
    assertNotNull(taxonIndex.findTaxonByName("Micropogonias undulatus"));
    assertNotNull(taxonIndex.findTaxonByName("Amphipoda"));
    assertNotNull(taxonIndex.findTaxonByName("Crustacea"));
    Taxon taxon = taxonIndex.findTaxonByName("Scomberomorus cavalla");
    List<String> preyList = new ArrayList<String>();
    final List<String> titles = new ArrayList<String>();
    Iterable<Relationship> classifiedAsRels = ((NodeBacked) taxon).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    int count = 0;
    for (Relationship classifiedAsRel : classifiedAsRels) {
        Node predatorSpecimen = classifiedAsRel.getStartNode();
        Specimen predator = new SpecimenNode(predatorSpecimen);
        Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(predator);
        for (Relationship prey : stomachContents) {
            Relationship singleRelationship = prey.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
            preyList.add((String) singleRelationship.getEndNode().getProperty("name"));
        }
        count++;
        Relationship collectedBy = predatorSpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED), Direction.INCOMING);
        assertThat(collectedBy, is(notNullValue()));
        String title = (String) collectedBy.getStartNode().getProperty("title");
        titles.add(title);
    }
    assertThat(count > 7, is(true));
    assertThat(preyList, hasItem("Organic matter"));
    assertThat(preyList, hasItem("Triglidae"));
    assertThat(preyList, hasItem("Sparidae"));
    assertThat(titles, hasItem("Beaumariage 1973"));
    assertThat(titles, hasItem("Blanton et al 1972"));
    assertNotNull(taxon);
    final String footprintWKT = WKT_FOOTPRINT2;
    LocationImpl expectedLocation = new LocationImpl(29.346953, -92.980614, -13.641, footprintWKT);
    expectedLocation.setLocality("Louisiana inner continental shelf");
    Location location = nodeFactory.findLocation(expectedLocation);
    assertThat(location, is(notNullValue()));
    assertThat(location.getFootprintWKT(), is(footprintWKT));
    assertThat(location.getLocality(), is("Louisiana inner continental shelf"));
    assertNotNull(location);
    List<Environment> environments = location.getEnvironments();
    assertThat(environments.size(), not(is(0)));
    assertThat(environments.get(0).getExternalId(), is("http://cmecscatalog.org/classification/aquaticSetting/13"));
    assertThat(environments.get(0).getName(), is("Marine Nearshore Subtidal"));
    assertNotNull(nodeFactory.findStudy("GoMexSI"));
}
Also used : Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) ArrayList(java.util.ArrayList) SpecimenNode(org.eol.globi.domain.SpecimenNode) Specimen(org.eol.globi.domain.Specimen) NodeBacked(org.eol.globi.domain.NodeBacked) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Environment(org.eol.globi.domain.Environment) Location(org.eol.globi.domain.Location)

Example 8 with LocationImpl

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

the class ExportTestUtil method createTestData.

public static Study createTestData(Double length, NodeFactory factory) throws NodeFactoryException, ParseException {
    Study myStudy = factory.createStudy(new StudyImpl("myStudy", null, null, null));
    Specimen specimen1 = factory.createSpecimen(myStudy, new TaxonImpl("Homo sapiens", "EOL:45634"));
    specimen1.setStomachVolumeInMilliLiter(666.0);
    specimen1.setLifeStage(new TermImpl("GLOBI:JUVENILE", "JUVENILE"));
    specimen1.setPhysiologicalState(new TermImpl("GLOBI:DIGESTATE", "DIGESTATE"));
    specimen1.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
    factory.setUnixEpochProperty(specimen1, ExportTestUtil.utcTestDate());
    final Specimen specimen2 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
    specimen2.setVolumeInMilliLiter(124.0);
    specimen1.ate(specimen2);
    final Specimen specimen3 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
    specimen3.setVolumeInMilliLiter(18.0);
    specimen1.ate(specimen3);
    if (null != length) {
        specimen1.setLengthInMm(length);
    }
    Location location = factory.getOrCreateLocation(new LocationImpl(88.0, -120.0, -60.0, null));
    specimen1.caughtIn(location);
    return myStudy;
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) TermImpl(org.eol.globi.domain.TermImpl) Location(org.eol.globi.domain.Location)

Example 9 with LocationImpl

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

the class ExporterAssociationAggregatesTest method createTestData.

private void createTestData(Double length, String studyTitle) throws NodeFactoryException, ParseException {
    Study myStudy = nodeFactory.getOrCreateStudy(new StudyImpl(studyTitle, "data source description", null, ExternalIdUtil.toCitation("contributor", "description", "pubYear")));
    Specimen specimen = nodeFactory.createSpecimen(myStudy, setPathAndId(new TaxonImpl("Homo sapiens", null)));
    specimen.setStomachVolumeInMilliLiter(666.0);
    specimen.setLifeStage(new TermImpl("GlOBI:JUVENILE", "JUVENILE"));
    specimen.setPhysiologicalState(new TermImpl("GlOBI:DIGESTATE", "DIGESTATE"));
    specimen.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
    nodeFactory.setUnixEpochProperty(specimen, new Date(ExportTestUtil.utcTestTime()));
    TaxonImpl taxon = new TaxonImpl("Canis lupus", null);
    Specimen otherSpecimen = nodeFactory.createSpecimen(myStudy, setPathAndId(taxon));
    otherSpecimen.setVolumeInMilliLiter(124.0);
    specimen.ate(otherSpecimen);
    specimen.ate(otherSpecimen);
    if (null != length) {
        specimen.setLengthInMm(length);
    }
    Location location = nodeFactory.getOrCreateLocation(new LocationImpl(44.0, 120.0, -60.0, null));
    specimen.caughtIn(location);
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Location(org.eol.globi.domain.Location)

Example 10 with LocationImpl

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

the class StudyImporterForHurlbert method importInteraction.

protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
    try {
        Taxon predatorTaxon = new TaxonImpl(predatorName);
        Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
        setBasisOfRecordAsLiterature(predatorSpecimen);
        Taxon preyTaxon = new TaxonImpl(preyTaxonName);
        String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
        if (NumberUtils.isDigits(preyNameId)) {
            preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
        }
        Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
        setBasisOfRecordAsLiterature(preySpecimen);
        String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
        if (StringUtils.isNotBlank(preyStage)) {
            Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
            preySpecimen.setLifeStage(lifeStage);
        }
        String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
        if (StringUtils.isNotBlank(preyPart)) {
            Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
            preySpecimen.setBodyPart(term);
        }
        Date date = addCollectionDate(record, study);
        nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
        nodeFactory.setUnixEpochProperty(preySpecimen, date);
        LocationImpl location = new LocationImpl(null, null, null, null);
        String longitude = columnValueOrNull(record, "Longitude_dd");
        String latitude = columnValueOrNull(record, "Latitude_dd");
        if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
            try {
                LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
                String altitude = columnValueOrNull(record, "Altitude_mean_m");
                Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
                location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
            } catch (InvalidLocationException e) {
                getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
            }
        }
        String locationRegion = columnValueOrNull(record, "Location_Region");
        String locationSpecific = columnValueOrNull(record, "Location_Specific");
        location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
        Location locationNode = nodeFactory.getOrCreateLocation(location);
        String habitat_type = columnValueOrNull(record, "Habitat_type");
        List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
        nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
        preySpecimen.caughtIn(locationNode);
        predatorSpecimen.caughtIn(locationNode);
        predatorSpecimen.ate(preySpecimen);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
    }
}
Also used : TsvParser(com.univocity.parsers.tsv.TsvParser) DateUtil(org.eol.globi.util.DateUtil) StringUtils(org.apache.commons.lang.StringUtils) CitationUtil(org.globalbioticinteractions.dataset.CitationUtil) Arrays(java.util.Arrays) Record(com.univocity.parsers.common.record.Record) Term(org.eol.globi.domain.Term) Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) Map(java.util.Map) LatLng(org.eol.globi.geo.LatLng) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) InvalidLocationException(org.eol.globi.util.InvalidLocationException) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TsvParserSettings(com.univocity.parsers.tsv.TsvParserSettings) List(java.util.List) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Study(org.eol.globi.domain.Study) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) InvalidLocationException(org.eol.globi.util.InvalidLocationException) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Specimen(org.eol.globi.domain.Specimen) StringUtils(org.apache.commons.lang.StringUtils) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) 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