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);
}
}
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());
}
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");
}
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.");
}
}
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"));
}
Aggregations