Search in sources :

Example 1 with Term

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

the class StudyImporterForKelpForest method createSpecimen.

protected Specimen createSpecimen(LabeledCSVParser parser, Map<String, Long> nameToId, String nameLabel, String stageLabel, Study study) throws NodeFactoryException {
    String sourceName = parser.getValueByLabel(nameLabel);
    Long id = nameToId.get(sourceName);
    String taxonExternalId = id == null ? null : TaxonomyProvider.ID_PREFIX_ITIS + id;
    Specimen sourceSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(sourceName, taxonExternalId));
    String sourceLifeStage = parser.getValueByLabel(stageLabel);
    Term orCreateLifeStage = nodeFactory.getOrCreateLifeStage("KELP:" + sourceLifeStage, sourceLifeStage);
    sourceSpecimen.setLifeStage(orCreateLifeStage);
    return sourceSpecimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term)

Example 2 with Term

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

the class StudyImporterForSPIRE method addLifeStage.

private void addLifeStage(Specimen specimen, String name) throws NodeFactoryException {
    Term terms;
    terms = nodeFactory.getOrCreateLifeStage("SPIRE:" + name, name);
    specimen.setLifeStage(terms);
}
Also used : Term(org.eol.globi.domain.Term)

Example 3 with Term

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

Example 4 with Term

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

the class StudyImporterForHechinger method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    Study study = createStudy();
    try {
        LabeledCSVParser nodes = parserFactory.createParser(getNodesResourceName(), CharsetConstant.UTF8);
        nodes.changeDelimiter(getDelimiter());
        Map<Integer, Term> stageForNode = new HashMap<>();
        Map<Integer, String> taxonForNode = new HashMap<Integer, String>();
        while (nodes.getLine() != null) {
            Integer nodeId = getNodeId(nodes);
            if (nodeId != null) {
                String name = parseMostGranularTaxonName(nodes);
                if (StringUtils.isBlank(name)) {
                    name = nodes.getValueByLabel("WorkingName");
                    if (StringUtils.isBlank(name)) {
                        getLogger().warn(study, "failed to find name for node on line [" + nodes.lastLineNumber() + "]");
                    }
                }
                if (StringUtils.isNotBlank(name)) {
                    try {
                        taxonForNode.put(nodeId, name);
                        String stage = nodes.getValueByLabel("Stage");
                        stageForNode.put(nodeId, nodeFactory.getOrCreateLifeStage(getNamespace() + ":" + stage, stage));
                    } catch (NodeFactoryException e) {
                        throw new StudyImporterException("failed to reader line [" + nodes.lastLineNumber() + "]", e);
                    }
                }
            }
        }
        LabeledCSVParser links = parserFactory.createParser(getLinksResourceName(), CharsetConstant.UTF8);
        links.changeDelimiter(getDelimiter());
        while (links.getLine() != null) {
            List<Location> locations = new ArrayList<>();
            if (getLocation() != null) {
                Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(getLocation().getLat(), getLocation().getLng(), null, null));
                if (loc != null) {
                    locations.add(loc);
                }
            }
            if (StringUtils.equals("1", links.getValueByLabel("PresentAtCSM"))) {
                locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(34.403511, -119.537873, null, null)));
            }
            if (StringUtils.equals("1", links.getValueByLabel("PresentAtEPB"))) {
                locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(31.748606, -116.626854, null, null)));
            }
            if (StringUtils.equals("1", links.getValueByLabel("PresentAtBSQ"))) {
                locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(30.378207, -115.938835, null, null)));
            }
            for (Location location : locations) {
                addLink(study, stageForNode, taxonForNode, links, location);
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("failed import study", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Term(org.eol.globi.domain.Term) IOException(java.io.IOException) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 5 with Term

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

the class StudyImporterForGoMexSI2 method addPhysiologicalState.

private void addPhysiologicalState(Map<String, String> properties, Specimen specimen) throws StudyImporterException {
    try {
        String name = properties.get(SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL);
        Term term = nodeFactory.getOrCreatePhysiologicalState(GOMEXSI_NAMESPACE + name, name);
        specimen.setPhysiologicalState(term);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to map life stage", e);
    }
}
Also used : Term(org.eol.globi.domain.Term)

Aggregations

Term (org.eol.globi.domain.Term)16 HashMap (java.util.HashMap)4 Study (org.eol.globi.domain.Study)4 IOException (java.io.IOException)3 Specimen (org.eol.globi.domain.Specimen)3 TaxonImpl (org.eol.globi.domain.TaxonImpl)3 TermImpl (org.eol.globi.domain.TermImpl)3 Location (org.eol.globi.domain.Location)2 LocationImpl (org.eol.globi.domain.LocationImpl)2 SpecimenNode (org.eol.globi.domain.SpecimenNode)2 Test (org.junit.Test)2 Relationship (org.neo4j.graphdb.Relationship)2 CSVParse (com.Ostermiller.util.CSVParse)1 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)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 TsvParserSettings (com.univocity.parsers.tsv.TsvParserSettings)1