use of com.univocity.parsers.common.record.Record 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);
}
}
use of com.univocity.parsers.common.record.Record in project eol-globi-data by jhpoelen.
the class StudyImporterForHurlbert method importStudy.
@Override
public void importStudy() throws StudyImporterException {
InputStream resource;
try {
resource = getDataset().getResource(RESOURCE);
} catch (IOException e) {
throw new StudyImporterException("failed to access [" + RESOURCE + "]", e);
}
Set<String> regions = new HashSet<String>();
Set<String> locales = new HashSet<String>();
Set<String> habitats = new HashSet<String>();
TsvParserSettings settings = new TsvParserSettings();
settings.getFormat().setLineSeparator("\n");
settings.setHeaderExtractionEnabled(true);
TsvParser parser = new TsvParser(settings);
parser.beginParsing(resource, CharsetConstant.UTF8);
Record record;
while ((record = parser.parseNextRecord()) != null) {
String columnNameSource = "Source";
String sourceCitation = columnValueOrNull(record, columnNameSource);
if (StringUtils.isBlank(sourceCitation)) {
LOG.warn("failed to extract source from column [" + columnNameSource + "] in [" + RESOURCE + "] on line [" + (parser.getContext().currentLine() + 1) + "]");
} else {
importRecords(regions, locales, habitats, record, sourceCitation);
}
}
}
use of com.univocity.parsers.common.record.Record in project eol-globi-data by jhpoelen.
the class StudyImporterForFishbase3 method handleTsvInputStream.
public static void handleTsvInputStream(RecordListener listener, InputStream is) throws StudyImporterException {
TsvParserSettings settings = new TsvParserSettings();
settings.getFormat().setLineSeparator("\n");
settings.setMaxCharsPerColumn(4096 * 8);
settings.setHeaderExtractionEnabled(true);
TsvParser parser = new TsvParser(settings);
parser.beginParsing(is, CharsetConstant.UTF8);
Record record;
while ((record = parser.parseNextRecord()) != null) {
listener.onRecord(record);
}
}
Aggregations