Search in sources :

Example 26 with TaxonNode

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

the class StudyImporterForLifeWatchGreeceTest method addTaxonNameForSpecimenNode.

private void addTaxonNameForSpecimenNode(Set<String> taxa, Node startNode) {
    Specimen predatorSpecimen = new SpecimenNode(startNode);
    Iterable<Relationship> classifications = NodeUtil.getClassifications(predatorSpecimen);
    for (Relationship classification : classifications) {
        taxa.add(new TaxonNode(classification.getEndNode()).getName());
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) SpecimenNode(org.eol.globi.domain.SpecimenNode)

Example 27 with TaxonNode

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

the class ExportUnmatchedTaxonNamesTest method exportOnePredatorNoPathButWithSameAs.

@Test
public void exportOnePredatorNoPathButWithSameAs() throws NodeFactoryException, IOException {
    taxonIndex = ExportTestUtil.taxonIndexWithEnricher(null, getGraphDb());
    String citation = "cite, study";
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("my, study", "my first, source", null, citation));
    Specimen predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapienz", null));
    Taxon humanz = taxonIndex.getOrCreateTaxon(new TaxonImpl("Homo sapienz", null));
    TaxonImpl taxon = new TaxonImpl("Homo sapiens", "TESTING:123");
    taxon.setPath("one | two | Homo sapiens");
    NodeUtil.connectTaxa(taxon, (TaxonNode) humanz, getGraphDb(), RelTypes.SIMILAR_TO);
    assertNotNull(humanz);
    Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Caniz", null));
    predatorSpecimen.interactsWith(preySpecimen, InteractType.ATE);
    predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens", null));
    Node synonymNode = ((NodeBacked) taxonIndex.getOrCreateTaxon(new TaxonImpl("Homo sapiens Synonym", null))).getUnderlyingNode();
    Node node = ((NodeBacked) taxonIndex.getOrCreateTaxon(new TaxonImpl("Homo sapiens", null))).getUnderlyingNode();
    Transaction tx = getGraphDb().beginTx();
    try {
        node.createRelationshipTo(synonymNode, NodeUtil.asNeo4j(RelTypes.SAME_AS));
        tx.success();
    } finally {
        tx.finish();
    }
    preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Canis", null));
    predatorSpecimen.ate(preySpecimen);
    resolveNames();
    StringWriter writer = new StringWriter();
    new ExportUnmatchedTaxonNames().exportStudy(study, writer, true);
    assertThat(writer.toString(), is("unmatched taxon name\tunmatched taxon id\tname status\tsimilar to taxon name\tsimilar to taxon path\tsimilar to taxon id\tstudy\tsource" + "\nHomo sapienz\t\t\tHomo sapiens\tone | two | Homo sapiens\tTESTING:123\tcite, study\tmy first, source" + "\nCaniz\t\t\t\t\t\tcite, study\tmy first, source" + "\nCanis\t\t\t\t\t\tcite, study\tmy first, source"));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) NodeBacked(org.eol.globi.domain.NodeBacked) Transaction(org.neo4j.graphdb.Transaction) StringWriter(java.io.StringWriter) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 28 with TaxonNode

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

the class NonResolvingTaxonIndexTest method createTaxon.

@Test
public final void createTaxon() throws NodeFactoryException {
    Taxon taxon1 = new TaxonImpl("bla bla", null);
    taxon1.setPath(null);
    TaxonNode taxon = taxonService.getOrCreateTaxon(taxon1);
    assertThat(taxon, is(notNullValue()));
    assertEquals("bla bla", 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 29 with TaxonNode

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

the class ResolvingTaxonIndexTest method indexResolvedOnly.

@Test
public void indexResolvedOnly() throws NodeFactoryException {
    TaxonNode unresolvedTaxon = getIndex().getOrCreateTaxon(new TaxonImpl("not resolved"));
    assertNotNull(unresolvedTaxon);
    assertFalse(TaxonUtil.isResolved(unresolvedTaxon));
    final ResolvingTaxonIndex indexResolvedOnly = getIndex();
    indexResolvedOnly.setIndexResolvedTaxaOnly(true);
    assertNull(indexResolvedOnly.getOrCreateTaxon(new TaxonImpl("no resolving either", null)));
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) TaxonImpl(org.eol.globi.domain.TaxonImpl) Test(org.junit.Test)

Example 30 with TaxonNode

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

the class LinkerTaxonIndexTest method linking.

@Test
public void linking() throws NodeFactoryException {
    Taxon taxonFound = new TaxonImpl("Homo sapiens", "Bar:123");
    taxonFound.setPath("Animalia | Mammalia | Homo sapiens");
    Taxon taxon = taxonIndex.getOrCreateTaxon(taxonFound);
    TaxonImpl taxon1 = new TaxonImpl("Homo sapiens also", "FOO:444");
    taxon1.setPathIds("BARZ:111 | FOOZ:777");
    NodeUtil.connectTaxa(taxon1, (TaxonNode) taxon, getGraphDb(), RelTypes.SAME_AS);
    taxon = taxonIndex.getOrCreateTaxon(new TaxonImpl("Bla blaus", null));
    taxon.setExternalId("FOO 1234");
    resolveNames();
    new LinkerTaxonIndex(getGraphDb()).link();
    IndexHits<Node> hits = getGraphDb().index().forNodes(LinkerTaxonIndex.INDEX_TAXON_NAMES_AND_IDS).query("*:*");
    Node next = hits.next();
    assertThat(new TaxonNode(next).getName(), is("Homo sapiens"));
    assertThat(hits.hasNext(), is(true));
    hits.close();
    assertSingleHit(PropertyAndValueDictionary.PATH + ":BAR\\:123");
    assertSingleHit(PropertyAndValueDictionary.PATH + ":FOO\\:444");
    assertSingleHit(PropertyAndValueDictionary.PATH + ":FOO\\:444 " + PropertyAndValueDictionary.PATH + ":BAR\\:123");
    assertSingleHit(PropertyAndValueDictionary.PATH + ":BAR\\:*");
    assertSingleHit(PropertyAndValueDictionary.PATH + ":Homo");
    assertSingleHit(PropertyAndValueDictionary.PATH + ":\"Homo sapiens\"");
    Taxon node = taxonIndex.findTaxonByName("Homo sapiens");
    assertThat(((NodeBacked) node).getUnderlyingNode().getProperty(PropertyAndValueDictionary.EXTERNAL_IDS).toString(), is("Animalia | Mammalia | Homo sapiens | BARZ:111 | FOOZ:777 | Bar:123 | FOO:444"));
    assertThat(((NodeBacked) node).getUnderlyingNode().getProperty(PropertyAndValueDictionary.NAME_IDS).toString(), is("Bar:123 | FOO:444"));
    assertThat(new TaxonFuzzySearchIndex(getGraphDb()).query("name:sapienz~").size(), is(1));
    assertThat(new TaxonFuzzySearchIndex(getGraphDb()).query("name:sapienz").size(), is(0));
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) TaxonFuzzySearchIndex(org.eol.globi.taxon.TaxonFuzzySearchIndex) ResolvingTaxonIndexTest(org.eol.globi.taxon.ResolvingTaxonIndexTest) Test(org.junit.Test)

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