Search in sources :

Example 16 with DatasetLocal

use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.

the class StudyImporterForLifeWatchGreeceTest method readAssociations.

@Test
public void readAssociations() throws StudyImporterException {
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(studies.size(), is(0));
    ParserFactoryLocal parserFactory = new ParserFactoryLocal();
    StudyImporterForLifeWatchGreece importer = new StudyImporterForLifeWatchGreece(parserFactory, nodeFactory);
    importer.setDataset(new DatasetLocal());
    importStudy(importer);
    studies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(studies.size(), is(146));
    Set<String> taxa = new HashSet<String>();
    int totalPredatorPreyRelationships = 0;
    for (Study study : studies) {
        assertThat(study.getCitation(), is(notNullValue()));
        assertThat(study.getTitle(), containsString("greece"));
        Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
        for (Relationship collectedRel : specimens) {
            addTaxonNameForSpecimenNode(taxa, collectedRel.getEndNode());
            Specimen predatorSpecimen = new SpecimenNode(collectedRel.getEndNode());
            Iterable<Relationship> prey = NodeUtil.getStomachContents(predatorSpecimen);
            for (Relationship ateRel : prey) {
                totalPredatorPreyRelationships++;
                addTaxonNameForSpecimenNode(taxa, ateRel.getEndNode());
            }
        }
    }
    assertThat(taxa.contains("Aves"), is(true));
    assertThat(totalPredatorPreyRelationships, is(793));
}
Also used : Study(org.eol.globi.domain.Study) Matchers.containsString(org.hamcrest.Matchers.containsString) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DatasetLocal (org.eol.globi.service.DatasetLocal)16 Test (org.junit.Test)11 Study (org.eol.globi.domain.Study)7 IOException (java.io.IOException)4 JsonNode (org.codehaus.jackson.JsonNode)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Relationship (org.neo4j.graphdb.Relationship)3 Specimen (org.eol.globi.domain.Specimen)2 Taxon (org.eol.globi.domain.Taxon)2 LatLng (org.eol.globi.geo.LatLng)2 GeoNamesService (org.eol.globi.service.GeoNamesService)2 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)2 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)1 Query (com.hp.hpl.jena.query.Query)1 QueryExecution (com.hp.hpl.jena.query.QueryExecution)1 QuerySolution (com.hp.hpl.jena.query.QuerySolution)1 ResultSet (com.hp.hpl.jena.query.ResultSet)1 Model (com.hp.hpl.jena.rdf.model.Model)1