Search in sources :

Example 1 with GraphServiceFactoryProxy

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

the class ResolvingTaxonIndexTest method ensureThatEnrichedPropertiesAreLinked.

@Test
public void ensureThatEnrichedPropertiesAreLinked() throws NodeFactoryException {
    this.taxonService = 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 {
            Taxon taxon1 = enrichTaxonWithSuffix(properties, "1");
            Taxon taxon2 = enrichTaxonWithSuffix(properties, "2");
            return Arrays.asList(TaxonUtil.taxonToMap(taxon1), TaxonUtil.taxonToMap(taxon2));
        }

        Taxon enrichTaxonWithSuffix(Map<String, String> properties, String suffix) {
            Taxon taxon = TaxonUtil.mapToTaxon(properties);
            taxon.setPathNames("kingdom" + suffix + CharsetConstant.SEPARATOR + "phylum" + CharsetConstant.SEPARATOR + "etc" + CharsetConstant.SEPARATOR);
            taxon.setPath("a kingdom name" + suffix + CharsetConstant.SEPARATOR + "a phylum name" + CharsetConstant.SEPARATOR + "a etc name" + CharsetConstant.SEPARATOR);
            taxon.setPathIds("a kingdom id" + suffix + CharsetConstant.SEPARATOR + "a phylum id" + CharsetConstant.SEPARATOR + "a etc id" + CharsetConstant.SEPARATOR);
            taxon.setExternalId("anExternalId" + suffix);
            taxon.setCommonNames(EXPECTED_COMMON_NAMES);
            return taxon;
        }

        @Override
        public void shutdown() {
        }
    }, getGraphDb());
    assertThat(getGraphDb().index().existsForNodes("taxons"), is(false));
    assertThat(getGraphDb().index().existsForNodes("thisDoesnoTExist"), is(false));
    TaxonNode indexedTaxonNode = taxonService.getOrCreateTaxon(new TaxonImpl("some name1"));
    assertThat(getGraphDb().index().existsForNodes("taxons"), is(true));
    assertEnrichedPropertiesSet(indexedTaxonNode, "1");
    TaxonNode someFoundTaxonNode = taxonService.findTaxonByName("some name1");
    assertThat(someFoundTaxonNode.getNodeID(), is(indexedTaxonNode.getNodeID()));
    assertEnrichedPropertiesSet(someFoundTaxonNode, "1");
    {
        Index<Node> ids = getGraphDb().index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
        assertThat(ids.query("path:\"some name2\"").size(), is(0));
    }
    LinkerTaxonIndex linkerTaxonIndex = new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb()));
    linkerTaxonIndex.index();
    {
        Index<Node> ids = getGraphDb().index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
        IndexHits<Node> hits = ids.query("path:\"a kingdom name2\"");
        assertThat(hits.size(), is(1));
        for (Node hit : hits) {
            TaxonNode taxonHit = new TaxonNode(hit);
            assertNotNull(taxonHit);
            assertThat(taxonHit.getNodeID(), is(indexedTaxonNode.getNodeID()));
        }
    }
    TaxonNode someOtherFoundTaxonNodeTake2 = taxonService.findTaxonByName("some name2");
    assertNull(someOtherFoundTaxonNodeTake2);
}
Also used : LinkerTaxonIndex(org.eol.globi.tool.LinkerTaxonIndex) TaxonNode(org.eol.globi.domain.TaxonNode) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) IndexHits(org.neo4j.graphdb.index.IndexHits) LinkerTaxonIndex(org.eol.globi.tool.LinkerTaxonIndex) Index(org.neo4j.graphdb.index.Index) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 2 with GraphServiceFactoryProxy

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

the class IndexInteractionsTest method indexInteractions.

@Test
public void indexInteractions() throws NodeFactoryException {
    TaxonIndex taxonIndex = getOrCreateTaxonIndex();
    // see https://github.com/globalbioticinteractions/globalbioticinteractions/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", new DOI("123.23", "222"), "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri"), inStream -> inStream));
    Study interaction = factory.getOrCreateStudy(study);
    TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
    Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
    donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
    TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
    Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
    NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
    Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
    mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
    donald.ate(mickey);
    new IndexInteractions(new GraphServiceFactoryProxy(getGraphDb())).index();
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j2(getGraphDb());
    StudyImpl study1 = new StudyImpl("some study", new DOI("123.23", "222"), "come citation");
    study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream));
    StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
    assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
    assertThat(interaction.getTitle(), is(someStudy.getTitle()));
    RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
    Set<Long> ids = new HashSet<>();
    List<Long> idList = new ArrayList<>();
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(someStudy.getUnderlyingNode()), new RelationshipListener() {

        @Override
        public void on(Relationship specimen) {
            assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
            Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(hasParticipant, Direction.INCOMING);
            for (Relationship relationship : relationships) {
                long id = relationship.getStartNode().getId();
                ids.add(id);
                idList.add(id);
            }
        }
    });
    assertThat(ids.size(), Is.is(1));
    assertThat(idList.size(), Is.is(2));
    Node interactionNode = getGraphDb().getNodeById(idList.get(0));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TaxonIndex(org.eol.globi.data.TaxonIndex) NodeUtil(org.eol.globi.util.NodeUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) Direction(org.neo4j.graphdb.Direction) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Is(org.hamcrest.core.Is) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) RelationshipListener(org.eol.globi.util.RelationshipListener) DOI(org.globalbioticinteractions.doi.DOI) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Taxon(org.eol.globi.domain.Taxon) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryException(org.eol.globi.data.NodeFactoryException) RelationshipType(org.neo4j.graphdb.RelationshipType) Study(org.eol.globi.domain.Study) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) TaxonNode(org.eol.globi.domain.TaxonNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) RelationshipListener(org.eol.globi.util.RelationshipListener) Specimen(org.eol.globi.domain.Specimen) TaxonIndex(org.eol.globi.data.TaxonIndex) DOI(org.globalbioticinteractions.doi.DOI) HashSet(java.util.HashSet) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Test(org.junit.Test)

Example 3 with GraphServiceFactoryProxy

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

the class LinkerDOITest method assertLinkMany.

private void assertLinkMany(long numberOfStudies) throws NodeFactoryException {
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "HOCKING"));
    getNodeFactory().getOrCreateStudy(new StudyImpl("title1", null, "MEDAN"));
    assertThat(study.getDOI(), is(nullValue()));
    for (int i = 0; i < numberOfStudies; i++) {
        getNodeFactory().getOrCreateStudy(new StudyImpl("id" + i, null, "foo bar this is not a citation" + i));
    }
    new LinkerDOI(new GraphServiceFactoryProxy(getGraphDb()), new DOIResolver() {

        @Override
        public Map<String, DOI> resolveDoiFor(Collection<String> references) throws IOException {
            Map<String, DOI> resolved = new HashMap<>();
            for (String reference : references) {
                resolved.put(reference, resolveDoiFor(reference));
            }
            return resolved;
        }

        @Override
        public DOI resolveDoiFor(String reference) throws IOException {
            return new DOI("123", "456");
        }
    }).index();
    StudyNode studyResolved = getNodeFactory().getOrCreateStudy(study);
    assertThat(studyResolved.getDOI(), is(new DOI("123", "456")));
}
Also used : HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) Collection(java.util.Collection) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) DOIResolver(org.eol.globi.service.DOIResolver) StudyNode(org.eol.globi.domain.StudyNode) DOI(org.globalbioticinteractions.doi.DOI)

Example 4 with GraphServiceFactoryProxy

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

the class LinkerDOITest method doLink.

@Test
public void doLink() throws NodeFactoryException, PropertyEnricherException {
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "some citation"));
    new LinkerDOI(new GraphServiceFactoryProxy(getGraphDb())).index();
    Study studyResolved = nodeFactory.getOrCreateStudy(study);
    assertThat(studyResolved.getDOI(), is(nullValue()));
    assertThat(study.getDOI(), is(nullValue()));
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 5 with GraphServiceFactoryProxy

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

the class LinkerTaxonIndexTest method linkingWithNameOnly.

@Test
public void linkingWithNameOnly() throws NodeFactoryException {
    Taxon taxonFound = new TaxonImpl("urn:catalog:AMNH:Mammals:M-39582", null);
    taxonIndex.getOrCreateTaxon(taxonFound);
    Taxon foundTaxon = taxonIndex.findTaxonByName("urn:catalog:AMNH:Mammals:M-39582");
    assertThat(foundTaxon, is(not(nullValue())));
    assertThat(foundTaxon.getName(), is("urn:catalog:AMNH:Mammals:M-39582"));
    resolveNames();
    new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb())).index();
    IndexHits<Node> hits = getGraphDb().index().forNodes(LinkerTaxonIndex.INDEX_TAXON_NAMES_AND_IDS).query("path:\"urn:catalog:AMNH:Mammals:M-39582\"");
    Node next = hits.next();
    assertThat(new TaxonNode(next).getName(), is("urn:catalog:AMNH:Mammals:M-39582"));
    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)

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