use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForBrose method importStudy.
@Override
public void importStudy() throws StudyImporterException {
LabeledCSVParser dataParser;
try {
dataParser = parserFactory.createParser(RESOURCE_PATH, CharsetConstant.UTF8);
} catch (IOException e) {
throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
}
dataParser.changeDelimiter('\t');
Map<String, String> refMap = ReferenceUtil.buildRefMap(parserFactory, REFERENCE_PATH);
try {
while (dataParser.getLine() != null) {
if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
importLine(dataParser, refMap);
}
}
} catch (IOException e) {
throw new StudyImporterException("problem importing study at line [" + dataParser.lastLineNumber() + "]", e);
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForBaremore method importStudy.
@Override
public void importStudy() throws StudyImporterException {
Study study;
try {
LabeledCSVParser parser = parserFactory.createParser(DATA_SOURCE, CharsetConstant.UTF8);
String[] line;
study = nodeFactory.getOrCreateStudy(new StudyImpl("Baremore 2010", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, "doi:10.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 = nodeFactory.getOrCreateLocation(new LocationImpl(29.219302, -87.06665, null, null));
Map<Integer, Specimen> specimenMap = new HashMap<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 = nodeFactory.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 = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesDescription, null));
preySpecimen.caughtIn(collectionLocation);
predatorSpecimen.ate(preySpecimen);
nodeFactory.setUnixEpochProperty(preySpecimen, nodeFactory.getUnixEpochProperty(predatorSpecimen));
}
}
}
} catch (IOException e) {
throw new StudyImporterException("failed to parse labels", e);
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForBlewett method parsePredatorPreyInteraction.
private void parsePredatorPreyInteraction(Study study, Map<String, Location> locationMap, Map<String, Date> collectionTimeMap) throws IOException, NodeFactoryException, TermLookupServiceException {
LabeledCSVParser parser = parserFactory.createParser("blewett/SnookDietData2000_02_Charlotte_Harbor_FL_Blewett_numeric_abundance.csv", CharsetConstant.UTF8);
String[] header = parser.getLabels();
String[] line;
while ((line = parser.getLine()) != null) {
if (line.length < 2) {
break;
}
Specimen predatorSpecimen = addPredator(study, parser, line);
List<Specimen> specimen = addPreyForPredator(header, line, study);
for (Specimen prey : specimen) {
predatorSpecimen.ate(prey);
}
String collectionCode = parser.getValueByLabel(COLLECTION_NO);
if (collectionCode != null) {
specimen.add(predatorSpecimen);
setLocationAndDate(locationMap, collectionTimeMap, specimen, collectionCode);
}
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForBlewett method buildLocationTimeMaps.
private void buildLocationTimeMaps(Map<String, Location> collectionLocationMap, Map<String, Date> collectionTimeMap, Study study) throws IOException, StudyImporterException {
LabeledCSVParser locationParser = parserFactory.createParser("blewett/SnookDietData2000_02_Charlotte_Harbor_FL_Blewett_date_and_abiotic.csv", CharsetConstant.UTF8);
String[] line;
while ((line = locationParser.getLine()) != null) {
if (line.length < 3) {
getLogger().warn(study, "line:" + locationParser.getLastLineNumber() + " [" + StringUtils.join(line, ",") + "] has missing location information");
}
String collectionCode = locationParser.getValueByLabel(COLLECTION_NO);
if (StringUtils.isBlank(collectionCode)) {
getLogger().warn(study, "blank location code for line: [" + locationParser.getLastLineNumber() + "]");
}
String latitude = locationParser.getValueByLabel("Latitude");
if (StringUtils.isBlank(latitude)) {
getLogger().warn(study, "blank value for lattitude for line: [" + locationParser.getLastLineNumber() + "]");
}
String longitude = locationParser.getValueByLabel("Longitude");
if (StringUtils.isBlank(longitude)) {
getLogger().warn(study, "blank value for longitude for line: [" + locationParser.getLastLineNumber() + "]");
}
Location location;
try {
location = nodeFactory.getOrCreateLocation(new LocationImpl(Double.parseDouble(latitude), Double.parseDouble(longitude), 0.0, null));
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create location", e);
}
collectionLocationMap.put(collectionCode, location);
String timeString = locationParser.getValueByLabel("Time");
if (StringUtils.isBlank(timeString)) {
getLogger().warn(study, "blank value for time for line: [" + locationParser.getLastLineNumber() + "]");
}
String dateString = locationParser.getValueByLabel("Date");
if (StringUtils.isBlank(dateString)) {
getLogger().warn(study, "blank value for date for line: [" + locationParser.getLastLineNumber() + "]");
}
String dateTimeString = dateString + " " + timeString;
try {
Date dateTime = parseDateString(dateTimeString);
collectionTimeMap.put(collectionCode, dateTime);
} catch (ParseException e) {
throw new StudyImporterException("failed to parse date time [" + dateTimeString + "] for collection [" + collectionCode + "] on line [" + locationParser.getLastLineNumber() + "]");
}
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForBarnes method importStudy.
@Override
public void importStudy() throws StudyImporterException {
LabeledCSVParser dataParser;
try {
dataParser = parserFactory.createParser(RESOURCE_PATH, CharsetConstant.UTF8);
} catch (IOException e) {
throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
}
dataParser.changeDelimiter('\t');
Map<String, String> refMap = ReferenceUtil.buildRefMap(parserFactory, REFERENCE_PATH);
try {
while (dataParser.getLine() != null) {
if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
importLine(dataParser, refMap);
}
}
} catch (IOException e) {
throw new StudyImporterException("problem importing study at line [" + dataParser.lastLineNumber() + "]", e);
}
}
Aggregations