Search in sources :

Example 31 with InteractionListener

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

the class DatasetImporterForMetaTableIT method importNHMStatic.

@Test
public void importNHMStatic() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    final InteractionListener interactionListener = links::add;
    final DatasetImporterForMetaTable.TableParserFactory tableFactory = (config, dataset) -> {
        String firstFewLines = "\"InteractionID\",\"InteractionURL\",\"Species1UUID\",\"Species1Name\",\"Species1LifeCycleStage\",\"Species1OrganismPart\",\"Species1Status\",\"InteractionType\",\"InteractionOntologyURL\",\"Species2UUID\",\"Species2Name\",\"Species2LifeCycleStage\",\"Species2OrganismPart\",\"Species2Status\",\"LocationUUID\",\"LocationName\",\"LocationCountryName\",\"ISO2\",\"Importance\",\"InteractionRecordType\",\"Reference\",\"ReferenceDOI\",\"Reference Page\",\"Notes\"\n" + "\"4bee827f-c9f5-4c0e-9db3-e40a6e4d8008\",\"http://phthiraptera.info/node/94209\",\"c8faa033-237b-40b9-9b76-d9e7fcff9238\",\"Menacanthus alaudae\",\"\",\"\",\"\",\"ectoparasite of\",\"http://purl.obolibrary.org/obo/RO_0002632\",\"e275d77c-e993-4de0-981f-b3f39fd4da9b\",\"Acanthis flavirostris\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"310\",\"[REF: Palma, Price & Hellenthal, 1998:310]\"\n" + "\"80e66e7c-75db-467f-9a89-a11f94d58eb3\",\"http://phthiraptera.info/node/94210\",\"fe5b2e50-b414-41d9-840d-189e732b2ea5\",\"Ricinus fringillae flammeae\",\"\",\"\",\"\",\"ectoparasite of\",\"http://purl.obolibrary.org/obo/RO_0002632\",\"f26a1199-c0bb-4d7c-a511-2fe6284c5378\",\"Acanthis flammea flammea\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"Self citation to checklist added. Requires page number.\"\n" + "\"001ee8aa-dbab-43b8-9137-a61565ccf41b\",\"http://phthiraptera.info/node/94211\",\"ee17d179-9f60-4198-ac49-dc9dab3ae529\",\"Brueelia sibirica\",\"\",\"\",\"\",\"ectoparasite of\",\"http://purl.obolibrary.org/obo/RO_0002632\",\"f26a1199-c0bb-4d7c-a511-2fe6284c5378\",\"Acanthis flammea flammea\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"Self citation to checklist added. Requires page number.\"\n" + "\"d0929673-2f4c-49ec-877f-116e74ea360e\",\"http://phthiraptera.info/node/94212\",\"46084bc3-cfbf-4e01-96f8-5ecb50bc5ff9\",\"Ricinus fringillae\",\"\",\"\",\"\",\"ectoparasite of\",\"http://purl.obolibrary.org/obo/RO_0002632\",\"2027cf09-f15d-4c2b-be28-9cb00fabf308\",\"Acanthis flammea\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"204\",\"[REF: Rheinwald, 1968:204]\"\n";
        return CSVTSVUtil.createLabeledCSVParser(CSVTSVUtil.createExcelCSVParse(IOUtils.toInputStream(firstFewLines, StandardCharsets.UTF_8)));
    };
    final String baseUrl = "https://raw.githubusercontent.com/globalbioticinteractions/natural-history-museum-london-interactions-bank/main";
    final String resource = baseUrl + "/globi.json";
    importAll(interactionListener, tableFactory, baseUrl, resource);
    assertThat(links.size(), is(4));
    for (Map<String, String> firstLine : links) {
        assertNotNull(firstLine.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME));
        assertNotNull(firstLine.get(TaxonUtil.TARGET_TAXON_ID));
        assertNotNull(firstLine.get(TaxonUtil.TARGET_TAXON_NAME));
        assertNotNull(firstLine.get(TaxonUtil.SOURCE_TAXON_ID));
        assertNotNull(firstLine.get(TaxonUtil.SOURCE_TAXON_NAME));
    }
}
Also used : TaxonUtil(org.eol.globi.service.TaxonUtil) CSVTSVUtil(org.eol.globi.util.CSVTSVUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) ResourceUtil(org.eol.globi.util.ResourceUtil) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) IsNot.not(org.hamcrest.core.IsNot.not) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Dataset(org.globalbioticinteractions.dataset.Dataset) Matchers.containsString(org.hamcrest.Matchers.containsString) InputStream(java.io.InputStream) 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 32 with InteractionListener

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

the class DatasetImporterForMetaTableIT method importGandhi.

@Test
public void importGandhi() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    final InteractionListener interactionListener = links::add;
    final String baseUrl = "https://raw.githubusercontent.com/globalbioticinteractions/gandhi2009/main";
    final String resource = baseUrl + "/globi.json";
    importAll(interactionListener, new DatasetImporterForMetaTable.TableParserFactoryImpl(), baseUrl, resource);
    assertThat(links.size() > 0, is(true));
    final Map<String, String> firstLine = links.get(0);
    assertThat(firstLine.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), startsWith("http://purl.obolibrary.org/obo/RO_"));
    assertNotNull(firstLine.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME));
    assertThat(firstLine.get(DatasetImporterForTSV.REFERENCE_CITATION), is(not(nullValue())));
    assertThat(firstLine.get(DatasetImporterForTSV.REFERENCE_DOI), is(not(nullValue())));
    assertThat(firstLine.get(TaxonUtil.TARGET_TAXON_NAME), is(not(nullValue())));
    assertThat(firstLine.get(TaxonUtil.SOURCE_TAXON_NAME), is(not(nullValue())));
}
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 33 with InteractionListener

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

the class DatasetImporterForPensoftIT method parseTableContentZookeys_318_5693.

@Test
public void parseTableContentZookeys_318_5693() throws IOException, StudyImporterException {
    final JsonNode tableObj = getTableObj("pensoft/annotated-table_zookeys_318_5693.json");
    List<Map<String, String>> rowValues = new ArrayList<>();
    InteractionListener listener = new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            rowValues.add(new TreeMap<>(interaction));
        }
    };
    parseRowsAndEnrich(tableObj, listener, getResourceServiceTest());
    assertThat(rowValues.size(), is(3));
    assertThat(rowValues.get(0), hasEntry("Aphidura species Host plant", "Silene fruticosa"));
    assertThat(rowValues.get(0), hasEntry("Aphidura species Host plant_expanded_taxon_id", "http://openbiodiv.net/9A18EF6D-F508-4649-B290-89A0C5216050"));
    assertThat(rowValues.get(0), hasEntry("Aphidura species Host plant_expanded_taxon_name", "Silene fruticosa"));
    assertThat(rowValues.get(0), hasEntry("_expanded_taxon_id", "http://openbiodiv.net/F260B0E2-2B48-435E-A34F-26090046EA31"));
    assertThat(rowValues.get(0), hasEntry("_expanded_taxon_name", "Aphidura picta"));
    assertThat(rowValues.get(1), hasEntry("Aphidura species Host plant", "Silene italica"));
    assertThat(rowValues.get(1), hasEntry("Aphidura species Host plant_expanded_taxon_id", "http://openbiodiv.net/5BE202E0-3DA3-422B-B7DD-00EECE8F99CC"));
    assertThat(rowValues.get(1), hasEntry("Aphidura species Host plant_expanded_taxon_name", "Silene italica"));
    assertThat(rowValues.get(1), hasEntry("_expanded_taxon_id", "http://openbiodiv.net/F260B0E2-2B48-435E-A34F-26090046EA31"));
    assertThat(rowValues.get(1), hasEntry("_expanded_taxon_name", "Aphidura picta"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test) TestUtil.getResourceServiceTest(org.eol.globi.data.TestUtil.getResourceServiceTest)

Example 34 with InteractionListener

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

the class DatasetImporterForPensoftIT method parseTableContent.

@Test
public void parseTableContent() throws IOException, StudyImporterException {
    final JsonNode tableObj = getTableObj();
    List<Map<String, String>> rowValues = new ArrayList<>();
    InteractionListener listener = new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            rowValues.add(new TreeMap<>(interaction));
        }
    };
    parseRowsAndEnrich(tableObj, listener, getResourceServiceTest());
    assertThat(rowValues.size(), is(121));
    assertThat(rowValues.get(0), hasEntry("Family Name", "Acanthaceae"));
    assertThat(rowValues.get(0), hasEntry("Family Name_expanded_taxon_id", "http://openbiodiv.net/4B689A17-2541-4F5F-A896-6F0C2EEA3FB4"));
    assertThat(rowValues.get(0), hasEntry("Family Name_expanded_taxon_name", "Acanthaceae"));
    assertThat(rowValues.get(0), hasEntry("Host Plant", "Ruellia sp."));
    assertThat(rowValues.get(0), hasEntry("Host Plant_expanded_taxon_id", "http://openbiodiv.net/56F59D49-725E-4BF7-8A6D-1B1A7A721231"));
    assertThat(rowValues.get(0), hasEntry("Host Plant_expanded_taxon_name", "Ruellia"));
    assertThat(rowValues.get(0), hasEntry("Thrips species", "Copidothrips octarticulatusThrips parvispinus"));
    assertThat(rowValues.get(0), hasEntry("Thrips species_expanded_taxon_id", "http://openbiodiv.net/6A54156A-BE5C-44D7-A9E3-3902DA4CCFAC"));
    assertThat(rowValues.get(0), hasEntry("Thrips species_expanded_taxon_name", "Copidothrips octarticulatus"));
    assertThat(rowValues.get(1), hasEntry("Family Name", "Acanthaceae"));
    assertThat(rowValues.get(1), hasEntry("Family Name_expanded_taxon_id", "http://openbiodiv.net/4B689A17-2541-4F5F-A896-6F0C2EEA3FB4"));
    assertThat(rowValues.get(1), hasEntry("Family Name_expanded_taxon_name", "Acanthaceae"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test) TestUtil.getResourceServiceTest(org.eol.globi.data.TestUtil.getResourceServiceTest)

Example 35 with InteractionListener

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

the class DatasetImporterForPensoftIT method singleTableHostInColumnHeader.

@Test
public void singleTableHostInColumnHeader() throws IOException, TermLookupServiceException, StudyImporterException {
    final JsonNode tableObj = getTableObj();
    assertNotNull(tableObj);
    tableObj.get("article_doi");
    final JsonNode annotations = tableObj.get("annotations");
    for (JsonNode annotation : annotations) {
        final InteractTypeMapper interactTypeMapper = new InteractTypeMapperFactoryImpl().create();
        if (annotation.has("id")) {
            final InteractType interactType = interactTypeMapper.getInteractType(annotation.get("id").asText());
        }
        if (annotation.has("context")) {
            String verbatimInteraction = annotation.get("context").asText();
        }
        annotation.get("row");
        annotation.get("column");
        annotation.get("possition");
    }
    tableObj.get("caption");
    List<Map<String, String>> rowValues = new ArrayList<>();
    InteractionListener listener = new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            rowValues.add(interaction);
        }
    };
    parseRowsAndEnrich(tableObj, listener, getResourceServiceTest());
}
Also used : InteractType(org.eol.globi.domain.InteractType) InteractionListener(org.eol.globi.process.InteractionListener) InteractTypeMapperFactoryImpl(org.eol.globi.util.InteractTypeMapperFactoryImpl) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test) TestUtil.getResourceServiceTest(org.eol.globi.data.TestUtil.getResourceServiceTest)

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