use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalist method buildTypeMap.
public static Map<Integer, InteractType> buildTypeMap(String resource, LabeledCSVParser labeledCSVParser) throws IOException {
LabeledCSVParser parser = labeledCSVParser;
Map<Integer, InteractType> typeMap = new TreeMap<Integer, InteractType>();
while (parser.getLine() != null) {
String inatIdString = parser.getValueByLabel("observation_field_id");
Integer inatId = null;
String prefix = PREFIX_OBSERVATION_FIELD;
if (StringUtils.startsWith(inatIdString, prefix)) {
inatId = Integer.parseInt(inatIdString.replace(prefix, ""));
}
if (inatId == null) {
LOG.warn("failed to map observation field id [" + inatIdString + "] in line [" + resource + ":" + parser.lastLineNumber() + "]");
} else {
String interactionTypeId = parser.getValueByLabel("interaction_type_id");
InteractType interactType = InteractType.typeOf(interactionTypeId);
if (interactType == null) {
LOG.warn("failed to map interaction type [" + interactionTypeId + "] in line [" + resource + ":" + parser.lastLineNumber() + "]");
} else {
typeMap.put(inatId, interactType);
}
}
}
return typeMap;
}
use of org.eol.globi.domain.InteractType in project eol-globi-data by jhpoelen.
the class TaxonInteractionIndexer method createTaxonInteractions.
public void createTaxonInteractions(Map<Fun.Tuple3<Long, String, Long>, Long> taxonInteractions) {
StopWatch watchForEntireRun = new StopWatch();
watchForEntireRun.start();
long count = 0;
Transaction tx = null;
for (Fun.Tuple3<Long, String, Long> uniqueTaxonInteraction : taxonInteractions.keySet()) {
if (count % 1000 == 0) {
finalizeTx(tx);
tx = graphService.beginTx();
}
final Node sourceTaxon = graphService.getNodeById(uniqueTaxonInteraction.a);
final Node targetTaxon = graphService.getNodeById(uniqueTaxonInteraction.c);
if (sourceTaxon != null && targetTaxon != null) {
final InteractType relType = InteractType.valueOf(uniqueTaxonInteraction.b);
final Long interactionCount = taxonInteractions.get(uniqueTaxonInteraction);
createInteraction(sourceTaxon, targetTaxon, relType, false, interactionCount);
createInteraction(targetTaxon, sourceTaxon, InteractType.inverseOf(relType), true, interactionCount);
}
count++;
}
finalizeTx(tx);
watchForEntireRun.stop();
LOG.info("created [" + count + "] taxon interactions in " + getProgressMsg(count, watchForEntireRun.getTime()));
}
use of org.eol.globi.domain.InteractType 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)));
}
}
Aggregations