use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.
the class StudyImporterForJSONLD method importStudy.
@Override
public void importStudy() throws StudyImporterException {
Model model;
try {
model = buildModel();
} catch (IOException e) {
throw new StudyImporterException("failed to import [" + getResourceURI() + "]", e);
}
Query query;
try {
query = QueryFactory.create(IOUtils.toString(new DatasetLocal().getResource("find-jsonld-interactions.rq"), CharsetConstant.UTF8));
} catch (IOException e) {
throw new StudyImporterException("failed to find sparql query", e);
}
QueryExecution exec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = exec.execSelect();
while (results.hasNext()) {
QuerySolution solution = results.nextSolution();
String subj = solution.get("subj").asResource().getURI();
String creationDate = solution.get("creationDate").asLiteral().getString();
String authorURI = solution.get("author").toString();
String author;
try {
author = nodeFactory.getAuthorResolver().findFullName(authorURI);
} catch (IOException e) {
throw new StudyImporterException("failed to resolve author URI [" + authorURI + "]");
}
final String source1 = author + ". " + new DateTime(parseDate(creationDate)).getYear() + ". " + CitationUtil.createLastAccessedString(getResourceURI().toString());
Study study = nodeFactory.getOrCreateStudy(new StudyImpl(getResourceURI() + subj, source1, null, subj));
study.setExternalId(subj);
Specimen source = createSpecimen(solution, study, "subjTaxon");
Specimen target = createSpecimen(solution, study, "targetTaxon");
String interactType = solution.get("p").asResource().getLocalName();
InteractType interactType1 = InteractType.typeOf(StringUtils.replace(interactType, "RO_", "RO:"));
if (interactType1 == null) {
throw new StudyImporterException("failed to map interaction type [" + interactType + "]");
}
String collTime = solution.get("collTime").asLiteral().getString();
Date date = parseDate(collTime);
nodeFactory.setUnixEpochProperty(source, date);
nodeFactory.setUnixEpochProperty(target, date);
Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(solution.get("collLat").asLiteral().getDouble(), solution.get("collLng").asLiteral().getDouble(), null, null));
target.caughtIn(loc);
source.caughtIn(loc);
source.interactsWith(target, interactType1);
}
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to import jsonld data in [" + getResourceURI() + "]", e);
} finally {
exec.close();
}
}
use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.
the class StudyImporterForRaymondIT method importStudy.
@Test
public void importStudy() throws StudyImporterException {
StudyImporterForRaymond importer = new StudyImporterForRaymond(new ParserFactoryLocal(), nodeFactory);
importer.setGeoNamesService(new GeoNamesService() {
@Override
public boolean hasTermForLocale(String locality) {
return true;
}
@Override
public LatLng findLatLng(String locality) throws IOException {
return new LatLng(0, 0);
}
});
importer.setDataset(new DatasetLocal());
importStudy(importer);
importer.setGeoNamesService(new GeoNamesServiceImpl());
Collection<String> unmappedLocations = new HashSet<String>();
for (String location : importer.getLocations()) {
if (!importer.getGeoNamesService().hasTermForLocale(location)) {
unmappedLocations.add(location);
}
}
assertThat(unmappedLocations, containsInAnyOrder("Not described", "South African waters", "Ocean location", "subantarctic waters", "oceanic habitat in Southern Ocean. 68� 07\u0019 S & 70�13\u0019 S", "Subantarctic Pacific Ocean"));
}
use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.
the class ParserFactoryForDatasetTest method parserWithDatasetContextLocalResource.
@Test
public void parserWithDatasetContextLocalResource() throws IOException {
ParserFactoryForDataset parserFactory = new ParserFactoryForDataset(new DatasetLocal());
LabeledCSVParser parser = parserFactory.createParser("classpath:/org/eol/globi/data/someResource.csv", "UTF-8");
assertThat(parser.getLine(), is(new String[] { "valueA", "valueB" }));
}
use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.
the class StudyImporterForCoetzerTest method importSome.
@Test
public void importSome() throws StudyImporterException, IOException {
StudyImporterForCoetzer importer = new StudyImporterForCoetzer(null, nodeFactory);
DatasetImpl dataset = new DatasetLocal();
JsonNode config = new ObjectMapper().readTree("{\"citation\": \"source citation\", \"resources\": {\"archive\": \"coetzer/CatalogOfAfrotropicalBees.zip\"}}");
dataset.setConfig(config);
importer.setDataset(dataset);
importStudy(importer);
List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
for (Study allStudy : allStudies) {
assertThat(allStudy.getSource(), startsWith("source citation"));
assertThat(allStudy.getSource(), containsString("Accessed at"));
}
assertThat(taxonIndex.findTaxonByName("Agrostis tremula"), is(notNullValue()));
assertThat(taxonIndex.findTaxonByName("Coelioxys erythrura"), is(notNullValue()));
assertThat(taxonIndex.findTaxonByName("Patellapis namaquensis"), is(notNullValue()));
}
use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.
the class StudyImporterForSeltmannTest method importSome.
@Test
public void importSome() throws StudyImporterException, IOException {
StudyImporterForSeltmann importer = new StudyImporterForSeltmann(null, nodeFactory);
Dataset dataset = new DatasetLocal();
JsonNode config = new ObjectMapper().readTree("{\"citation\": \"some citation\", \"resources\": {\"archive\": \"seltmann/testArchive.zip\"}}");
dataset.setConfig(config);
importer.setDataset(dataset);
importStudy(importer);
List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
for (Study allStudy : allStudies) {
assertThat(allStudy.getSource(), startsWith("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
for (Relationship specimen : specimens) {
SpecimenNode spec = new SpecimenNode(specimen.getEndNode());
final String recordId = (String) spec.getUnderlyingNode().getProperty("idigbio:recordID");
assertThat(recordId, is(notNullValue()));
assertThat(spec.getExternalId(), is(recordId));
Term basisOfRecord = spec.getBasisOfRecord();
assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
}
}
assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
Aggregations