Search in sources :

Example 16 with TaxonNode

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

the class NonResolvingTaxonIndexTest method assertNotIndexed.

private final void assertNotIndexed(String magicValue) throws NodeFactoryException {
    Taxon taxon1 = new TaxonImpl(magicValue, null);
    taxon1.setPath(null);
    TaxonNode taxon = taxonService.getOrCreateTaxon(taxon1);
    assertThat(taxon, is(notNullValue()));
    assertThat(taxonService.findTaxonByName(magicValue), is(nullValue()));
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 17 with TaxonNode

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

the class NonResolvingTaxonIndexTest method createTaxonExternalIdIndex.

@Test
public final void createTaxonExternalIdIndex() throws NodeFactoryException {
    Taxon taxon1 = new TaxonImpl(null, "foo:123");
    taxon1.setPath(null);
    TaxonNode taxon = taxonService.getOrCreateTaxon(taxon1);
    assertThat(taxon, is(notNullValue()));
    assertThat(taxonService.findTaxonById("foo:123"), is(notNullValue()));
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Test(org.junit.Test)

Example 18 with TaxonNode

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

the class NonResolvingTaxonIndexTest method createNullTaxon.

@Test
public final void createNullTaxon() throws NodeFactoryException {
    Taxon taxon1 = new TaxonImpl(null, "EOL:1234");
    taxon1.setPath(null);
    TaxonNode taxon = taxonService.getOrCreateTaxon(taxon1);
    assertThat(taxon, is(notNullValue()));
    assertEquals("no name", taxon.getName());
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Test(org.junit.Test)

Example 19 with TaxonNode

use of org.eol.globi.domain.TaxonNode 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)

Example 20 with TaxonNode

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

the class LinkerOpenTreeOfLife method link.

protected boolean link(GraphDatabaseService graphDb, OpenTreeTaxonIndex index, Map<String, Long> ottIds, Relationship rel) {
    boolean hasPrexistingLink = false;
    TaxonNode taxonNode = new TaxonNode(rel.getEndNode());
    String externalId = taxonNode.getExternalId();
    if (StringUtils.contains(externalId, TaxonomyProvider.OPEN_TREE_OF_LIFE.getIdPrefix())) {
        ottIds.clear();
        hasPrexistingLink = true;
    } else {
        externalId = StringUtils.replace(externalId, TaxonomyProvider.INTERIM_REGISTER_OF_MARINE_AND_NONMARINE_GENERA.getIdPrefix(), "irmng:");
        externalId = StringUtils.replace(externalId, TaxonomyProvider.INDEX_FUNGORUM.getIdPrefix(), "if:");
        externalId = StringUtils.replace(externalId, TaxonomyProvider.GBIF.getIdPrefix(), "gbif:");
        externalId = StringUtils.replace(externalId, TaxonomyProvider.NCBI.getIdPrefix(), "ncbi:");
        Long ottId = index.findOpenTreeTaxonIdFor(externalId);
        if (ottId != null) {
            if (ottIds.size() == 0) {
                Taxon taxonCopy = copyAndLinkToOpenTreeTaxon(taxonNode, ottId);
                NodeUtil.connectTaxa(taxonCopy, new TaxonNode(rel.getStartNode()), graphDb, RelTypes.SAME_AS);
            }
            ottIds.put(externalId, ottId);
        }
    }
    return hasPrexistingLink;
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon)

Aggregations

TaxonNode (org.eol.globi.domain.TaxonNode)31 Taxon (org.eol.globi.domain.Taxon)13 Test (org.junit.Test)13 Node (org.neo4j.graphdb.Node)12 Relationship (org.neo4j.graphdb.Relationship)12 TaxonImpl (org.eol.globi.domain.TaxonImpl)11 Study (org.eol.globi.domain.Study)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Specimen (org.eol.globi.domain.Specimen)5 SpecimenNode (org.eol.globi.domain.SpecimenNode)5 Transaction (org.neo4j.graphdb.Transaction)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)3 StudyImpl (org.eol.globi.domain.StudyImpl)2 StudyNode (org.eol.globi.domain.StudyNode)2 PropertyEnricher (org.eol.globi.service.PropertyEnricher)2 TaxonFuzzySearchIndex (org.eol.globi.taxon.TaxonFuzzySearchIndex)2