Search in sources :

Example 11 with NodeTypeDirection

use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.

the class DatasetImporterForRaymondTest method assertThatAllStudiesHaveAtLeastOneInteraction.

protected void assertThatAllStudiesHaveAtLeastOneInteraction() {
    AtomicBoolean foundAtLeastOne = new AtomicBoolean(false);
    List<StudyNode> studies = NodeUtil.findAllStudies(getGraphDb());
    for (StudyNode study : studies) {
        NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), next -> {
            Specimen specimen = new SpecimenNode(next.getEndNode());
            assertThat(specimen.getSampleLocation().getLongitude(), is(-61.66666667d));
            assertThat(next.getProperty(SpecimenConstant.EVENT_DATE), is(not(nullValue())));
            foundAtLeastOne.set(true);
        });
    }
    assertTrue(foundAtLeastOne.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Specimen(org.eol.globi.domain.Specimen) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) SpecimenNode(org.eol.globi.domain.SpecimenNode) StudyNode(org.eol.globi.domain.StudyNode)

Example 12 with NodeTypeDirection

use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.

the class DatasetImporterForRoopnarineTest method validateSpecimen.

private int validateSpecimen() {
    AtomicInteger totalRels = new AtomicInteger(0);
    RelationshipListener handler = rel -> {
        Node specimen = rel.getEndNode();
        assertNotNull(specimen);
        Relationship collectedAtRelationship = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING);
        assertNotNull("missing location information", collectedAtRelationship);
        Node locationNode = collectedAtRelationship.getEndNode();
        assertNotNull(locationNode);
        assertTrue(locationNode.hasProperty(LocationConstant.LATITUDE));
        assertTrue(locationNode.hasProperty(LocationConstant.LONGITUDE));
        totalRels.incrementAndGet();
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(getStudySingleton(getGraphDb()).getUnderlyingNode()), handler);
    return totalRels.get();
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Direction(org.neo4j.graphdb.Direction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Is(org.hamcrest.core.Is) Relationship(org.neo4j.graphdb.Relationship) Ignore(org.junit.Ignore) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationConstant(org.eol.globi.domain.LocationConstant) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 13 with NodeTypeDirection

use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.

the class DatasetImporterForSeltmannIT method importArchive.

private void importArchive(String archiveName) throws StudyImporterException {
    DatasetImporterForSeltmann importer = new DatasetImporterForSeltmann(null, nodeFactory);
    URI archiveURI = URI.create(ARCHIVE_URI_PREFIX + archiveName);
    DatasetImpl dataset = new DatasetImpl("some/namespace", archiveURI, inStream -> inStream);
    createAndSetConfig(archiveURI, dataset);
    importer.setDataset(dataset);
    importStudy(importer);
    List<StudyNode> allStudies = NodeUtil.findAllStudies(getGraphDb());
    for (StudyNode allStudy : allStudies) {
        assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        NodeUtil.handleCollectedRelationships(new NodeTypeDirection(allStudy.getUnderlyingNode()), relationship -> {
            Specimen spec = new SpecimenNode(relationship.getEndNode());
            Term basisOfRecord = spec.getBasisOfRecord();
            assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
            assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
        });
    }
    assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode) URI(java.net.URI) StudyNode(org.eol.globi.domain.StudyNode)

Example 14 with NodeTypeDirection

use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.

the class DatasetImporterForSimonsTest method createAndPopulateStudy.

@Test
public void createAndPopulateStudy() throws StudyImporterException {
    String csvString = "\"Obs\",\"spcode\", \"sizecl\", \"cruise\", \"stcode\", \"numstom\", \"numfood\", \"pctfull\", \"predator famcode\", \"prey\", \"number\", \"season\", \"depth\", \"transect\", \"alphcode\", \"taxord\", \"station\", \"long\", \"lat\", \"time\", \"sizeclass\", \"predator\"\n";
    csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca agassizi\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString += "2, 11, 2, 1, 1, 20, 15, 592.5, 6, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 20, \"Chandeleur Islands\", \"aabd\", 47.11, \"C1\", 344445.31, 3323087.25, 144, \"26-50\", \"Halieutichthys aculeatus\"\n";
    DatasetImporterForSimons importer = new DatasetImporterForSimons(new TestParserFactory(csvString), nodeFactory);
    importStudy(importer);
    assertNotNull(taxonIndex.findTaxonByName("Rhynchoconger flavus"));
    assertNotNull(taxonIndex.findTaxonByName("Halieutichthys aculeatus"));
    assertNotNull(taxonIndex.findTaxonByName("Ampelisca sp. (abdita complex)"));
    assertNotNull(nodeFactory.findStudy(new StudyImpl("Simons 1997")));
    assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_1, LONG_1, -60.0d, null)));
    assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_2, LONG_2, -20.0d, null)));
    assertNotNull(nodeFactory.findSeason("summer"));
    StudyNode foundStudy = (StudyNode) nodeFactory.findStudy(new StudyImpl("Simons 1997"));
    assertNotNull(foundStudy);
    RelationshipListener handler = rel -> {
        Node specimen = rel.getEndNode();
        Node speciesNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
        String scientificName = (String) speciesNode.getProperty("name");
        if ("Rhynchoconger flavus".equals(scientificName)) {
            String seasonName = "summer";
            String genusName = "Ampelisca sp. (abdita complex)";
            double length = (201.0d + 300.0d) / 2.0d;
            assertSpecimen(specimen, LONG_1, LAT_1, -60.0, seasonName, genusName, length);
            Iterable<Relationship> ateRelationships = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
            List<String> preyNames = new ArrayList<String>();
            for (Relationship ateRel : ateRelationships) {
                Node preyTaxonNode = ateRel.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS)).iterator().next().getEndNode();
                preyNames.add(preyTaxonNode.getProperty(PropertyAndValueDictionary.NAME).toString());
            }
            assertThat(preyNames, hasItem("Ampelisca sp. (abdita complex)"));
            assertThat(preyNames.contains("Ampelisca agassizi"), Is.is(true));
            assertThat(preyNames.size(), Is.is(2));
        } else if ("Halieutichthys aculeatus".equals(scientificName)) {
            String genusName = "Ampelisca sp. (abdita complex)";
            String seasonName = "summer";
            double length = (26.0d + 50.0d) / 2.0d;
            assertSpecimen(specimen, LONG_2, LAT_2, -20.0, seasonName, genusName, length);
        } else if ("Ampelisca sp. (abdita complex)".equals(scientificName)) {
            Node locationNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING).getEndNode();
            assertNotNull(locationNode);
            assertTrue(locationNode.hasProperty(LocationConstant.LONGITUDE));
            assertTrue(locationNode.hasProperty(LocationConstant.ALTITUDE));
            assertTrue(locationNode.hasProperty(LocationConstant.LATITUDE));
        } else if ("Ampelisca agassizi".equals(scientificName)) {
            assertPreySpecimen(specimen, LONG_1, LAT_1, -60.0);
        } else {
            fail("found predator with unexpected scientificName [" + scientificName + "]");
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(foundStudy.getUnderlyingNode()), handler);
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) LocationImpl(org.eol.globi.domain.LocationImpl) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) Is(org.hamcrest.core.Is) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RelationshipListener(org.eol.globi.util.RelationshipListener) Is.is(org.hamcrest.core.Is.is) UTMRef(uk.me.jstott.jcoord.UTMRef) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Iterator(java.util.Iterator) LatLng(uk.me.jstott.jcoord.LatLng) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) Assert(org.junit.Assert) LocationConstant(org.eol.globi.domain.LocationConstant) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) StudyImpl(org.eol.globi.domain.StudyImpl) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 15 with NodeTypeDirection

use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.

the class DatasetImporterForBaremoreTest method validateSpecimen.

private int validateSpecimen(StudyNode study) {
    AtomicInteger totalRels = new AtomicInteger(0);
    RelationshipListener handler = rel -> {
        assertTrue(rel.hasProperty(SpecimenConstant.EVENT_DATE));
        Node specimen = rel.getEndNode();
        assertNotNull(specimen);
        Iterable<Relationship> rels = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
        for (Relationship ignored : rels) {
            assertTrue(specimen.hasProperty(SpecimenConstant.LENGTH_IN_MM));
            assertTrue(specimen.hasProperty(SpecimenConstant.LIFE_STAGE_LABEL));
        }
        Relationship collectedAtRelationship = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING);
        assertNotNull(collectedAtRelationship);
        Node locationNode = collectedAtRelationship.getEndNode();
        assertNotNull(locationNode);
        assertThat(locationNode.getProperty(LocationConstant.LATITUDE), is(29.219302));
        assertThat(locationNode.getProperty(LocationConstant.LONGITUDE), is(-87.06665));
        totalRels.incrementAndGet();
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    return totalRels.get();
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Direction(org.neo4j.graphdb.Direction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Is(org.hamcrest.core.Is) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Is.is(org.hamcrest.core.Is.is) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationConstant(org.eol.globi.domain.LocationConstant) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener)

Aggregations

NodeTypeDirection (org.eol.globi.util.NodeTypeDirection)29 StudyNode (org.eol.globi.domain.StudyNode)25 Node (org.neo4j.graphdb.Node)21 Relationship (org.neo4j.graphdb.Relationship)20 Test (org.junit.Test)19 NodeUtil (org.eol.globi.util.NodeUtil)16 RelationshipListener (org.eol.globi.util.RelationshipListener)16 SpecimenNode (org.eol.globi.domain.SpecimenNode)15 Direction (org.neo4j.graphdb.Direction)14 RelTypes (org.eol.globi.domain.RelTypes)12 Specimen (org.eol.globi.domain.Specimen)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 TaxonNode (org.eol.globi.domain.TaxonNode)9 IOException (java.io.IOException)8 InteractType (org.eol.globi.domain.InteractType)8 Is.is (org.hamcrest.core.Is.is)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Study (org.eol.globi.domain.Study)7 Assert.assertTrue (org.junit.Assert.assertTrue)7