Search in sources :

Example 1 with NodeFactoryException

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()));
}
Also used : Node(org.neo4j.graphdb.Node) StopWatch(org.apache.commons.lang.time.StopWatch) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Relationship(org.neo4j.graphdb.Relationship)

Example 2 with NodeFactoryException

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;
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) NodeFactoryException(org.eol.globi.data.NodeFactoryException) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Aggregations

NodeFactoryException (org.eol.globi.data.NodeFactoryException)2 StopWatch (org.apache.commons.lang.time.StopWatch)1 TaxonImpl (org.eol.globi.domain.TaxonImpl)1 TaxonNode (org.eol.globi.domain.TaxonNode)1 PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1