Search in sources :

Example 51 with DatasetImpl

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

the class DatasetImporterForSeltmannIT method importArchive.

private void importArchive(String archiveName) throws StudyImporterException {
    DatasetImporterForSeltmann importer = new DatasetImporterForSeltmann(null, nodeFactory);
    URI archiveURI = URI.create(ARCHIVE_URI_PREFIX + archiveName);
    DatasetImpl dataset = new DatasetImpl("some/namespace", archiveURI, inStream -> inStream);
    createAndSetConfig(archiveURI, dataset);
    importer.setDataset(dataset);
    importStudy(importer);
    List<StudyNode> allStudies = NodeUtil.findAllStudies(getGraphDb());
    for (StudyNode allStudy : allStudies) {
        assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        NodeUtil.handleCollectedRelationships(new NodeTypeDirection(allStudy.getUnderlyingNode()), relationship -> {
            Specimen spec = new SpecimenNode(relationship.getEndNode());
            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 : Specimen(org.eol.globi.domain.Specimen) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode) URI(java.net.URI) StudyNode(org.eol.globi.domain.StudyNode)

Example 52 with DatasetImpl

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

the class DatasetImporterForHechingerIT 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. https://doi.org/10.1890/10-1383.1 .\",\n" + "  \"doi\": \"https://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(inStream -> inStream);
    dataset.setConfig(config);
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    DatasetImporterForHechinger importer = new DatasetImporterForHechinger(parserFactory, nodeFactory);
    importer.setDataset(dataset);
    importer.setLogger(new ImportLogger() {

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

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

        @Override
        public void severe(LogContext ctx, String message) {
            LOG.error(message);
        }
    });
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    assertThat(study, is(notNullValue()));
    assertThat(getSpecimenCount(study), is(27932));
    String query = "CYPHER 2.3 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";
    Result result = getGraphDb().execute(query);
    assertThat(result.resultAsString(), CoreMatchers.containsString("Branta bernicla"));
    assertThat(result.resultAsString(), CoreMatchers.containsString("Athya affinis"));
    assertThat(result.resultAsString(), CoreMatchers.containsString("Anas acuta"));
    assertThat(result.resultAsString(), CoreMatchers.containsString("30.378207 | -115.938835 |"));
    query = "CYPHER 2.3 START taxon = node:taxons('*:*')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:PARASITE_OF]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon" + " RETURN taxon.name";
    result = getGraphDb().execute(query);
    Set<String> actualParasites = new HashSet<String>();
    result.forEachRemaining(row -> 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 = "CYPHER 2.3 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 = getGraphDb().execute(query);
    Set<String> actualPrey = new HashSet<String>();
    result.forEachRemaining(row -> actualPrey.add((String) row.get("resourceExternalId")));
    assertThat(actualPrey.size(), is(0));
}
Also used : LogContext(org.eol.globi.domain.LogContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyNode(org.eol.globi.domain.StudyNode) Result(org.neo4j.graphdb.Result) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with DatasetImpl

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

the class DatasetImporterForMetaTableIT method parseNaturalHistoryMuseum.

@Test
public void parseNaturalHistoryMuseum() throws IOException, StudyImporterException {
    final Class<DatasetImporterForMetaTable> clazz = DatasetImporterForMetaTable.class;
    final String name = "test-meta-globi-nhm.json";
    final URL resource = clazz.getResource(name);
    org.junit.Assert.assertNotNull(resource);
    final JsonNode config = new ObjectMapper().readTree(clazz.getResourceAsStream(name));
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(config);
    final List<JsonNode> tables = DatasetImporterForMetaTable.collectTables(dataset);
    assertThat(tables.size(), is(1));
    JsonNode firstTable = tables.get(0);
    String bibliographicCitation = firstTable.get("dcterms:bibliographicCitation").asText();
    assertThat(bibliographicCitation, containsString("NHM Interactions Bank. https://doi.org/10.5519/0060767"));
    String resourceUrl = firstTable.get("url").asText();
    // see https://github.com/globalbioticinteractions/globalbioticinteractions/issues/266
    // assertThat(resourceUrl, is("http://data.nhm.ac.uk/dataset/82e807f0-6273-4f19-be0a-7f7558442a25/resource/1f64e2cf-d738-4a7c-9e81-a1951eac635f/download/output.csv"));
    assertThat(firstTable.get("headerRowCount").asInt(), is(1));
    assertThat(firstTable.has("tableSchema"), is(true));
    assertThat(firstTable.has("null"), is(true));
    assertThat(firstTable.get("tableSchema").has("columns"), is(true));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Matchers.containsString(org.hamcrest.Matchers.containsString) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 54 with DatasetImpl

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

the class DatasetImporterForRSSTest method datasetFor.

private DatasetImpl datasetFor(String configJson) throws IOException {
    JsonNode config = new ObjectMapper().readTree(configJson);
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(config);
    return dataset;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 55 with DatasetImpl

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

the class DatasetImporterForBatBaseIT method importAll.

@Test
public void importAll() throws StudyImporterException {
    AtomicInteger counter = new AtomicInteger(0);
    DatasetImporterForBatBase importer = new DatasetImporterForBatBase(null, null);
    DatasetImpl dataset = new DatasetImpl("test/batplant", URI.create("classpath:/org/eol/globi/data/batplant/"), is -> is);
    importer.setDataset(dataset);
    importer.setInteractionListener(new InteractionValidator(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            counter.incrementAndGet();
        }
    }, new NullImportLogger() {

        @Override
        public void warn(LogContext ctx, String message) {
            fail("unexpected warning: [" + message + "]");
        }
    }));
    importer.importStudy();
    assertThat(counter.get() > 0, Is.is(true));
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InteractionValidator(org.eol.globi.process.InteractionValidator) LogContext(org.eol.globi.domain.LogContext) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)83 Test (org.junit.Test)73 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)50 URI (java.net.URI)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)31 Dataset (org.globalbioticinteractions.dataset.Dataset)25 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)21 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)21 InteractionListener (org.eol.globi.process.InteractionListener)19 URL (java.net.URL)18 Map (java.util.Map)17 StudyNode (org.eol.globi.domain.StudyNode)17 HashMap (java.util.HashMap)16 Is.is (org.hamcrest.core.Is.is)16 List (java.util.List)15 StudyImpl (org.eol.globi.domain.StudyImpl)15 StringUtils (org.apache.commons.lang3.StringUtils)14 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)14 Is (org.hamcrest.core.Is)14