Search in sources :

Example 16 with Study

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()));
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Test(org.junit.Test)

Example 17 with Study

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));
}
Also used : Study(org.eol.globi.domain.Study) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 18 with Study

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"));
}
Also used : Study(org.eol.globi.domain.Study) StringWriter(java.io.StringWriter) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 19 with Study

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"));
}
Also used : Study(org.eol.globi.domain.Study) StringWriter(java.io.StringWriter) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Map(java.util.Map) Test(org.junit.Test)

Example 20 with Study

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;
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) TermImpl(org.eol.globi.domain.TermImpl) Location(org.eol.globi.domain.Location)

Aggregations

Study (org.eol.globi.domain.Study)141 Test (org.junit.Test)84 StudyImpl (org.eol.globi.domain.StudyImpl)61 Specimen (org.eol.globi.domain.Specimen)38 Relationship (org.neo4j.graphdb.Relationship)33 TaxonImpl (org.eol.globi.domain.TaxonImpl)32 IOException (java.io.IOException)30 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)24 Location (org.eol.globi.domain.Location)24 StringWriter (java.io.StringWriter)21 LocationImpl (org.eol.globi.domain.LocationImpl)20 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 Taxon (org.eol.globi.domain.Taxon)16 SpecimenNode (org.eol.globi.domain.SpecimenNode)14 Date (java.util.Date)13 DatasetImpl (org.eol.globi.service.DatasetImpl)13 Node (org.neo4j.graphdb.Node)12 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)10 InteractType (org.eol.globi.domain.InteractType)9