use of org.eol.globi.data.NodeFactoryException in project eol-globi-data by jhpoelen.
the class NameResolver method resolveNames.
public void resolveNames(Long batchSize) {
StopWatch watchForEntireRun = new StopWatch();
watchForEntireRun.start();
StopWatch watchForBatch = new StopWatch();
watchForBatch.start();
Long count = 0L;
Index<Node> studyIndex = graphService.index().forNodes("studies");
IndexHits<Node> studies = studyIndex.query("title", "*");
for (Node studyNode : studies) {
final Study study1 = new StudyNode(studyNode);
final Iterable<Relationship> specimens = NodeUtil.getSpecimens(study1);
for (Relationship collected : specimens) {
SpecimenNode specimen = new SpecimenNode(collected.getEndNode());
final Relationship classifiedAs = specimen.getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
if (classifiedAs == null) {
final Relationship describedAs = specimen.getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING);
final TaxonNode describedAsTaxon = new TaxonNode(describedAs.getEndNode());
try {
if (taxonFilter.shouldInclude(describedAsTaxon)) {
Taxon resolvedTaxon = taxonIndex.getOrCreateTaxon(describedAsTaxon);
if (resolvedTaxon != null) {
specimen.classifyAs(resolvedTaxon);
}
}
} catch (NodeFactoryException e) {
LOG.warn("failed to create taxon with name [" + describedAsTaxon.getName() + "] and id [" + describedAsTaxon.getExternalId() + "]", e);
} finally {
count++;
if (count % batchSize == 0) {
watchForBatch.stop();
final long duration = watchForBatch.getTime();
if (duration > 0) {
LOG.info("resolved batch of [" + batchSize + "] names in " + getProgressMsg(batchSize, duration));
}
watchForBatch.reset();
watchForBatch.start();
}
}
}
}
}
studies.close();
watchForEntireRun.stop();
LOG.info("resolved [" + count + "] names in " + getProgressMsg(count, watchForEntireRun.getTime()));
}
use of org.eol.globi.data.NodeFactoryException in project eol-globi-data by jhpoelen.
the class ResolvingTaxonIndex method resolveAndIndex.
private TaxonNode resolveAndIndex(Taxon origTaxon, Taxon taxon) throws NodeFactoryException {
TaxonNode indexedTaxon = findTaxon(taxon);
while (indexedTaxon == null) {
try {
taxon = TaxonUtil.enrich(enricher, taxon);
} catch (PropertyEnricherException e) {
throw new NodeFactoryException("failed to enrich taxon with name [" + taxon.getName() + "]", e);
}
indexedTaxon = findTaxon(taxon);
if (indexedTaxon == null) {
if (TaxonUtil.isResolved(taxon)) {
indexedTaxon = createAndIndexTaxon(origTaxon, taxon);
} else {
String truncatedName = NodeUtil.truncateTaxonName(taxon.getName());
if (StringUtils.equals(truncatedName, taxon.getName())) {
if (isIndexResolvedOnly()) {
break;
} else {
indexedTaxon = addNoMatchTaxon(origTaxon);
}
} else {
taxon = new TaxonImpl();
taxon.setName(truncatedName);
indexedTaxon = findTaxonByName(taxon.getName());
}
}
}
}
return indexedTaxon;
}
Aggregations