@Test public void parsePredats() throws StudyImporterException { final List<Map<String, String>> links = new ArrayList<>(); InputStream is = getClass().getResourceAsStream("predats_fishbase_first100.tsv"); DatasetImporterForFishbase3.importPredators(links::add, is, speciesMap, references, countries, "FB"); Map<String, String> firstItem = links.get(0); assertThat(firstItem.get("referenceCitation"), Is.is("Guerrero, R.D. III. 1982. Control of tilapia reproduction. p. 309-316. In R.S.V. Pullin and R.H. Lowe-McConnell (eds.) The biology and culture of tilapias. ICLARM Conf. Proc. 7. 432 p.")); assertThat(firstItem.get("decimalLongitude"), Is.is(nullValue())); assertThat(firstItem.get("decimalLatitude"), Is.is(nullValue())); assertThat(firstItem.get("referenceUrl"), Is.is("http: assertThat(firstItem.get("localityName"), Is.is(nullValue())); assertThat(firstItem.get("localityId"), Is.is(nullValue())); assertThat(firstItem.get("sourceTaxonId"), Is.is("FBC:FB:SPECCODE:457")); assertThat(firstItem.get("sourceTaxonName"), Is.is("Cichla ocellaris")); assertThat(firstItem.get("sourceLifeStageName"), Is.is("juv./adults")); assertThat(firstItem.get("targetTaxonId"), Is.is("FBC:FB:SPECCODE:2")); assertThat(firstItem.get("targetTaxonName"), Is.is("Oreochromis niloticus")); assertThat(firstItem.get("targetLifeStageName"), Is.is("recruits/juv.")); assertThat(firstItem.get("studyTitle"), Is.is("FB_REF:84")); assertThat(firstItem.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME), Is.is("preysOn")); assertThat(firstItem.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), Is.is("http: Map<String, String> secondItem = links.get(1); assertThat(secondItem.get("decimalLongitude"), Is.is("39.6356930625")); assertThat(secondItem.get("decimalLatitude"), Is.is("8.62180446746")); assertThat(secondItem.get("localityName"), Is.is("Ethiopia|Lake Awassa")); assertThat(secondItem.get("localityId"), Is.is("FB_COUNTRY:230|")); }
protected static void importPredators(InteractionListener interactionListener, InputStream is, Map<String, Map<String, String>> speciesMap, Map<String, Map<String, String>> references, Map<String, Map<String, String>> countries, String defaultNamespace) throws StudyImporterException { RecordListener listener1 = record -> { Map<String, String> props = new HashMap<>(); String predatorSpeciesCode = columnValueOrNull(record, "predatcode"); String speciesDB = columnValueOrNull(record, "PredatCodeDB"); String taxonIdPrefix = StringUtils.isBlank(speciesDB) ? defaultNamespace : speciesDB; String sourceTaxonId = idForSpecies(taxonIdPrefix, predatorSpeciesCode); props.put(TaxonUtil.SOURCE_TAXON_ID, sourceTaxonId); if (StringUtils.isNotBlank(predatorSpeciesCode)) { Map<String, String> predatorProps = speciesMap.get(sourceTaxonId); if (predatorProps != null) { props.put(TaxonUtil.SOURCE_TAXON_NAME, predatorProps.get("name")); } } String predatorStage = columnValueOrNull(record, "Predatstage"); props.put(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME, predatorStage); String preySpeciesCode = columnValueOrNull(record, "SpecCode"); String targetTaxonId = null; if (StringUtils.isNotBlank(preySpeciesCode)) { targetTaxonId = idForSpecies(defaultNamespace, preySpeciesCode); Map<String, String> preySpecies = speciesMap.get(targetTaxonId); if (preySpecies != null) { props.put(TaxonUtil.TARGET_TAXON_NAME, preySpecies.get("name")); } } props.put(TaxonUtil.TARGET_TAXON_ID, targetTaxonId); String preyLifestage = columnValueOrNull(record, "PreyStage"); props.put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, preyLifestage); lookupReference(references, defaultNamespace, record, props, "PredatsRefNo"); lookupLocality(countries, defaultNamespace, record, props); InteractType interactType = InteractType.PREYS_UPON; props.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, interactType.getLabel()); props.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, interactType.getIRI()); interactionListener.newLink(props); }; handleTsvInputStream(listener1, is); }
DatasetImporterForFishbase3 extends DatasetImporterWithListener { protected static void importPredators(InteractionListener interactionListener, InputStream is, Map<String, Map<String, String>> speciesMap, Map<String, Map<String, String>> references, Map<String, Map<String, String>> countries, String defaultNamespace) throws StudyImporterException { RecordListener listener1 = record -> { Map<String, String> props = new HashMap<>(); String predatorSpeciesCode = columnValueOrNull(record, "predatcode"); String speciesDB = columnValueOrNull(record, "PredatCodeDB"); String taxonIdPrefix = StringUtils.isBlank(speciesDB) ? defaultNamespace : speciesDB; String sourceTaxonId = idForSpecies(taxonIdPrefix, predatorSpeciesCode); props.put(TaxonUtil.SOURCE_TAXON_ID, sourceTaxonId); if (StringUtils.isNotBlank(predatorSpeciesCode)) { Map<String, String> predatorProps = speciesMap.get(sourceTaxonId); if (predatorProps != null) { props.put(TaxonUtil.SOURCE_TAXON_NAME, predatorProps.get("name")); } } String predatorStage = columnValueOrNull(record, "Predatstage"); props.put(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME, predatorStage); String preySpeciesCode = columnValueOrNull(record, "SpecCode"); String targetTaxonId = null; if (StringUtils.isNotBlank(preySpeciesCode)) { targetTaxonId = idForSpecies(defaultNamespace, preySpeciesCode); Map<String, String> preySpecies = speciesMap.get(targetTaxonId); if (preySpecies != null) { props.put(TaxonUtil.TARGET_TAXON_NAME, preySpecies.get("name")); } } props.put(TaxonUtil.TARGET_TAXON_ID, targetTaxonId); String preyLifestage = columnValueOrNull(record, "PreyStage"); props.put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, preyLifestage); lookupReference(references, defaultNamespace, record, props, "PredatsRefNo"); lookupLocality(countries, defaultNamespace, record, props); InteractType interactType = InteractType.PREYS_UPON; props.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, interactType.getLabel()); props.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, interactType.getIRI()); interactionListener.newLink(props); }; handleTsvInputStream(listener1, is); } }
DatasetImporterForFishbase3 extends DatasetImporterWithListener { protected static void importPredators(InteractionListener interactionListener, InputStream is, Map<String, Map<String, String>> speciesMap, Map<String, Map<String, String>> references, Map<String, Map<String, String>> countries, String defaultNamespace) throws StudyImporterException { RecordListener listener1 = record -> { Map<String, String> props = new HashMap<>(); String predatorSpeciesCode = columnValueOrNull(record, "predatcode"); String speciesDB = columnValueOrNull(record, "PredatCodeDB"); String taxonIdPrefix = StringUtils.isBlank(speciesDB) ? defaultNamespace : speciesDB; String sourceTaxonId = idForSpecies(taxonIdPrefix, predatorSpeciesCode); props.put(TaxonUtil.SOURCE_TAXON_ID, sourceTaxonId); if (StringUtils.isNotBlank(predatorSpeciesCode)) { Map<String, String> predatorProps = speciesMap.get(sourceTaxonId); if (predatorProps != null) { props.put(TaxonUtil.SOURCE_TAXON_NAME, predatorProps.get("name")); } } String predatorStage = columnValueOrNull(record, "Predatstage"); props.put(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME, predatorStage); String preySpeciesCode = columnValueOrNull(record, "SpecCode"); String targetTaxonId = null; if (StringUtils.isNotBlank(preySpeciesCode)) { targetTaxonId = idForSpecies(defaultNamespace, preySpeciesCode); Map<String, String> preySpecies = speciesMap.get(targetTaxonId); if (preySpecies != null) { props.put(TaxonUtil.TARGET_TAXON_NAME, preySpecies.get("name")); } } props.put(TaxonUtil.TARGET_TAXON_ID, targetTaxonId); String preyLifestage = columnValueOrNull(record, "PreyStage"); props.put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, preyLifestage); lookupReference(references, defaultNamespace, record, props, "PredatsRefNo"); lookupLocality(countries, defaultNamespace, record, props); InteractType interactType = InteractType.PREYS_UPON; props.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, interactType.getLabel()); props.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, interactType.getIRI()); interactionListener.newLink(props); }; handleTsvInputStream(listener1, is); } DatasetImporterForFishbase3(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForFishbase3 extends DatasetImporterWithListener { protected static void importPredators(InteractionListener interactionListener, InputStream is, Map<String, Map<String, String>> speciesMap, Map<String, Map<String, String>> references, Map<String, Map<String, String>> countries, String defaultNamespace) throws StudyImporterException { RecordListener listener1 = record -> { Map<String, String> props = new HashMap<>(); String predatorSpeciesCode = columnValueOrNull(record, "predatcode"); String speciesDB = columnValueOrNull(record, "PredatCodeDB"); String taxonIdPrefix = StringUtils.isBlank(speciesDB) ? defaultNamespace : speciesDB; String sourceTaxonId = idForSpecies(taxonIdPrefix, predatorSpeciesCode); props.put(TaxonUtil.SOURCE_TAXON_ID, sourceTaxonId); if (StringUtils.isNotBlank(predatorSpeciesCode)) { Map<String, String> predatorProps = speciesMap.get(sourceTaxonId); if (predatorProps != null) { props.put(TaxonUtil.SOURCE_TAXON_NAME, predatorProps.get("name")); } } String predatorStage = columnValueOrNull(record, "Predatstage"); props.put(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME, predatorStage); String preySpeciesCode = columnValueOrNull(record, "SpecCode"); String targetTaxonId = null; if (StringUtils.isNotBlank(preySpeciesCode)) { targetTaxonId = idForSpecies(defaultNamespace, preySpeciesCode); Map<String, String> preySpecies = speciesMap.get(targetTaxonId); if (preySpecies != null) { props.put(TaxonUtil.TARGET_TAXON_NAME, preySpecies.get("name")); } } props.put(TaxonUtil.TARGET_TAXON_ID, targetTaxonId); String preyLifestage = columnValueOrNull(record, "PreyStage"); props.put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, preyLifestage); lookupReference(references, defaultNamespace, record, props, "PredatsRefNo"); lookupLocality(countries, defaultNamespace, record, props); InteractType interactType = InteractType.PREYS_UPON; props.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, interactType.getLabel()); props.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, interactType.getIRI()); interactionListener.newLink(props); }; handleTsvInputStream(listener1, is); } DatasetImporterForFishbase3(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); static void handleTsvInputStream(RecordListener listener, InputStream is); }
DatasetImporterForFishbase3 extends DatasetImporterWithListener { protected static void importPredators(InteractionListener interactionListener, InputStream is, Map<String, Map<String, String>> speciesMap, Map<String, Map<String, String>> references, Map<String, Map<String, String>> countries, String defaultNamespace) throws StudyImporterException { RecordListener listener1 = record -> { Map<String, String> props = new HashMap<>(); String predatorSpeciesCode = columnValueOrNull(record, "predatcode"); String speciesDB = columnValueOrNull(record, "PredatCodeDB"); String taxonIdPrefix = StringUtils.isBlank(speciesDB) ? defaultNamespace : speciesDB; String sourceTaxonId = idForSpecies(taxonIdPrefix, predatorSpeciesCode); props.put(TaxonUtil.SOURCE_TAXON_ID, sourceTaxonId); if (StringUtils.isNotBlank(predatorSpeciesCode)) { Map<String, String> predatorProps = speciesMap.get(sourceTaxonId); if (predatorProps != null) { props.put(TaxonUtil.SOURCE_TAXON_NAME, predatorProps.get("name")); } } String predatorStage = columnValueOrNull(record, "Predatstage"); props.put(DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME, predatorStage); String preySpeciesCode = columnValueOrNull(record, "SpecCode"); String targetTaxonId = null; if (StringUtils.isNotBlank(preySpeciesCode)) { targetTaxonId = idForSpecies(defaultNamespace, preySpeciesCode); Map<String, String> preySpecies = speciesMap.get(targetTaxonId); if (preySpecies != null) { props.put(TaxonUtil.TARGET_TAXON_NAME, preySpecies.get("name")); } } props.put(TaxonUtil.TARGET_TAXON_ID, targetTaxonId); String preyLifestage = columnValueOrNull(record, "PreyStage"); props.put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, preyLifestage); lookupReference(references, defaultNamespace, record, props, "PredatsRefNo"); lookupLocality(countries, defaultNamespace, record, props); InteractType interactType = InteractType.PREYS_UPON; props.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, interactType.getLabel()); props.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, interactType.getIRI()); interactionListener.newLink(props); }; handleTsvInputStream(listener1, is); } DatasetImporterForFishbase3(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); static void handleTsvInputStream(RecordListener listener, InputStream is); static final String C_CODE_GLOBAL; }