use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalistTest method importTestResponseWithTaxonId.
@Test
public void importTestResponseWithTaxonId() throws IOException, StudyImporterException {
importer.parseJSON(getClass().getResourceAsStream("inaturalist/response_with_taxon_ids.json"), new ArrayList<Integer>() {
{
}
}, new HashMap<Integer, InteractType>() {
{
put(47, InteractType.HAS_HOST);
}
});
resolveNames();
assertThat(NodeUtil.findAllStudies(getGraphDb()).size(), is(10));
Study anotherStudy = nodeFactory.findStudy("INAT:2366807");
assertThat(anotherStudy, is(notNullValue()));
assertThat(anotherStudy.getExternalId(), is("https://www.inaturalist.org/observations/2366807"));
assertThat(taxonIndex.findTaxonById("GBIF:2959023"), is(nullValue()));
assertThat(taxonIndex.findTaxonById("GBIF:7246356"), is(nullValue()));
assertThat(taxonIndex.findTaxonById("INAT_TAXON:406089"), is(notNullValue()));
assertThat(taxonIndex.findTaxonById("INAT_TAXON:480390"), is(notNullValue()));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForJRFerrerParisTest method testSomeLine.
@Test
public void testSomeLine() throws StudyImporterException, NodeFactoryException {
String csvContent = "\"\",\"Lepidoptera Family\",\"Lepidoptera Name\",\"Hostplant Family\",\"Hostplant Name\",\"Country\",\"reference\"\n" + "\"27385\",\"Pieridae\",\"Hesperocharis anguitia\",\"Santalales\",\"'Loranthus'\",\"Brazil\",\"Braby & Nishida 2007\"\n" + "\"27386\",\"Pieridae\",\"Mathania carrizoi\",\"Santalales\",\"'Loranthus'\",\"Argentina\",\"Braby & Nishida 2007\"\n" + "\"27387\",\"Pieridae\",\"Mylothris agathina\",\"Santalales\",\"?Loranthus? spp.\",\"Kenya, Tanzania, South Africa\",\"Braby 2005\"\n" + "\"27388\",\"Pieridae\",\"Mylothris chloris\",\"Santalales\",\"?Loranthus? spp.\",\"Kenya\",\"Braby 2005\"";
StudyImporterForJRFerrerParis importer = new StudyImporterForJRFerrerParis(new TestParserFactory(csvContent), nodeFactory);
importStudy(importer);
Study study = getStudySingleton(getGraphDb());
assertNotNull(taxonIndex.findTaxonByName("Hesperocharis anguitia"));
Iterable<Relationship> collectedRels = NodeUtil.getSpecimens(study);
int totalRels = 0;
for (Relationship collectedRel : collectedRels) {
totalRels++;
}
assertThat(totalRels, Is.is(8));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class ExportTaxonCacheTest method exportOnePredatorTwoPrey.
@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
taxonIndex = ExportTestUtil.taxonIndexWithEnricher(null, getGraphDb());
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("title", "source", null, "citation"));
Taxon taxon = new TaxonImpl("Homo sapiens");
taxon.setExternalId("homoSapiensId");
taxon.setPath("one\ttwo three");
taxon.setExternalUrl("http://some/thing");
taxon.setThumbnailUrl("http://thing/some");
Taxon human = taxonIndex.getOrCreateTaxon(taxon);
TaxonImpl taxon1 = new TaxonImpl("Canis lupus", "canisLupusId");
taxon1.setPath("four five six");
taxonIndex.getOrCreateTaxon(taxon1);
NodeUtil.connectTaxa(new TaxonImpl("Alternate Homo sapiens no path", "alt:123"), (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
final TaxonImpl altTaxonWithPath = new TaxonImpl("Alternate Homo sapiens", "alt:123");
altTaxonWithPath.setPath("some path here");
NodeUtil.connectTaxa(altTaxonWithPath, (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
NodeUtil.connectTaxa(new TaxonImpl("Similar Homo sapiens", "alt:456"), (TaxonNode) human, getGraphDb(), RelTypes.SIMILAR_TO);
StringWriter writer = new StringWriter();
new ExportTaxonCache().exportStudy(study, writer, true);
assertThat(writer.toString(), is("id\tname\trank\tcommonNames\tpath\tpathIds\tpathNames\texternalUrl\tthumbnailUrl" + "\nhomoSapiensId\tHomo sapiens\t\t\tone two three\t\t\thttp://some/thing\thttp://thing/some" + "\nalt:123\tAlternate Homo sapiens\t\t\tsome path here\t\t\thttp://some/thing\thttp://thing/some" + "\ncanisLupusId\tCanis lupus\t\t\tfour five six\t\t\t\t"));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class ExportTaxonMapTest method exportOnePredatorTwoPrey.
@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
final PropertyEnricher taxonEnricher = new PropertyEnricher() {
@Override
public Map<String, String> enrich(Map<String, String> properties) {
Taxon taxon = new TaxonImpl();
TaxonUtil.mapToTaxon(properties, taxon);
if ("Homo sapiens".equals(taxon.getName())) {
taxon.setExternalId("homoSapiensId");
taxon.setPath("one two three");
} else if ("Canis lupus".equals(taxon.getName())) {
taxon.setExternalId("canisLupusId");
taxon.setPath("four\tfive six");
}
return TaxonUtil.taxonToMap(taxon);
}
@Override
public void shutdown() {
}
};
taxonIndex = ExportTestUtil.taxonIndexWithEnricher(taxonEnricher, getGraphDb());
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("title", "source", null, "citation"));
Taxon taxon = new TaxonImpl("Homo sapiens");
taxon.setExternalId("homoSapiensId");
taxon.setPath("one two three");
taxon.setExternalUrl("http://some/thing");
taxon.setThumbnailUrl("http://thing/some");
nodeFactory.createSpecimen(study, taxon);
Taxon human = taxonIndex.getOrCreateTaxon(taxon);
TaxonImpl dog = new TaxonImpl("Canis lupus");
dog.setExternalId("canisLupusId");
dog.setPath("four\tfive six");
nodeFactory.createSpecimen(study, dog);
final TaxonImpl altTaxonWithPath = new TaxonImpl("Alternate Homo sapiens", "alt:123");
altTaxonWithPath.setPath("some path here");
NodeUtil.connectTaxa(altTaxonWithPath, (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
NodeUtil.connectTaxa(new TaxonImpl("Alternate Homo sapiens no path", "alt:123"), (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
NodeUtil.connectTaxa(new TaxonImpl("Similar Homo sapiens", "alt:456"), (TaxonNode) human, getGraphDb(), RelTypes.SIMILAR_TO);
resolveNames();
StringWriter writer = new StringWriter();
new ExportTaxonMap().exportStudy(study, writer, true);
assertThat(writer.toString(), is("providedTaxonId\tprovidedTaxonName\tresolvedTaxonId\tresolvedTaxonName" + "\nhomoSapiensId\tHomo sapiens\thomoSapiensId\tHomo sapiens" + "\nhomoSapiensId\tHomo sapiens\talt:123\tAlternate Homo sapiens" + "\ncanisLupusId\tCanis lupus\tcanisLupusId\tCanis lupus"));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class ExportTestUtil method createTestData.
public static Study createTestData(Double length, NodeFactory factory) throws NodeFactoryException, ParseException {
Study myStudy = factory.createStudy(new StudyImpl("myStudy", null, null, null));
Specimen specimen1 = factory.createSpecimen(myStudy, new TaxonImpl("Homo sapiens", "EOL:45634"));
specimen1.setStomachVolumeInMilliLiter(666.0);
specimen1.setLifeStage(new TermImpl("GLOBI:JUVENILE", "JUVENILE"));
specimen1.setPhysiologicalState(new TermImpl("GLOBI:DIGESTATE", "DIGESTATE"));
specimen1.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
factory.setUnixEpochProperty(specimen1, ExportTestUtil.utcTestDate());
final Specimen specimen2 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
specimen2.setVolumeInMilliLiter(124.0);
specimen1.ate(specimen2);
final Specimen specimen3 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
specimen3.setVolumeInMilliLiter(18.0);
specimen1.ate(specimen3);
if (null != length) {
specimen1.setLengthInMm(length);
}
Location location = factory.getOrCreateLocation(new LocationImpl(88.0, -120.0, -60.0, null));
specimen1.caughtIn(location);
return myStudy;
}
Aggregations