Search in sources :

Example 16 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class StudyImporterForGoMexSI2IT method assertSpecimenProperties.

private static void assertSpecimenProperties(GraphDatabaseService service) {
    Index<Node> taxa = service.index().forNodes("taxons");
    boolean detectedAtLeastOneLifeState = false;
    boolean detectedAtLeastOnePhysiologicalState = false;
    boolean detectedAtLeastOnePreyBodyPart = false;
    boolean detectedAtLeastOneBodyLength = false;
    boolean detectedAtLeastOneLocation = false;
    boolean detectedAtLeastOneFrequencyOfOccurrence = false;
    boolean detectedAtLeastOneTotalNumberConsumed = false;
    boolean detectedAtLeastOneTotalVolume = false;
    boolean detectedAtLeastOneGoMexSIProperty = false;
    assertThat(taxa, is(notNullValue()));
    for (Node taxonNode : taxa.query("name", "*")) {
        Iterable<Relationship> classifiedAs = taxonNode.getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
        for (Relationship classifiedA : classifiedAs) {
            Node specimenNode = classifiedA.getStartNode();
            detectedAtLeastOneLifeState |= specimenNode.hasProperty(SpecimenConstant.LIFE_STAGE_LABEL);
            detectedAtLeastOnePhysiologicalState |= specimenNode.hasProperty(SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL);
            detectedAtLeastOnePreyBodyPart |= specimenNode.hasProperty(SpecimenConstant.BODY_PART_LABEL);
            detectedAtLeastOneBodyLength |= specimenNode.hasProperty(SpecimenConstant.LENGTH_IN_MM);
            detectedAtLeastOneFrequencyOfOccurrence |= specimenNode.hasProperty(SpecimenConstant.FREQUENCY_OF_OCCURRENCE);
            detectedAtLeastOneTotalNumberConsumed |= specimenNode.hasProperty(SpecimenConstant.TOTAL_COUNT);
            detectedAtLeastOneTotalVolume |= specimenNode.hasProperty(SpecimenConstant.TOTAL_VOLUME_IN_ML);
            detectedAtLeastOneGoMexSIProperty |= specimenNode.hasProperty(StudyImporterForGoMexSI2.GOMEXSI_NAMESPACE + "PRED_DATABASE_NAME");
            detectedAtLeastOneGoMexSIProperty |= specimenNode.hasProperty(StudyImporterForGoMexSI2.GOMEXSI_NAMESPACE + "PREY_DATABASE_NAME");
            if (specimenNode.hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED))) {
                detectedAtLeastOneLocation = true;
            }
        }
    }
    assertThat(detectedAtLeastOneLifeState, is(true));
    assertThat(detectedAtLeastOnePhysiologicalState, is(true));
    assertThat(detectedAtLeastOnePreyBodyPart, is(true));
    assertThat(detectedAtLeastOneLocation, is(true));
    assertThat(detectedAtLeastOneBodyLength, is(true));
    assertThat(detectedAtLeastOneFrequencyOfOccurrence, is(true));
    assertThat(detectedAtLeastOneTotalNumberConsumed, is(true));
    assertThat(detectedAtLeastOneTotalVolume, is(true));
    assertThat(detectedAtLeastOneGoMexSIProperty, is(true));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) Relationship(org.neo4j.graphdb.Relationship)

Example 17 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class StudyImporterForINaturalistTest method importTestResponse.

@Test
public void importTestResponse() throws IOException, StudyImporterException {
    importer.parseJSON(getClass().getResourceAsStream("inaturalist/sample_inaturalist_response.json"), new ArrayList<Integer>() {

        {
            add(47);
        }
    }, new HashMap<Integer, InteractType>() {

        {
            put(13, InteractType.ATE);
        }
    });
    resolveNames();
    assertThat(NodeUtil.findAllStudies(getGraphDb()).size(), is(22));
    Study anotherStudy = nodeFactory.findStudy("INAT:831");
    assertThat(anotherStudy, is(notNullValue()));
    assertThat(anotherStudy.getCitation(), containsString("Ken-ichi Ueda. 2008. Argiope eating Orthoptera. iNaturalist.org. Accessed at <https://www.inaturalist.org/observations/831> on "));
    assertThat(anotherStudy.getExternalId(), is("https://www.inaturalist.org/observations/831"));
    anotherStudy = nodeFactory.findStudy("INAT:97380");
    assertThat(anotherStudy, is(notNullValue()));
    assertThat(anotherStudy.getCitation(), containsString("annetanne. 2012. Misumena vatia eating Eristalis nemorum."));
    assertThat(anotherStudy.getExternalId(), is("https://www.inaturalist.org/observations/97380"));
    Taxon sourceTaxonNode = taxonIndex.findTaxonByName("Arenaria interpres");
    assertThat(sourceTaxonNode, is(not(nullValue())));
    Iterable<Relationship> relationships = ((NodeBacked) sourceTaxonNode).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    for (Relationship relationship : relationships) {
        Node sourceSpecimen = relationship.getStartNode();
        assertThat(new SpecimenNode(sourceSpecimen).getBasisOfRecord().getName(), is("HumanObservation"));
        assertThat(new SpecimenNode(sourceSpecimen).getBasisOfRecord().getId(), is("TEST:HumanObservation"));
        assertThat(new SpecimenNode(sourceSpecimen).getExternalId(), containsString(TaxonomyProvider.ID_PREFIX_INATURALIST));
        Relationship ateRel = sourceSpecimen.getSingleRelationship(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
        Node preySpecimen = ateRel.getEndNode();
        assertThat(preySpecimen, is(not(nullValue())));
        Relationship preyClassification = preySpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
        String actualPreyName = (String) preyClassification.getEndNode().getProperty("name");
        assertThat(actualPreyName, is("Crepidula fornicata"));
        Relationship locationRel = sourceSpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING);
        assertThat((Double) locationRel.getEndNode().getProperty("latitude"), is(41.249813));
        assertThat((Double) locationRel.getEndNode().getProperty("longitude"), is(-72.542556));
        Relationship collectedRel = sourceSpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED), Direction.INCOMING);
        assertThat((Long) collectedRel.getProperty(SpecimenConstant.DATE_IN_UNIX_EPOCH), is(any(Long.class)));
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) Relationship(org.neo4j.graphdb.Relationship) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SpecimenNode(org.eol.globi.domain.SpecimenNode) Test(org.junit.Test)

Example 18 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class StudyImporterForRobledoTest method createAndPopulateStudy.

@Test
public void createAndPopulateStudy() throws StudyImporterException, NodeFactoryException {
    StudyImporterForRobledo importer = new StudyImporterForRobledo(new ParserFactoryLocal(), nodeFactory);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    assertNotNull(taxonIndex.findTaxonByName("Heliconia imbricata"));
    assertNotNull(taxonIndex.findTaxonByName("Renealmia alpinia"));
    assertNotNull(nodeFactory.findStudy(study.getTitle()));
    int count = 0;
    Iterable<Relationship> specimenRels = NodeUtil.getSpecimens(study);
    for (Relationship specimenRel : specimenRels) {
        Specimen specimen1 = new SpecimenNode(specimenRel.getEndNode());
        Location sampleLocation = specimen1.getSampleLocation();
        assertThat(sampleLocation, is(notNullValue()));
        assertThat(sampleLocation.getAltitude(), is(35.0));
        assertThat(Math.round(sampleLocation.getLongitude()), is(-84L));
        assertThat(Math.round(sampleLocation.getLatitude()), is(10L));
        count++;
    }
    assertThat(count, is(93));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) SpecimenNode(org.eol.globi.domain.SpecimenNode) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Aggregations

SpecimenNode (org.eol.globi.domain.SpecimenNode)18 Relationship (org.neo4j.graphdb.Relationship)17 Study (org.eol.globi.domain.Study)13 Test (org.junit.Test)11 Specimen (org.eol.globi.domain.Specimen)9 Node (org.neo4j.graphdb.Node)7 HashMap (java.util.HashMap)6 JsonNode (org.codehaus.jackson.JsonNode)5 Location (org.eol.globi.domain.Location)5 Taxon (org.eol.globi.domain.Taxon)4 TaxonNode (org.eol.globi.domain.TaxonNode)4 Date (java.util.Date)3 Environment (org.eol.globi.domain.Environment)3 LocationImpl (org.eol.globi.domain.LocationImpl)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 LogContext (org.eol.globi.domain.LogContext)2 Term (org.eol.globi.domain.Term)2 DatasetImpl (org.eol.globi.service.DatasetImpl)2