Search in sources :

Example 6 with GraphServiceFactoryProxy

use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.

the class LinkerTaxonIndexTest method linkingWithIdOnlyNoPath.

@Test
public void linkingWithIdOnlyNoPath() throws NodeFactoryException {
    Taxon taxonFound = new TaxonImpl(null, "some id");
    taxonIndex.getOrCreateTaxon(taxonFound);
    resolveNames();
    new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb())).index();
    IndexHits<Node> hits = getGraphDb().index().forNodes(LinkerTaxonIndex.INDEX_TAXON_NAMES_AND_IDS).query("path:\"some id\"");
    assertThat(hits.hasNext(), is(true));
    Node next = hits.next();
    assertThat(new TaxonNode(next).getExternalId(), is("some id"));
    assertThat(hits.hasNext(), is(false));
    hits.close();
}
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) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) ResolvingTaxonIndexTest(org.eol.globi.taxon.ResolvingTaxonIndexTest) Test(org.junit.Test)

Example 7 with GraphServiceFactoryProxy

use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.

the class LinkerTaxonIndexTest method findByStringWithWhitespaces.

@Test
public void findByStringWithWhitespaces() throws NodeFactoryException {
    NonResolvingTaxonIndex taxonService = new NonResolvingTaxonIndex(getGraphDb());
    taxonService.getOrCreateTaxon(setTaxonProps(new TaxonImpl("Homo sapiens")));
    resolveNames();
    resolveNames();
    new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb())).index();
    assertThat(getGraphDb().index().existsForNodes(TaxonFuzzySearchIndex.TAXON_NAME_SUGGESTIONS), is(true));
    Index<Node> index = getGraphDb().index().forNodes(TaxonFuzzySearchIndex.TAXON_NAME_SUGGESTIONS);
    Query query = new TermQuery(new Term("name", "name"));
    IndexHits<Node> hits = index.query(query);
    assertThat(hits.size(), is(1));
    hits = index.query("name", "s nme~");
    assertThat(hits.size(), is(1));
    hits = index.query("name", "geRman~");
    assertThat(hits.size(), is(1));
    hits = index.query("name:geRman~ AND name:som~");
    assertThat(hits.size(), is(1));
    hits = index.query("name:hmo~ AND name:SApiens~");
    assertThat(hits.size(), is(1));
    hits = index.query("name:hmo~ AND name:sapiens~");
    assertThat(hits.size(), is(1));
    // queries are case sensitive . . . should all be lower cased.
    hits = index.query("name:HMO~ AND name:saPIENS~");
    assertThat(hits.size(), is(0));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Term(org.apache.lucene.index.Term) ResolvingTaxonIndexTest(org.eol.globi.taxon.ResolvingTaxonIndexTest) Test(org.junit.Test)

Example 8 with GraphServiceFactoryProxy

use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.

the class LinkerTaxonIndexTest method indexTaxaWithLiteratureLink.

private void indexTaxaWithLiteratureLink() 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("doi:10.123/456", "doi:10.123/456");
    taxon1.setPath("doi:10.123/456");
    taxon1.setPathIds("doi:10.123/456");
    NodeUtil.connectTaxa(taxon1, (TaxonNode) taxon, getGraphDb(), RelTypes.SAME_AS);
    resolveNames();
    new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb())).index();
}
Also used : Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy)

Example 9 with GraphServiceFactoryProxy

use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.

the class NameResolverTest method literatureTaxon.

@Test
public void literatureTaxon() throws NodeFactoryException {
    Specimen someOtherOrganism = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("foo", "foo:123"));
    Specimen someOtherOrganism2 = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("bar", "bar:456"));
    someOtherOrganism.ate(someOtherOrganism2);
    final NameResolver nameResolver = new NameResolver(new GraphServiceFactoryProxy(getGraphDb()), new ResolvingTaxonIndex(new PropertyEnricher() {

        @Override
        public Map<String, String> enrichFirstMatch(Map<String, String> properties) throws PropertyEnricherException {
            return enrichAllMatches(properties).get(0);
        }

        @Override
        public List<Map<String, String>> enrichAllMatches(Map<String, String> properties) throws PropertyEnricherException {
            TaxonImpl literature = new TaxonImpl("doi:10.678/901", "doi:10.678/901");
            literature.setPath("some | other | path");
            TaxonImpl concept = new TaxonImpl("Donald duckus", "foo:XXX");
            concept.setPath("some | path");
            return Arrays.asList(TaxonUtil.taxonToMap(literature), TaxonUtil.taxonToMap(concept));
        }

        @Override
        public void shutdown() {
        }
    }, getGraphDb()));
    nameResolver.setBatchSize(1L);
    nameResolver.index();
    Taxon resolvedTaxon = taxonIndex.findTaxonById("foo:123");
    assertThat(resolvedTaxon, is(notNullValue()));
    assertThat(resolvedTaxon.getExternalId(), is("foo:XXX"));
    assertThat(resolvedTaxon.getName(), is("Donald duckus"));
    Taxon resolvedTaxon2 = taxonIndex.findTaxonByName("foo");
    assertThat(resolvedTaxon2.getExternalId(), is("foo:XXX"));
    assertThat(resolvedTaxon2.getName(), is("Donald duckus"));
}
Also used : Specimen(org.eol.globi.domain.Specimen) PropertyEnricher(org.eol.globi.service.PropertyEnricher) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) ResolvingTaxonIndex(org.eol.globi.taxon.ResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 10 with GraphServiceFactoryProxy

use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.

the class NameResolverTest method iNaturalistTaxon.

@Test
public void iNaturalistTaxon() throws NodeFactoryException {
    Specimen someOtherOrganism = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Blaus bla", "INAT_TAXON:58831"));
    Specimen someOtherOrganism2 = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Redus rha", "INAT_TAXON:126777"));
    someOtherOrganism.ate(someOtherOrganism2);
    GraphServiceFactory graphServiceFactory = new GraphServiceFactoryProxy(getGraphDb());
    final NameResolver nameResolver = new NameResolver(graphServiceFactory, new NonResolvingTaxonIndex(getGraphDb()));
    nameResolver.setBatchSize(1L);
    nameResolver.index();
    Taxon resolvedTaxon = taxonIndex.findTaxonById("INAT_TAXON:58831");
    assertThat(resolvedTaxon, is(notNullValue()));
    assertThat(resolvedTaxon.getExternalId(), is("INAT_TAXON:58831"));
    assertThat(resolvedTaxon.getName(), is("Blaus bla"));
    Taxon resolvedTaxon2 = taxonIndex.findTaxonByName("Blaus bla");
    assertThat(resolvedTaxon2, is(notNullValue()));
    assertThat(resolvedTaxon2.getExternalId(), is("INAT_TAXON:58831"));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) GraphServiceFactory(org.eol.globi.db.GraphServiceFactory) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Test(org.junit.Test)

Aggregations

GraphServiceFactoryProxy (org.eol.globi.db.GraphServiceFactoryProxy)16 TaxonImpl (org.eol.globi.domain.TaxonImpl)13 Test (org.junit.Test)12 Taxon (org.eol.globi.domain.Taxon)11 StudyImpl (org.eol.globi.domain.StudyImpl)7 TaxonNode (org.eol.globi.domain.TaxonNode)7 Node (org.neo4j.graphdb.Node)7 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)6 Specimen (org.eol.globi.domain.Specimen)5 ResolvingTaxonIndexTest (org.eol.globi.taxon.ResolvingTaxonIndexTest)4 StudyNode (org.eol.globi.domain.StudyNode)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2 GraphDBTestCase (org.eol.globi.data.GraphDBTestCase)2 NodeFactoryException (org.eol.globi.data.NodeFactoryException)2 NodeFactoryNeo4j2 (org.eol.globi.data.NodeFactoryNeo4j2)2 RelTypes (org.eol.globi.domain.RelTypes)2 Study (org.eol.globi.domain.Study)2 PropertyEnricher (org.eol.globi.service.PropertyEnricher)2