Search in sources :

Example 1 with InteractTypeMapper

use of org.eol.globi.util.InteractTypeMapper in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withTaxonHierarchy.

@Test
public void withTaxonHierarchy() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return null;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, "eats");
            put(TaxonUtil.TARGET_TAXON_GENUS, "Donald");
            put(TaxonUtil.TARGET_TAXON_SPECIFIC_EPITHET, "duck");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(TaxonUtil.TARGET_TAXON_NAME), is("Donald duck"));
    assertThat(links.get(0).get(TaxonUtil.TARGET_TAXON_PATH_NAMES), is("genus | species"));
    assertThat(links.get(0).get(TaxonUtil.TARGET_TAXON_PATH), is("Donald | Donald duck"));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with InteractTypeMapper

use of org.eol.globi.util.InteractTypeMapper 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)

Example 3 with InteractTypeMapper

use of org.eol.globi.util.InteractTypeMapper in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withVerbatimInteractionType.

@Test
public void withVerbatimInteractionType() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return InteractType.ATE;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, "Donald");
            put(INTERACTION_TYPE_ID, "duck");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is("duck"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is("Donald"));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("eats"));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with InteractTypeMapper

use of org.eol.globi.util.InteractTypeMapper in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withBlankInteractionType.

@Test
public void withBlankInteractionType() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return InteractType.ATE;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, "");
            put(INTERACTION_TYPE_ID, "");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("eats"));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is(""));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is(""));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with InteractTypeMapper

use of org.eol.globi.util.InteractTypeMapper in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withNullInteractionType.

@Test
public void withNullInteractionType() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return InteractType.ATE;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, null);
            put(INTERACTION_TYPE_ID, null);
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), is(nullValue()));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is(nullValue()));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is(nullValue()));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is(nullValue()));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

InteractTypeMapper (org.eol.globi.util.InteractTypeMapper)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 InteractType (org.eol.globi.domain.InteractType)5 HashMap (java.util.HashMap)4 NullImportLogger (org.eol.globi.tool.NullImportLogger)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 TreeMap (java.util.TreeMap)1 TestUtil.getResourceServiceTest (org.eol.globi.data.TestUtil.getResourceServiceTest)1 InteractionListener (org.eol.globi.process.InteractionListener)1 InteractTypeMapperFactoryImpl (org.eol.globi.util.InteractTypeMapperFactoryImpl)1