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());
}
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();
}
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()));
}
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);
}
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();
}
Aggregations