Search in sources :

Example 1 with TermImpl

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

the class TaxonUtil method mapToTaxon.

public static void mapToTaxon(Map<String, String> properties, Taxon taxon) {
    taxon.setName(properties.get(NAME));
    taxon.setRank(properties.get(RANK));
    final String externalId = properties.get(EXTERNAL_ID);
    taxon.setExternalId(externalId);
    taxon.setPath(properties.get(PATH));
    taxon.setPathIds(properties.get(PATH_IDS));
    taxon.setPathNames(properties.get(PATH_NAMES));
    taxon.setCommonNames(properties.get(COMMON_NAMES));
    final String externalUrl = properties.get(EXTERNAL_URL);
    if (StringUtils.isBlank(externalUrl) && StringUtils.isNotBlank(externalId)) {
        taxon.setExternalUrl(ExternalIdUtil.urlForExternalId(externalId));
    } else {
        taxon.setExternalUrl(externalUrl);
    }
    taxon.setThumbnailUrl(properties.get(THUMBNAIL_URL));
    String statusId = properties.get(STATUS_ID);
    String statusLabel = properties.get(STATUS_LABEL);
    if (StringUtils.isNotBlank(statusId) && StringUtils.isNotBlank(statusLabel)) {
        taxon.setStatus(new TermImpl(statusId, statusLabel));
    }
    taxon.setNameSource(properties.get(NAME_SOURCE));
    taxon.setNameSourceURL(properties.get(NAME_SOURCE_URL));
    taxon.setNameSourceAccessedAt(properties.get(NAME_SOURCE_ACCESSED_AT));
}
Also used : TermImpl(org.eol.globi.domain.TermImpl)

Example 2 with TermImpl

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

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

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

the class InteractionListenerImpl method setBasisOfRecordIfAvailable.

private void setBasisOfRecordIfAvailable(Map<String, String> link, Specimen specimen) {
    final String basisOfRecordName = link.get(BASIS_OF_RECORD_NAME);
    final String basisOfRecordId = link.get(BASIS_OF_RECORD_ID);
    if (StringUtils.isNotBlank(basisOfRecordName) || StringUtils.isNotBlank(basisOfRecordId)) {
        specimen.setBasisOfRecord(new TermImpl(basisOfRecordId, basisOfRecordName));
    }
}
Also used : TermImpl(org.eol.globi.domain.TermImpl)

Example 5 with TermImpl

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

TermImpl (org.eol.globi.domain.TermImpl)19 TaxonImpl (org.eol.globi.domain.TaxonImpl)11 Specimen (org.eol.globi.domain.Specimen)9 Study (org.eol.globi.domain.Study)7 StudyImpl (org.eol.globi.domain.StudyImpl)7 Location (org.eol.globi.domain.Location)6 LocationImpl (org.eol.globi.domain.LocationImpl)6 Date (java.util.Date)5 HashMap (java.util.HashMap)3 Taxon (org.eol.globi.domain.Taxon)3 Term (org.eol.globi.domain.Term)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 LatLng (org.eol.globi.geo.LatLng)2 CSVParse (com.Ostermiller.util.CSVParse)1 Database (com.healthmarketscience.jackcess.Database)1 DatabaseBuilder (com.healthmarketscience.jackcess.DatabaseBuilder)1 Table (com.healthmarketscience.jackcess.Table)1 Record (com.univocity.parsers.common.record.Record)1 TsvParser (com.univocity.parsers.tsv.TsvParser)1