Search in sources :

Example 6 with InteractionListener

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

the class DatasetImporterForMetaTableIT method importAll.

public static void importAll(InteractionListener interactionListener, DatasetImporterForMetaTable.TableParserFactory tableFactory, String baseUrl, String resource) throws IOException, StudyImporterException {
    final InputStream inputStream = ResourceUtil.asInputStream(resource, inStream -> inStream);
    final JsonNode config = new ObjectMapper().readTree(inputStream);
    final Dataset dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(config);
    for (JsonNode table : DatasetImporterForMetaTable.collectTables(dataset)) {
        DatasetImporterForMetaTable.importTable(interactionListener, tableFactory, table, new DatasetImpl(null, URI.create(baseUrl), inStream -> inStream), null);
    }
}
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) InputStream(java.io.InputStream) Dataset(org.globalbioticinteractions.dataset.Dataset) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with InteractionListener

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

the class DatasetImporterForPensoftIT method importStudy.

@Test
public void importStudy() throws StudyImporterException, URISyntaxException {
    final DatasetImporterForPensoft importer = new DatasetImporterForPensoft(new ParserFactoryLocal(), null);
    final Dataset dataset = new DatasetImpl("some/name", URI.create("some:uri"), in -> in);
    final ObjectNode objectNode = new ObjectMapper().createObjectNode();
    final URL resource = getClass().getResource("pensoft/annotated-tables-first-two.json");
    objectNode.put("url", resource.toURI().toString());
    objectNode.put("citation", "some dataset citation");
    dataset.setConfig(objectNode);
    List<Map<String, String>> links = new ArrayList<>();
    importer.setDataset(dataset);
    importer.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    });
    importer.importStudy();
    assertThat(links.size(), is(121));
    assertThat(links.get(0), hasEntry("Family Name", "Acanthaceae"));
    assertThat(links.get(0), hasEntry("Family Name_expanded_taxon_name", "Acanthaceae"));
    assertThat(links.get(0), hasEntry("Family Name_expanded_taxon_id", "http://openbiodiv.net/4B689A17-2541-4F5F-A896-6F0C2EEA3FB4"));
    assertThat(links.get(0), hasEntry("referenceUrl", "https://doi.org/10.3897/zookeys.306.5455"));
    assertThat(links.get(0), hasEntry("referenceDoi", "10.3897/zookeys.306.5455"));
    assertThat(links.get(0), hasEntry("referenceCitation", "Dewi Sartiami, Laurence A. Mound. 2013. Identification of the terebrantian thrips (Insecta, Thysanoptera) associated with cultivated plantsĀ inĀ Java, Indonesia. ZooKeys. https://doi.org/10.3897/zookeys.306.5455"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dataset(org.globalbioticinteractions.dataset.Dataset) ArrayList(java.util.ArrayList) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) TreeMap(java.util.TreeMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) TestUtil.getResourceServiceTest(org.eol.globi.data.TestUtil.getResourceServiceTest)

Example 8 with InteractionListener

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

the class DatasetImporterForPensoftIT method parseTableContentWithRowSpan.

@Test
public void parseTableContentWithRowSpan() throws IOException, StudyImporterException {
    final String tableContent = IOUtils.toString(getClass().getResourceAsStream("pensoft/table-with-rowspan.html"), StandardCharsets.UTF_8);
    final ObjectNode tableObj = new ObjectMapper().createObjectNode();
    tableObj.put("table_id", "<http://openbiodiv.net/FB706B4E-BAC2-4432-AD28-48063E7753E4>");
    tableObj.put("caption", "a caption");
    tableObj.put("article_doi", "10.12/34");
    tableObj.put("article_id", "<http://openbiodiv.net/D37E8D1A-221B-FFA6-FFE7-4458FFA0FFC2>");
    tableObj.put("table_content", tableContent);
    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(8));
    assertThat(rowValues.get(0), hasEntry("Family Name", "Apiaceae"));
    assertThat(rowValues.get(0), hasEntry("Thrips species_expanded_taxon_name", "Thrips parvispinus"));
    assertThat(rowValues.get(1), hasEntry("Family Name", "Apiaceae"));
    assertThat(rowValues.get(1), hasEntry("Thrips species_expanded_taxon_name", "Thrips nigropilosus"));
    assertThat(rowValues.get(2), hasEntry("Family Name", "Apiaceae"));
    assertThat(rowValues.get(2), hasEntry("Thrips species_expanded_taxon_name", "Thrips parvispinus"));
    assertThat(rowValues.get(7), hasEntry("Family Name", "Apocynaceae"));
    assertThat(rowValues.get(7), hasEntry("Thrips species_expanded_taxon_name", "Thrips malloti"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Map(java.util.Map) TreeMap(java.util.TreeMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) TestUtil.getResourceServiceTest(org.eol.globi.data.TestUtil.getResourceServiceTest)

Example 9 with InteractionListener

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

the class DatasetImporterForRSSTest method enrichingInteractionListener.

@Test
public void enrichingInteractionListener() throws StudyImporterException {
    DatasetImporterWithListener studyImporter = new DatasetImporterWithListener(new ParserFactory() {

        @Override
        public LabeledCSVParser createParser(URI studyResource, String characterEncoding) throws IOException {
            return null;
        }
    }, new NodeFactoryNull()) {

        @Override
        public void importStudy() throws StudyImporterException {
        // 
        }
    };
    final List<Map<String, String>> receivedLinks = new ArrayList<>();
    studyImporter.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            receivedLinks.add(interaction);
        }
    });
    TreeMap<Pair<String, String>, Map<String, String>> interactionsWithUnresolvedOccurrenceIds = new TreeMap<Pair<String, String>, Map<String, String>>() {

        {
            put(Pair.of(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234"), new TreeMap<String, String>() {

                {
                    put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234");
                    put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, "lifeStageName");
                    put(DatasetImporterForTSV.TARGET_LIFE_STAGE_ID, "lifeStageId");
                    put(DatasetImporterForTSV.TARGET_BODY_PART_NAME, "bodyPartName");
                    put(DatasetImporterForTSV.TARGET_BODY_PART_ID, "bodyPartId");
                    put(TaxonUtil.TARGET_TAXON_NAME, "taxonName");
                    put(TaxonUtil.TARGET_TAXON_ID, "taxonId");
                }
            });
        }
    };
    InteractionListenerResolving listener = new InteractionListenerResolving(interactionsWithUnresolvedOccurrenceIds, studyImporter.getInteractionListener());
    listener.on(new TreeMap<String, String>() {

        {
            put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234");
        }
    });
    assertThat(receivedLinks.size(), is(1));
    Map<String, String> received = receivedLinks.get(0);
    assertThat(received.get(TaxonUtil.TARGET_TAXON_NAME), is("taxonName"));
    assertThat(received.get(TaxonUtil.TARGET_TAXON_ID), is("taxonId"));
    assertThat(received.get(DatasetImporterForTSV.TARGET_BODY_PART_NAME), is("bodyPartName"));
    assertThat(received.get(DatasetImporterForTSV.TARGET_BODY_PART_ID), is("bodyPartId"));
    assertThat(received.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME), is("lifeStageName"));
    assertThat(received.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_ID), is("lifeStageId"));
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) TreeMap(java.util.TreeMap) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) InteractionListenerResolving(org.eol.globi.util.InteractionListenerResolving) Map(java.util.Map) TreeMap(java.util.TreeMap) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 10 with InteractionListener

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

the class DatasetImporterForZOVERTest method parseVirusHostRecord.

@Test
public void parseVirusHostRecord() throws IOException, StudyImporterException {
    String hostLabel = "tick";
    long virusId = 35237L;
    String virusData = DatasetImporterForZOVER.getVirusData(hostLabel, virusId, new ResourceService() {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            return getClass().getResourceAsStream("zover/tick_viruses_35237.json");
        }
    }, "http://www.mgc.ac.cn");
    List<Map<String, String>> interactions = new ArrayList<>();
    InteractionListener listener = new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            interactions.add(interaction);
        }
    };
    JsonNode jsonNode = new ObjectMapper().readTree(virusData);
    DatasetImporterForZOVER.parseData(hostLabel, listener, jsonNode, virusId);
    assertThat(interactions.size(), is(281));
    Map<String, String> first = interactions.get(0);
    assertThat(first.get(SOURCE_TAXON_NAME), is("African swine fever virus"));
    assertThat(first.get(SOURCE_TAXON_ID), is("NCBI:10497"));
    assertThat(first.get(SOURCE_TAXON_PATH), is("Asfarviridae | African swine fever virus"));
    assertThat(first.get(INTERACTION_TYPE_NAME), is("pathogenOf"));
    assertThat(first.get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002556"));
    assertThat(first.get(TARGET_TAXON_NAME), is("Ornithodoros porcinus"));
    assertThat(first.get(TARGET_TAXON_ID), is("NCBI:34594"));
    assertThat(first.get(TARGET_TAXON_PATH), is("Ornithodoros | Ornithodoros porcinus"));
    assertThat(first.get(LOCALITY_NAME), is("South Africa"));
    assertThat(first.get(REFERENCE_URL), is("https://www.ncbi.nlm.nih.gov/nuccore/GQ867183"));
    assertThat(first.get(REFERENCE_ID), is("urn:lsid:cn.ac.mgc:tick:35237"));
}
Also used : InputStream(java.io.InputStream) ResourceService(org.eol.globi.service.ResourceService) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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