Search in sources :

Example 1 with DatasetLocal

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();
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Query(com.hp.hpl.jena.query.Query) StudyImpl(org.eol.globi.domain.StudyImpl) IOException(java.io.IOException) DatasetLocal(org.eol.globi.service.DatasetLocal) QueryExecution(com.hp.hpl.jena.query.QueryExecution) DateTime(org.joda.time.DateTime) Date(java.util.Date) Specimen(org.eol.globi.domain.Specimen) QuerySolution(com.hp.hpl.jena.query.QuerySolution) Model(com.hp.hpl.jena.rdf.model.Model) ResultSet(com.hp.hpl.jena.query.ResultSet) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 2 with DatasetLocal

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"));
}
Also used : GeoNamesServiceImpl(org.eol.globi.service.GeoNamesServiceImpl) GeoNamesService(org.eol.globi.service.GeoNamesService) IOException(java.io.IOException) LatLng(org.eol.globi.geo.LatLng) DatasetLocal(org.eol.globi.service.DatasetLocal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with DatasetLocal

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" }));
}
Also used : LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) DatasetLocal(org.eol.globi.service.DatasetLocal) Test(org.junit.Test)

Example 4 with DatasetLocal

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()));
}
Also used : Study(org.eol.globi.domain.Study) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) DatasetLocal(org.eol.globi.service.DatasetLocal) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with DatasetLocal

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()));
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.eol.globi.service.Dataset) Relationship(org.neo4j.graphdb.Relationship) JsonNode(org.codehaus.jackson.JsonNode) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

DatasetLocal (org.eol.globi.service.DatasetLocal)16 Test (org.junit.Test)11 Study (org.eol.globi.domain.Study)7 IOException (java.io.IOException)4 JsonNode (org.codehaus.jackson.JsonNode)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Relationship (org.neo4j.graphdb.Relationship)3 Specimen (org.eol.globi.domain.Specimen)2 Taxon (org.eol.globi.domain.Taxon)2 LatLng (org.eol.globi.geo.LatLng)2 GeoNamesService (org.eol.globi.service.GeoNamesService)2 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)2 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)1 Query (com.hp.hpl.jena.query.Query)1 QueryExecution (com.hp.hpl.jena.query.QueryExecution)1 QuerySolution (com.hp.hpl.jena.query.QuerySolution)1 ResultSet (com.hp.hpl.jena.query.ResultSet)1 Model (com.hp.hpl.jena.rdf.model.Model)1