Search in sources :

Example 36 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForMetaTableIT method importAll.

public static void importAll(InteractionListener interactionListener, StudyImporterForMetaTable.TableParserFactory tableFactory, String baseUrl, String resource) throws IOException, StudyImporterException {
    final InputStream inputStream = ResourceUtil.asInputStream(resource);
    final JsonNode config = new ObjectMapper().readTree(inputStream);
    final Dataset dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
    dataset.setConfig(config);
    for (JsonNode table : StudyImporterForMetaTable.collectTables(dataset)) {
        StudyImporterForMetaTable.importTable(interactionListener, tableFactory, table, new DatasetImpl(null, URI.create(baseUrl)), null);
    }
}
Also used : InputStream(java.io.InputStream) Dataset(org.eol.globi.service.Dataset) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 37 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class TableInteractionListenerProxyTest method interactionListener2Test.

@Test
public void interactionListener2Test() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    JsonNode config = new ObjectMapper().readTree("{ \"dcterms:bibliographicCitation\":\"some citation\", \"url\":\"some resource url\" }");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://someurl"));
    dataset.setConfig(config);
    final TableInteractionListenerProxy listener = new TableInteractionListenerProxy(dataset, new InteractionListener() {

        @Override
        public void newLink(Map<String, String> properties) throws StudyImporterException {
            links.add(properties);
        }
    });
    listener.newLink(new HashMap<String, String>() {

        {
            put(StudyImporterForTSV.REFERENCE_CITATION, "some ref");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(StudyImporterForTSV.STUDY_SOURCE_CITATION), startsWith("some citation. Accessed at <some resource url> on "));
    assertThat(links.get(0).get(StudyImporterForTSV.REFERENCE_CITATION), startsWith("some ref"));
}
Also used : ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 38 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class TableInteractionListenerProxyTest method interactionListenerTest.

@Test
public void interactionListenerTest() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    JsonNode config = new ObjectMapper().readTree("{ \"dcterms:bibliographicCitation\":\"some citation\", \"url\":\"some resource url\" }");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://someurl"));
    dataset.setConfig(config);
    final TableInteractionListenerProxy listener = new TableInteractionListenerProxy(dataset, new InteractionListener() {

        @Override
        public void newLink(Map<String, String> properties) throws StudyImporterException {
            links.add(properties);
        }
    });
    listener.newLink(new HashMap<>());
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(StudyImporterForTSV.STUDY_SOURCE_CITATION), startsWith("some citation. Accessed at <some resource url> on "));
    assertThat(links.get(0).get(StudyImporterForTSV.REFERENCE_CITATION), startsWith("some citation. Accessed at <some resource url> on "));
}
Also used : ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 39 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForHechingerTest method importStudy.

@Test
public void importStudy() throws StudyImporterException, IOException {
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Ryan F. Hechinger, Kevin D. Lafferty, John P. McLaughlin, Brian L. Fredensborg, Todd C. Huspeni, Julio Lorda, Parwant K. Sandhu, Jenny C. Shaw, Mark E. Torchin, Kathleen L. Whitney, and Armand M. Kuris 2011. Food webs including parasites, biomass, body sizes, and life stages for three California/Baja California estuaries. Ecology 92:791–791. http://dx.doi.org/10.1890/10-1383.1 .\",\n" + "  \"doi\": \"http://dx.doi.org/10.1890/10-1383.1\",\n" + "  \"format\": \"hechinger\",\n" + "  \"delimiter\": \"\\t\",\n" + "  \"resources\": {\n" + "    \"nodes\": \"hechinger/Metaweb_Nodes.txt\",\n" + "    \"links\": \"hechinger/Metaweb_Links.txt\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetLocal();
    dataset.setConfig(config);
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    StudyImporterForHechinger importer = new StudyImporterForHechinger(parserFactory, nodeFactory);
    importer.setDataset(dataset);
    importer.setLogger(new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            LOG.warn(message);
        }

        @Override
        public void info(LogContext study, String message) {
            LOG.info(message);
        }

        @Override
        public void severe(LogContext study, String message) {
            LOG.error(message);
        }
    });
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    assertThat(study, is(notNullValue()));
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
    int count = 0;
    for (Relationship specimen : specimens) {
        count++;
    }
    assertThat(count, is(27932));
    ExecutionEngine engine = new ExecutionEngine(getGraphDb());
    String query = "START resourceTaxon = node:taxons(name='Suaeda spp.')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon, specimen-[:COLLECTED_AT]->location" + " RETURN taxon.name, specimen.lifeStage?, type(r), resourceTaxon.name, resourceSpecimen.lifeStage?, location.latitude as lat, location.longitude as lng";
    ExecutionResult result = engine.execute(query);
    assertThat(result.dumpToString(), containsString("Branta bernicla"));
    assertThat(result.dumpToString(), containsString("Athya affinis"));
    assertThat(result.dumpToString(), containsString("Anas acuta"));
    assertThat(result.dumpToString(), containsString("30.378207 | -115.938835 |"));
    query = "START taxon = node:taxons('*:*')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:PARASITE_OF]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon" + " RETURN taxon.name";
    result = engine.execute(query);
    Set<String> actualParasites = new HashSet<String>();
    for (Map<String, Object> row : result) {
        actualParasites.add((String) row.get("taxon.name"));
    }
    assertThat(actualParasites.size() > 0, is(true));
    for (String unlikelyParasite : unlikelyParasites()) {
        assertThat(actualParasites, not(hasItem(unlikelyParasite)));
    }
    // Trypanorhyncha (kind of tapeworms) are typically parasites, not prey
    query = "START resourceTaxon = node:taxons(name='Trypanorhyncha')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r:PREYS_UPON]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon" + " RETURN specimen.externalId + type(r) + resourceSpecimen.externalId as `resourceExternalId`";
    result = engine.execute(query);
    Set<String> actualPrey = new HashSet<String>();
    for (Map<String, Object> row : result) {
        actualPrey.add((String) row.get("resourceExternalId"));
    }
    assertThat(actualPrey.size(), is(0));
}
Also used : Study(org.eol.globi.domain.Study) LogContext(org.eol.globi.domain.LogContext) JsonNode(org.codehaus.jackson.JsonNode) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) DatasetImpl(org.eol.globi.service.DatasetImpl) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DatasetLocal(org.eol.globi.service.DatasetLocal) ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) Relationship(org.neo4j.graphdb.Relationship) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForPlanqueIT method importAll.

@Test
public void importAll() throws StudyImporterException, NodeFactoryException, IOException {
    final List<String> errorMessages = new ArrayList<String>();
    BaseStudyImporter importer = new StudyImporterForPlanque(new ParserFactoryLocal(), nodeFactory);
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Benjamin Planque, Raul Primicerio, Kathrine Michalsen, Michaela Aschan, Grégoire Certain, Padmini Dalpadado, Harald Gjøsæater, Cecilie Hansen, Edda Johannesen, Lis Lindal Jørgensen, Ina Kolsum, Susanne Kortsch, Lise-Marie Leclerc, Lena Omli, Mette Skern-Mauritzen, and Magnus Wiedmann 2014. Who eats whom in the Barents Sea: a food web topology from plankton to whales. Ecology 95:1430–1430. http://dx.doi.org/10.1890/13-1062.1\",\n" + "  \"doi\": \"http://dx.doi.org/10.1890/13-1062.1\",\n" + "  \"format\": \"planque\",\n" + "  \"resources\": {\n" + "    \"links\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/PairwiseList.txt\",\n" + "    \"references\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/References.txt\",\n" + "    \"referencesForLinks\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/PairWise2References.txt\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
    dataset.setConfig(config);
    importer.setDataset(dataset);
    importer.setLogger(new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            errorMessages.add(message);
        }

        @Override
        public void info(LogContext study, String message) {
        }

        @Override
        public void severe(LogContext study, String message) {
        }
    });
    importStudy(importer);
    int interactionCount = 0;
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    for (Study study : studies) {
        Iterable<Relationship> specimenRels = NodeUtil.getSpecimens(study);
        for (Relationship specimenRel : specimenRels) {
            interactionCount++;
        }
    }
    assertThat(interactionCount, is(4900));
    int uniqueReference = 236;
    // note that the +1 is for all links that had no reference associated to it
    assertThat(studies.size(), is(uniqueReference + 1));
    assertThat(taxonIndex.findTaxonByName("Trisopterus esmarkii"), is(notNullValue()));
    assertThat(errorMessages.size(), is(0));
}
Also used : Study(org.eol.globi.domain.Study) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) Relationship(org.neo4j.graphdb.Relationship) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

DatasetImpl (org.eol.globi.service.DatasetImpl)45 Test (org.junit.Test)31 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)24 JsonNode (org.codehaus.jackson.JsonNode)16 Study (org.eol.globi.domain.Study)13 Relationship (org.neo4j.graphdb.Relationship)9 ArrayList (java.util.ArrayList)6 ObjectNode (org.codehaus.jackson.node.ObjectNode)6 StudyImpl (org.eol.globi.domain.StudyImpl)6 Dataset (org.eol.globi.service.Dataset)6 Node (org.neo4j.graphdb.Node)5 InputStream (java.io.InputStream)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)4 NodeFactoryWithDatasetContext (org.eol.globi.data.NodeFactoryWithDatasetContext)3 LogContext (org.eol.globi.domain.LogContext)3 Specimen (org.eol.globi.domain.Specimen)3 Taxon (org.eol.globi.domain.Taxon)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2