Search in sources :

Example 61 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class DatasetImporterForBaremore method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    Study study;
    try {
        LabeledCSVParser parser = getParserFactory().createParser(DATA_SOURCE, CharsetConstant.UTF8);
        String[] line;
        study = getNodeFactory().getOrCreateStudy(new StudyImpl("Baremore 2010", new DOI("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 = getNodeFactory().getOrCreateLocation(new LocationImpl(29.219302, -87.06665, null, null));
        Map<Integer, Specimen> specimenMap = new TreeMap<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 = getNodeFactory().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 = getNodeFactory().createSpecimen(study, new TaxonImpl(preySpeciesDescription, null));
                    preySpecimen.caughtIn(collectionLocation);
                    getNodeFactory().setUnixEpochProperty(preySpecimen, getNodeFactory().getUnixEpochProperty(predatorSpecimen));
                    predatorSpecimen.ate(preySpecimen);
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to parse labels", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) DOI(org.globalbioticinteractions.doi.DOI) Location(org.eol.globi.domain.Location)

Example 62 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class ExporterReferencesTest method exportReference.

@Test
public void exportReference() throws IOException, NodeFactoryException, ParseException {
    StudyImpl myStudy1 = new StudyImpl("myStudy", new DOI("1234", "44"), ExternalIdUtil.toCitation("John Doe", "description study 1", "1927"));
    myStudy1.setExternalId("GAME:444");
    StudyNode myStudy = (StudyNode) nodeFactory.getOrCreateStudy(myStudy1);
    StringWriter row = new StringWriter();
    new ExporterReferences().exportStudy(myStudy, ExportUtil.AppenderWriter.of(row), true);
    ExportTestUtil.assertSameAsideFromNodeIds(row.getBuffer().toString().split("\n"), getExpectedData());
    row = new StringWriter();
    new ExporterReferences().exportStudy(myStudy, ExportUtil.AppenderWriter.of(row), false);
    ExportTestUtil.assertSameAsideFromNodeIds(row.getBuffer().toString(), getExpectedRow());
}
Also used : StringWriter(java.io.StringWriter) StudyImpl(org.eol.globi.domain.StudyImpl) DOI(org.globalbioticinteractions.doi.DOI) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 63 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class ExporterReferencesTest method exportReferenceEscapeCharacters.

@Test
public void exportReferenceEscapeCharacters() throws IOException, NodeFactoryException, ParseException {
    StudyNode myStudy = (StudyNode) nodeFactory.createStudy(new StudyImpl("myStudy", new DOI("some", "doi"), "bla \"one\""));
    StringWriter row = new StringWriter();
    new ExporterReferences().exportStudy(myStudy, ExportUtil.AppenderWriter.of(row), false);
    ExportTestUtil.assertSameAsideFromNodeIds(row.getBuffer().toString(), "globi:ref:X\t\tbla \"one\"\t\t\t\t\t\t\t\t\t\t\t\t\thttps://doi.org/10.some/doi\t10.some/doi\t\n");
}
Also used : StringWriter(java.io.StringWriter) StudyImpl(org.eol.globi.domain.StudyImpl) StudyNode(org.eol.globi.domain.StudyNode) DOI(org.globalbioticinteractions.doi.DOI) Test(org.junit.Test)

Example 64 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class DOIResolverCache method init.

public void init(final Reader reader) throws PropertyEnricherException, IOException {
    DB db = initDb("doiCache");
    StopWatch watch = new StopWatch();
    watch.start();
    final CSVParse parser = CSVTSVUtil.createTSVParser(reader);
    if (db.exists("doiCache")) {
        LOG.info("reusing existing doi cache...");
    } else {
        LOG.info("doi cache building...");
        doiCitationMap = db.createTreeMap("doiCache").pumpPresort(300000).pumpIgnoreDuplicates().pumpSource(new Iterator<Fun.Tuple2<String, DOI>>() {

            private String[] line = null;

            final AtomicBoolean nextLineParsed = new AtomicBoolean(false);

            String getCitation(String[] line) {
                return line != null && line.length > 1 ? line[1] : null;
            }

            DOI getDOI(String[] line) {
                String doiString = line[0];
                try {
                    return StringUtils.isBlank(doiString) ? null : DOI.create(doiString);
                } catch (MalformedDOIException e) {
                    LOG.warn("skipping malformed doi [" + doiString + "]", e);
                    return null;
                }
            }

            @Override
            public boolean hasNext() {
                try {
                    while (!nextLineParsed.get()) {
                        line = parser.getLine();
                        if (line == null) {
                            break;
                        }
                        nextLineParsed.set(getDOI(line) != null && StringUtils.isNotBlank(getCitation(line)));
                    }
                    return line != null && nextLineParsed.get();
                } catch (IOException e) {
                    LOG.error("problem reading", e);
                    return false;
                }
            }

            @Override
            public Fun.Tuple2<String, DOI> next() {
                String citationString = StringUtils.defaultString(getCitation(line), "");
                DOI doi = getDOI(line);
                nextLineParsed.set(false);
                return new Fun.Tuple2<>(citationString, doi);
            }
        }).make();
        db.commit();
        watch.stop();
        LOG.info("doi cache built in [" + watch.getTime(TimeUnit.SECONDS) + "] s.");
    }
}
Also used : CSVParse(com.Ostermiller.util.CSVParse) IOException(java.io.IOException) StopWatch(org.apache.commons.lang3.time.StopWatch) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DB(org.mapdb.DB) Fun(org.mapdb.Fun) DOI(org.globalbioticinteractions.doi.DOI)

Example 65 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class DOIResolverCacheTest method initCache2.

@Test
public void initCache2() throws IOException, PropertyEnricherException {
    String bla = "doi\tcitation\n" + "10.some/A\tcitationA\n" + "10.some/B\tcitationB";
    Reader reader = new StringReader(bla);
    doiResolverCache.init(reader);
    Map<String, DOI> doiForReference = doiResolverCache.resolveDoiFor(Collections.singletonList("citationA"));
    assertThat(doiForReference.get("citationA").toString(), is("10.some/A"));
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) DOI(org.globalbioticinteractions.doi.DOI) Test(org.junit.Test)

Aggregations

DOI (org.globalbioticinteractions.doi.DOI)74 Test (org.junit.Test)50 StudyImpl (org.eol.globi.domain.StudyImpl)28 IOException (java.io.IOException)15 Study (org.eol.globi.domain.Study)15 Specimen (org.eol.globi.domain.Specimen)13 StudyNode (org.eol.globi.domain.StudyNode)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 TaxonImpl (org.eol.globi.domain.TaxonImpl)11 URI (java.net.URI)10 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)8 MalformedDOIException (org.globalbioticinteractions.doi.MalformedDOIException)8 Location (org.eol.globi.domain.Location)7 LocationImpl (org.eol.globi.domain.LocationImpl)7 ArrayList (java.util.ArrayList)6 Dataset (org.globalbioticinteractions.dataset.Dataset)6 Reader (java.io.Reader)5 StringReader (java.io.StringReader)5