Search in sources :

Example 26 with InteractionListener

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

the class DatasetImporterForSPIRETest method phytoplanktonUnlikelyPredators.

@Test
public void phytoplanktonUnlikelyPredators() throws IOException, StudyImporterException {
    RDFDefaultErrorHandler.silent = true;
    DatasetImporterForSPIRE importer = createImporter();
    final List<String> predators = new ArrayList<String>();
    importer.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) {
            if (!DatasetImporterForSPIRE.isValid(interaction)) {
                predators.add(interaction.get(DatasetImporterForSPIRE.PREDATOR_NAME));
            }
        }
    });
    importStudy(importer);
    assertThat(predators, hasItem("phytoplankton"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with InteractionListener

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

the class DatasetImporterForGrayTest method importLines.

@Test
public void importLines() throws IOException, StudyImporterException {
    DatasetImporterForGray gray = createImporter(nodeFactory);
    final List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
    gray.importLinks(IOUtils.toInputStream(firstFewLines(), StandardCharsets.UTF_8), new InteractionListener() {

        @Override
        public void on(final Map<String, String> interaction) {
            maps.add(interaction);
        }
    }, null);
    resolveNames();
    assertThat(maps.size(), is(4));
    Map<String, String> firstLink = maps.get(0);
    assertThat(firstLink.get(TaxonUtil.SOURCE_TAXON_NAME), is("Ancylus fluviatilis"));
    assertThat(firstLink.get(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME), is(nullValue()));
    assertThat(firstLink.get(TaxonUtil.TARGET_TAXON_NAME), is("FPOM"));
    assertThat(firstLink.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME), is(nullValue()));
    assertThat(firstLink.get(DatasetImporterForTSV.REFERENCE_CITATION), is("Ledger, M.E., Brown, L.E., Edwards, F., Milner, A.M. & Woodward, G. (2012) Drought alters the structure and functioning of complex food webs. Nature Climate Change."));
    assertThat(firstLink.get(DatasetImporterForTSV.REFERENCE_ID), is("10.5281/zenodo.13751/source.id/50"));
    assertStaticInfo(firstLink);
    Map<String, String> secondLink = maps.get(1);
    assertThat(secondLink.get(TaxonUtil.SOURCE_TAXON_NAME), is("Ancylus fluviatilis"));
    assertThat(secondLink.get(TaxonUtil.TARGET_TAXON_NAME), is("CPOM"));
    assertThat(secondLink.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("observed"));
    assertStaticInfo(secondLink);
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 28 with InteractionListener

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

the class DatasetImporterForDBatVirTest method parseInteractionsFull.

@Test
public void parseInteractionsFull() throws IOException, StudyImporterException {
    InputStream first2 = new GZIPInputStream(getClass().getResourceAsStream("/org/eol/globi/data/dbatvir/dbatvir.json.gz"));
    List<Map<String, String>> links = new ArrayList<>();
    InteractionListener interactionListener = links::add;
    DatasetImporterForDBatVir.parseInteractions(first2, interactionListener);
    assertThat(links.size(), Is.is(11164));
    assertThat(links.get(0).get(SOURCE_TAXON_NAME), Is.is("Eptesicus nilssoni"));
    assertThat(links.get(0).get(SOURCE_TAXON_ID), Is.is("NCBI:59451"));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), Is.is("http://purl.obolibrary.org/obo/RO_0002453"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), Is.is("hostOf"));
    assertThat(links.get(0).get(TARGET_TAXON_NAME), Is.is("ZV2011"));
    assertThat(links.get(0).get(TARGET_TAXON_ID), Is.is("NCBI:2706560"));
    assertThat(links.get(0).get(TARGET_TAXON_PATH), Is.is("Phenuiviridae | Zwiesel bat banyangvirus | ZV2011"));
    assertThat(links.get(0).get(TARGET_TAXON_PATH_IDS), Is.is(" | NCBI:2706560 | "));
    assertThat(links.get(0).get(TARGET_TAXON_PATH_NAMES), Is.is("family | species | strain"));
    assertThat(links.get(0).get(DatasetImporterForMetaTable.EVENT_DATE), Is.is("2011"));
    assertThat(links.get(0).get(LOCALITY_NAME), Is.is("Germany"));
    assertThat(links.get(0).get(REFERENCE_ID), Is.is("http://www.ncbi.nlm.nih.gov/pubmed/31992832"));
    assertThat(links.get(0).get(REFERENCE_URL), Is.is("http://www.ncbi.nlm.nih.gov/pubmed/31992832"));
    assertThat(links.get(0).get(REFERENCE_CITATION), Is.is("Kohl C, Brinkmann A, Radonic A, Dabrowski PW, Nitsche A, Muhldorfer K, Wibbelt G, Kurth A, Zwiesel bat banyangvirus, a potentially zoonotic Huaiyangshan banyangvirus (Formerly known as SFTS)-like banyangvirus in Northern bats from Germany. Sci Rep 2020, 10(1):1370."));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InteractionListener(org.eol.globi.process.InteractionListener) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Example 29 with InteractionListener

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

the class DatasetImporterForGlobalWebDbTest method dietMatrices.

@Test
public void dietMatrices() throws StudyImporterException {
    final AtomicInteger count = new AtomicInteger();
    DatasetImporterForGlobalWebDb importer = new DatasetImporterForGlobalWebDb(null, null);
    importer.setDataset(new DatasetLocal(inStream -> inStream));
    importer.importDietMatrices(URI.create("classpath:/org/eol/globi/data/globalwebdb-test.zip"), matrixString -> {
        try {
            DatasetImporterForGlobalWebDb.parseDietMatrix(new InteractionListener() {

                @Override
                public void on(Map<String, String> interaction) throws StudyImporterException {
                    count.incrementAndGet();
                }
            }, matrixString, "a source citation");
        } catch (IOException e) {
            throw new StudyImporterException(e);
        }
    });
    assertThat(count.get(), is(207));
}
Also used : TaxonUtil(org.eol.globi.service.TaxonUtil) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TreeList(org.apache.commons.collections4.list.TreeList) InteractionListener(org.eol.globi.process.InteractionListener) Test(org.junit.Test) IOException(java.io.IOException) DatasetLocal(org.eol.globi.service.DatasetLocal) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) DatasetLocal(org.eol.globi.service.DatasetLocal) Test(org.junit.Test)

Example 30 with InteractionListener

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

the class DatasetImporterForMangalIT method importAll.

@Test
public void importAll() throws StudyImporterException {
    AtomicInteger counter = new AtomicInteger(0);
    DatasetImporterForMangal importer = new DatasetImporterForMangal(null, null);
    importer.setDataset(new DatasetLocal(inStream -> inStream));
    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 : LogContext(org.eol.globi.domain.LogContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) InteractionValidator(org.eol.globi.process.InteractionValidator) InteractionListener(org.eol.globi.process.InteractionListener) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) InteractionListenerImpl(org.eol.globi.process.InteractionListenerImpl) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NullImportLogger(org.eol.globi.tool.NullImportLogger) DatasetLocal(org.eol.globi.service.DatasetLocal) Is(org.hamcrest.core.Is) 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) DatasetLocal(org.eol.globi.service.DatasetLocal) Map(java.util.Map) 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