Search in sources :

Example 11 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForZenodoMetadataTest method findAnnotationsStaticZenodo.

@Test
public void findAnnotationsStaticZenodo() throws IOException, StudyImporterException {
    final InputStream searchResultStream = getClass().getResourceAsStream("zenodo/search-results-zenodo.json");
    List<Map<String, String>> links = new ArrayList<>();
    final InteractionListener interactionListener = new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    };
    DatasetImporterForZenodoMetadata.parseSearchResults(searchResultStream, interactionListener);
    assertThat(links.size(), Is.is(97));
    List<String> citations = new ArrayList<>();
    for (Map<String, String> link : links) {
        final String s = link.get(REFERENCE_CITATION);
        assertNotNull(s);
        citations.add(s);
    }
    assertThat(citations.get(0), Is.is("Rachel L. Graham, Ralph S. Baric. (2010). Recombination, Reservoirs, and the Modular Spike: Mechanisms of Coronavirus Cross-Species Transmission. Journal of Virology. https://doi.org/10.1128/JVI.01394-09"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Example 12 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForZenodoMetadataTest method paginate.

@Test
public void paginate() throws IOException, StudyImporterException {
    AtomicInteger counter = new AtomicInteger(0);
    final DatasetImporterForZenodoMetadata studyImporterForZenodoMetadata = new DatasetImporterForZenodoMetadata(null, null);
    studyImporterForZenodoMetadata.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
        }
    });
    final DatasetImpl dataset = new DatasetImpl("name/space", URI.create("some:uri"), in -> in) {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            if (StringUtils.contains(resourceName.getHost(), "zenodo.org")) {
                counter.incrementAndGet();
            }
            InputStream is;
            if (URI.create("https://sandbox.zenodo.org/api/records/?sort=mostrecent&custom=%5Bobo%3ARO_0002453%5D%3A%5B%3A%5D&page=2&size=10").equals(resourceName)) {
                is = DatasetImporterForZenodoMetadataTest.class.getResourceAsStream("zenodo/search-results-page-2.json");
            } else if (URI.create("https://zenodo.org/api/records/?custom=%5Bobo%3ARO_0002453%5D%3A%5B%3A%5D").equals(resourceName)) {
                is = DatasetImporterForZenodoMetadataTest.class.getResourceAsStream("zenodo/search-results-page-1.json");
            } else {
                throw new IOException("kaboom!");
            }
            return is;
        }
    };
    studyImporterForZenodoMetadata.setDataset(dataset);
    studyImporterForZenodoMetadata.importStudy();
    assertThat(counter.get(), Is.is(2));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Example 13 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForPensoftTest method generateTableData.

@Test
public void generateTableData() throws IOException, StudyImporterException {
    List<Map<String, String>> links = new ArrayList<>();
    parseRowsAndEnrich(getTableObj(), new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    }, new ResourceService() {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            String journalQueryPrefix = "http://graph.openbiodiv.net/repositories/OpenBiodiv2020?query=PREFIX%20fabio:%20%3Chttp://purl.org/spar/fabio/%3E%0APREFIX%20prism:%20%3Chttp://prismstandard.org/namespaces/basic/2.0/%3E%0APREFIX%20doco:%20%3Chttp://purl.org/spar/doco/%3E%0APREFIX%20dc:%20%3Chttp://purl.org/dc/elements/1.1/%3E%0ASELECT%20%20%20%20?article%20%20%20%20?title%20%20%20%20?doi%20%20%20%20(group_concat(distinct%20?authorName;%20separator=%22,%20%22)%20as%20?authorsList)%20%20%20%20%20(%20REPLACE(str(?pubDate),%20%22(%5C%5Cd*)-.*%22,%20%22$1%22)%20as%20?pubYear)%20%20%20%20?journalName%20WHERE%20%7B%20%0A%20%20%20%20BIND(";
            String taxonQueryPrefix = "http://graph.openbiodiv.net/repositories/OpenBiodiv2020?query=PREFIX%20fabio:%20%3Chttp://purl.org/spar/fabio/%3E%0APREFIX%20prism:%20%3Chttp://prismstandard.org/namespaces/basic/2.0/%3E%0APREFIX%20doco:%20%3Chttp://purl.org/spar/doco/%3E%0APREFIX%20dc:%20%3Chttp://purl.org/dc/elements/1.1/%3E%0Aselect%20?name%20?rank%20?id%20?kingdom%20?phylum%20?class%20?order%20?family%20?genus%20?specificEpithet%20where%20%7B%20%7B%0A%20%20%20%20BIND";
            if (StringUtils.startsWith(resourceName.toString(), journalQueryPrefix)) {
                return getClass().getResourceAsStream("/org/eol/globi/data/pensoft/pensoft-sparql-result.txt");
            } else if (resourceName.toString().startsWith(taxonQueryPrefix)) {
                return getClass().getResourceAsStream("/org/eol/globi/data/pensoft/pensoft-sparql-result2.txt");
            } else {
                throw new RuntimeException("unexpected");
            }
        }
    });
    assertThat(links.size(), is(121));
    for (Map<String, String> link : links) {
        assertThat(link.get("tableSchema"), is("{\"columns\":[{\"name\":\"Family Name\",\"titles\":\"Family Name\",\"datatype\":\"string\"},{\"name\":\"Host Plant\",\"titles\":\"Host Plant\",\"datatype\":\"string\"},{\"name\":\"Thrips species\",\"titles\":\"Thrips species\",\"datatype\":\"string\"},{\"name\":\"Family Name_expanded_taxon_id\",\"titles\":\"Family Name_expanded_taxon_id\",\"datatype\":\"string\"},{\"name\":\"Family Name_expanded_taxon_name\",\"titles\":\"Family Name_expanded_taxon_name\",\"datatype\":\"string\"},{\"name\":\"Host Plant_expanded_taxon_id\",\"titles\":\"Host Plant_expanded_taxon_id\",\"datatype\":\"string\"},{\"name\":\"Host Plant_expanded_taxon_name\",\"titles\":\"Host Plant_expanded_taxon_name\",\"datatype\":\"string\"},{\"name\":\"Thrips species_expanded_taxon_id\",\"titles\":\"Thrips species_expanded_taxon_id\",\"datatype\":\"string\"},{\"name\":\"Thrips species_expanded_taxon_name\",\"titles\":\"Thrips species_expanded_taxon_name\",\"datatype\":\"string\"}]}"));
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ResourceService(org.eol.globi.service.ResourceService) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) Test(org.junit.Test)

Example 14 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForDwCATest method hasResourceRelationshipsOccurrenceToTaxa.

@Test
public void hasResourceRelationshipsOccurrenceToTaxa() throws IOException, URISyntaxException {
    URI sampleArchive = getClass().getResource("inaturalist-dwca-rr.zip").toURI();
    Archive archive = DwCAUtil.archiveFor(sampleArchive, "target/tmp");
    AtomicInteger numberOfFoundLinks = new AtomicInteger(0);
    importResourceRelationshipExtension(archive, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            numberOfFoundLinks.incrementAndGet();
            if (1 == numberOfFoundLinks.get()) {
                assertThat(interaction.get(TaxonUtil.SOURCE_TAXON_ID), is("http://www.inaturalist.org/taxa/465153"));
                assertThat(interaction.get(SOURCE_TAXON_NAME), is("Gorgonocephalus eucnemis"));
                assertThat(interaction.get(SOURCE_OCCURRENCE_ID), is("http://www.inaturalist.org/observations/2309983"));
                assertThat(interaction.get(INTERACTION_TYPE_NAME), is("Eaten by"));
                assertThat(interaction.get(INTERACTION_TYPE_ID), is("http://www.inaturalist.org/observation_fields/879"));
                assertThat(interaction.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("HumanObservation"));
                assertThat(interaction.get(TaxonUtil.TARGET_TAXON_ID), is("http://www.inaturalist.org/taxa/133061"));
                assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is("Enhydra lutris kenyoni"));
                assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is("https://www.inaturalist.org/users/dpom"));
                assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/ResourceRelationship | http://rs.tdwg.org/dwc/terms/Occurrence | http://rs.tdwg.org/dwc/terms/Taxon"));
            }
        }
    });
    assertThat(numberOfFoundLinks.get(), is(1));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) Archive(org.gbif.dwc.Archive) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) Test(org.junit.Test)

Example 15 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForDwCATest method hasResourceRelationshipsOccurrenceToOccurrence.

@Test
public void hasResourceRelationshipsOccurrenceToOccurrence() throws IOException, URISyntaxException {
    URI sampleArchive = getClass().getResource("fmnh-rr-test.zip").toURI();
    Archive archive = DwCAUtil.archiveFor(sampleArchive, "target/tmp");
    AtomicInteger numberOfFoundLinks = new AtomicInteger(0);
    importResourceRelationshipExtension(archive, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            numberOfFoundLinks.incrementAndGet();
            if (1 == numberOfFoundLinks.get()) {
                assertThat(interaction.get(relatedResourceID.qualifiedName()), is("http://n2t.net/ark:/65665/37d63a454-d948-4b1d-89db-89809887ef41"));
                assertThat(interaction.get(SOURCE_TAXON_NAME), is("Trichobius parasparsus Wenzel, 1976"));
                assertThat(interaction.get(SOURCE_OCCURRENCE_ID), is("8afec7db-7b19-44f7-8ac8-8d98614e71d2"));
                assertThat(interaction.get(INTERACTION_TYPE_NAME), is("Ectoparasite of"));
                assertThat(interaction.get(INTERACTION_TYPE_ID), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("PreservedSpecimen"));
                assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.TARGET_OCCURRENCE_ID), is("http://n2t.net/ark:/65665/37d63a454-d948-4b1d-89db-89809887ef41"));
                assertThat(interaction.get(DatasetImporterForTSV.TARGET_CATALOG_NUMBER), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.TARGET_COLLECTION_CODE), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.TARGET_INSTITUTION_CODE), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is("A. L. Tuttle | M. D. Tuttle"));
            } else if (2 == numberOfFoundLinks.get()) {
                assertThat(interaction.get(SOURCE_TAXON_NAME), is("Rhinolophus fumigatus aethiops"));
                assertThat(interaction.get(SOURCE_OCCURRENCE_ID), is("7048675a-b110-4baf-91a3-2db138316709"));
                assertThat(interaction.get(INTERACTION_TYPE_NAME), is("Host to"));
                assertThat(interaction.get(INTERACTION_TYPE_ID), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("PreservedSpecimen"));
                assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.TARGET_OCCURRENCE_ID), is("10d8d814-2afc-4cf2-9843-a2b719346179"));
                assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is("G. Heinrich"));
            } else if (8 == numberOfFoundLinks.get()) {
                assertThat(interaction.get(SOURCE_OCCURRENCE_ID), is("3efb94e7-5182-4dd3-bec5-aa838ba22b4f"));
                assertThat(interaction.get(SOURCE_TAXON_NAME), is("Thamnophis fulvus"));
                assertThat(interaction.get(INTERACTION_TYPE_NAME), is("Stomach Contents of"));
                assertThat(interaction.get(INTERACTION_TYPE_ID), is(nullValue()));
                assertThat(interaction.get(DatasetImporterForTSV.TARGET_OCCURRENCE_ID), is("5c419063-682a-4b3f-8a27-9ed286717922"));
                assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is("Thamnophis fulvus"));
                assertThat(interaction.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("PreservedSpecimen"));
                assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is("C. M. Barber"));
            }
            assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is(notNullValue()));
            assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/ResourceRelationship | http://rs.tdwg.org/dwc/terms/Occurrence"));
        }
    });
    assertThat(numberOfFoundLinks.get(), is(8));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) Archive(org.gbif.dwc.Archive) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) Test(org.junit.Test)

Aggregations

InteractionListener (org.eol.globi.process.InteractionListener)58 Test (org.junit.Test)51 Map (java.util.Map)46 ArrayList (java.util.ArrayList)36 TreeMap (java.util.TreeMap)26 URI (java.net.URI)24 IOException (java.io.IOException)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 URL (java.net.URL)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 InputStream (java.io.InputStream)13 List (java.util.List)13 TaxonUtil (org.eol.globi.service.TaxonUtil)13 Archive (org.gbif.dwc.Archive)13 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)13 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10