Search in sources :

Example 66 with StudyImpl

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

the class StudyImporterForPlanque method importLink.

private void importLink(LabeledCSVParser parser, Map<String, List<String>> pairWiseKeyToFullCitation) throws NodeFactoryException, StudyImporterException {
    final String linkKey = parser.getValueByLabel("PWKEY");
    List<String> longReferences = pairWiseKeyToFullCitation.get(linkKey);
    if (CollectionUtils.isEmpty(longReferences)) {
        LOG.debug("no reference found for [" + linkKey + "] on line [" + parser.lastLineNumber() + "], using source citation instead");
        longReferences = new ArrayList<String>() {

            {
                add(getSourceCitation());
            }
        };
    }
    for (String longReference : longReferences) {
        String studyId = "PLANQUE-" + StringUtils.abbreviate(longReference, 20) + MD5.getHashString(longReference);
        Study localStudy = nodeFactory.getOrCreateStudy(new StudyImpl(studyId, getSourceCitation(), null, ExternalIdUtil.toCitation(null, longReference, null)));
        String predatorName = parser.getValueByLabel("PREDATOR");
        if (StringUtils.isBlank(predatorName)) {
            getLogger().warn(localStudy, "found empty predator name on line [" + parser.lastLineNumber() + "]");
        } else {
            addInteractionForPredator(parser, localStudy, predatorName);
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl)

Example 67 with StudyImpl

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

the class StudyImporterForKelpForest method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    try {
        String source = "Beas-Luna, R., Novak, M., Carr, M. H., Tinker, M. T., Black, A., Caselle, J. E., … Iles, A. (2014). An Online Database for Informing Ecological Network Models: http://kelpforest.ucsc.edu. PLoS ONE, 9(10), e109356. doi:10.1371/journal.pone.0109356";
        Study study = nodeFactory.getOrCreateStudy(new StudyImpl(source, source, "doi:10.1371/journal.pone.0109356", source));
        LabeledCSVParser parser = parserFactory.createParser(NODES, "UTF-8");
        String[] line;
        Map<String, Long> nameToId = new HashMap<String, Long>();
        while ((line = parser.getLine()) != null) {
            if (line.length > 2) {
                String name = parser.getValueByLabel("working_name");
                String itisId = parser.getValueByLabel("itis_id");
                Long id = StringUtils.isBlank(itisId) ? null : Long.parseLong(itisId);
                id = (id != null && id > 0L) ? id : null;
                nameToId.put(name, id);
            }
        }
        Map<String, InteractType> typeToType = new HashMap<String, InteractType>() {

            {
                put("trophic", InteractType.ATE);
                put("parasitic", InteractType.PARASITE_OF);
            }
        };
        parser = parserFactory.createParser(LINKS, "UTF-8");
        while ((line = parser.getLine()) != null) {
            if (line.length > 2) {
                String interactionType = parser.getValueByLabel("type");
                InteractType interactType = typeToType.get(interactionType);
                if (null == interactType) {
                    LOG.warn("ignoring type [" + interactionType + "] on line: [" + (parser.getLastLineNumber() + 1) + "]");
                } else {
                    Specimen sourceSpecimen = createSpecimen(parser, nameToId, "node_1_working_name", "node1_stage", study);
                    Specimen targetSpecimen = createSpecimen(parser, nameToId, "node_2_working_name", "node2_stage", study);
                    sourceSpecimen.interactsWith(targetSpecimen, interactType);
                }
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("failed to import", e);
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Specimen(org.eol.globi.domain.Specimen)

Example 68 with StudyImpl

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

the class StudyImporterForJRFerrerParis method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String citation = "Ferrer-Paris, José R.; Sánchez-Mercado, Ada Y.; Lozano, Cecilia; Zambrano, Liset; Soto, José; Baettig, Jessica; Leal, María (2014): A compilation of larval host-plant records for six families of butterflies (Lepidoptera: Papilionoidea) from available electronic resources. figshare. http://dx.doi.org/10.6084/m9.figshare.1168861 . " + CitationUtil.createLastAccessedString(RESOURCE);
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Ferrer-Paris 2014", citation, "http://dx.doi.org/10.6084/m9.figshare.1168861", citation));
    try {
        LabeledCSVParser parser = parserFactory.createParser(RESOURCE, CharsetConstant.UTF8);
        while (parser.getLine() != null) {
            String butterflyName = createTaxon(parser, "Lepidoptera Name");
            String plantName = createTaxon(parser, "Hostplant Name");
            if (validNames(butterflyName, plantName, study, parser.lastLineNumber())) {
                addAssociation(study, parser, butterflyName, plantName);
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to access resource [" + RESOURCE + "]");
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

Example 69 with StudyImpl

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

the class NodeFactoryIT method createStudyWithDOIResolving.

@Test
public void createStudyWithDOIResolving() throws NodeFactoryException {
    NodeFactoryNeo4j fullNodeFactory = new NodeFactoryNeo4j(getGraphDb());
    fullNodeFactory.setDoiResolver(new DOIResolverImpl());
    Study study = fullNodeFactory.getOrCreateStudy(new StudyImpl("bla", "source", "doi:10.1073/pnas.1216534110", ""));
    assertThat(study.getCitation(), is("DePalma RA, Burnham DA, Martin LD, Rothschild BM, Larson PL. Physical evidence of predatory behavior in Tyrannosaurus rex. Proceedings of the National Academy of Sciences [Internet]. 2013 July 15;110(31):12560–12564. Available from: http://dx.doi.org/10.1073/pnas.1216534110"));
    assertThat(study.getDOI(), is("doi:10.1073/pnas.1216534110"));
}
Also used : Study(org.eol.globi.domain.Study) DOIResolverImpl(org.eol.globi.service.DOIResolverImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 70 with StudyImpl

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

the class NodeFactoryIT method createStudy.

@Test
public void createStudy() throws NodeFactoryException {
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("bla", "source", "http://dx.doi.org/10.1111/j.1469-7998.1966.tb02907.x", ExternalIdUtil.toCitation(null, "descr", null)));
    assertThat(study.getDOI(), is("http://dx.doi.org/10.1111/j.1469-7998.1966.tb02907.x"));
    assertThat(study.getCitation(), is("http://dx.doi.org/10.1111/j.1469-7998.1966.tb02907.x"));
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Aggregations

StudyImpl (org.eol.globi.domain.StudyImpl)82 Study (org.eol.globi.domain.Study)60 Test (org.junit.Test)40 Specimen (org.eol.globi.domain.Specimen)33 TaxonImpl (org.eol.globi.domain.TaxonImpl)33 IOException (java.io.IOException)20 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)17 Location (org.eol.globi.domain.Location)15 StringWriter (java.io.StringWriter)12 LocationImpl (org.eol.globi.domain.LocationImpl)12 Date (java.util.Date)9 HashMap (java.util.HashMap)9 Taxon (org.eol.globi.domain.Taxon)9 StudyNode (org.eol.globi.domain.StudyNode)7 Node (org.neo4j.graphdb.Node)7 File (java.io.File)6 TermImpl (org.eol.globi.domain.TermImpl)6 DatasetImpl (org.eol.globi.service.DatasetImpl)6 InteractType (org.eol.globi.domain.InteractType)5 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)5