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);
}
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations