Search in sources :

Example 11 with GraphServiceFactoryProxy

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

the class CypherTestUtil method validate.

public static void validate(CypherQuery cypherQuery, GraphDatabaseService graphDatabaseService) {
    try (Transaction tx = graphDatabaseService.beginTx()) {
        new NodeFactoryNeo4j2(graphDatabaseService);
        new NonResolvingTaxonIndex(graphDatabaseService);
        new LinkerTaxonIndex(new GraphServiceFactoryProxy(graphDatabaseService)).index();
        CacheService cacheService = new CacheService();
        File cacheDir = new File("target/reportGeneration" + UUID.randomUUID());
        cacheService.setCacheDir(cacheDir);
        CmdGenerateReport reportGenerator = new CmdGenerateReport(graphDatabaseService, cacheService);
        reportGenerator.run(NOPLogger.NOP_LOGGER);
        Map<String, Object> params = cypherQuery.getParams() == null ? Collections.emptyMap() : new HashMap<>(cypherQuery.getParams());
        try {
            graphDatabaseService.execute(cypherQuery.getVersionedQuery(), params);
        } catch (NullPointerException ex) {
            // encountered nullpointer exceptions were caused by initialization of graph database
            throw ex;
        } catch (RuntimeException ex) {
            // work fine in cypher query, but cause parse exception when running programatically
            if (!ex.getMessage().contains("Encountered \" \":\" \": \"\"")) {
                throw ex;
            }
        } finally {
            FileUtils.deleteQuietly(cacheDir);
        }
    }
}
Also used : NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) LinkerTaxonIndex(org.eol.globi.tool.LinkerTaxonIndex) Transaction(org.neo4j.graphdb.Transaction) CmdGenerateReport(org.eol.globi.tool.CmdGenerateReport) File(java.io.File) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) CacheService(org.eol.globi.service.CacheService)

Example 12 with GraphServiceFactoryProxy

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

the class LinkerOpenTreeOfLifeTest method assertOTTLink.

protected void assertOTTLink(int expectedCount, String ottId, Taxon taxon) throws NodeFactoryException, PropertyEnricherException {
    OpenTreeTaxonIndex index = null;
    try {
        index = new OpenTreeTaxonIndex(getClass().getResource("taxonomy-small.tsv"));
        Taxon createdTaxon = taxonIndex.getOrCreateTaxon(taxon);
        long nodeID = ((NodeBacked) createdTaxon).getNodeID();
        new LinkerTermMatcher((terms, termMatchListener) -> {
            for (Term term : terms) {
                termMatchListener.foundTaxonForTerm(nodeID, term, NameType.SAME_AS, taxon);
            }
        }, new GraphServiceFactoryProxy(getGraphDb())).index();
        new LinkerOpenTreeOfLife(index, new GraphServiceFactoryProxy(getGraphDb())).index();
        Collection<String> externalIds = LinkerTestUtil.assertHasOther(taxon.getName(), expectedCount, taxonIndex, RelTypes.SAME_AS);
        assertThat(externalIds, hasItem(TaxonomyProvider.OPEN_TREE_OF_LIFE.getIdPrefix() + ottId));
    } finally {
        if (index != null) {
            index.destroy();
        }
    }
}
Also used : Taxon(org.eol.globi.domain.Taxon) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) NodeBacked(org.eol.globi.domain.NodeBacked) Term(org.eol.globi.domain.Term) OpenTreeTaxonIndex(org.eol.globi.opentree.OpenTreeTaxonIndex) Collection(java.util.Collection) PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) Test(org.junit.Test) NameType(org.eol.globi.domain.NameType) RelTypes(org.eol.globi.domain.RelTypes) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) TaxonImpl(org.eol.globi.domain.TaxonImpl) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Is.is(org.hamcrest.core.Is.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) NodeBacked(org.eol.globi.domain.NodeBacked) Taxon(org.eol.globi.domain.Taxon) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Term(org.eol.globi.domain.Term) OpenTreeTaxonIndex(org.eol.globi.opentree.OpenTreeTaxonIndex)

Example 13 with GraphServiceFactoryProxy

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

the class LinkerTermMatcherTest method assertTaxonMapping.

private void assertTaxonMapping(String classifiedId) throws NodeFactoryException {
    Taxon taxon2 = new TaxonImpl("Holorchis castex", classifiedId);
    Taxon createdTaxon = taxonIndex.getOrCreateTaxon(taxon2);
    Node specimenDummy = getGraphDb().createNode();
    Node originalTaxonDummy = getGraphDb().createNode();
    originalTaxonDummy.setProperty("name", "holorchis castex");
    originalTaxonDummy.setProperty("externalId", "EOL:11987314");
    specimenDummy.createRelationshipTo(originalTaxonDummy, NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS));
    specimenDummy.createRelationshipTo(((TaxonNode) createdTaxon).getUnderlyingNode(), NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    TaxonCacheService taxonCacheService = new TaxonCacheService("/org/eol/globi/taxon/taxonCacheHolorchis.tsv", "/org/eol/globi/taxon/taxonMapHolorchis.tsv");
    new LinkerTermMatcher(taxonCacheService, new GraphServiceFactoryProxy(getGraphDb())).index();
    Collection<String> externalIds = LinkerTestUtil.sameAsCountForNode(RelTypes.SAME_AS, (TaxonNode) createdTaxon);
    assertThat(externalIds, hasItem("EOL_V2:11987314"));
    assertThat(externalIds, hasItem("GBIF:5890922"));
}
Also used : TaxonCacheService(org.eol.globi.taxon.TaxonCacheService) 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)

Example 14 with GraphServiceFactoryProxy

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

the class TaxonInteractionIndexerTest method indexNoNameNoMatch.

@Test
public void indexNoNameNoMatch() throws NodeFactoryException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Homo sapiens", PropertyAndValueDictionary.NO_MATCH));
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Canis lupus", PropertyAndValueDictionary.NO_MATCH));
    human.ate(animal);
    for (int i = 0; i < 10; i++) {
        Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Arius felis", null));
        human.ate(fish);
    }
    assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    new NameResolver(new GraphServiceFactoryProxy(getGraphDb()), new NonResolvingTaxonIndex(getGraphDb())).index();
    assertNotNull(taxonIndex.findTaxonByName("Homo sapiens"));
    assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxonIndex.findTaxonByName(PropertyAndValueDictionary.NO_NAME));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Test(org.junit.Test)

Example 15 with GraphServiceFactoryProxy

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

the class TaxonInteractionIndexerTest method buildTaxonInterIndex.

@Test
public void buildTaxonInterIndex() throws NodeFactoryException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Homo sapiens", "NCBI:9606"));
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Canis lupus", "WORMS:2"));
    human.ate(animal);
    for (int i = 0; i < 10; i++) {
        Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Arius felis", "WORMS:158711"));
        human.ate(fish);
    }
    assertNull(taxonIndex.findTaxonById("WORMS:2"));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    new NameResolver(new GraphServiceFactoryProxy(getGraphDb()), new NonResolvingTaxonIndex(getGraphDb())).index();
    new TaxonInteractionIndexer(new GraphServiceFactoryProxy(getGraphDb())).index();
    Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
    assertNotNull(homoSapiens);
    Iterable<Relationship> rels = ((NodeBacked) homoSapiens).getUnderlyingNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
    List<String> humanFood = new ArrayList<String>();
    List<Long> counts = new ArrayList<Long>();
    List<String> labels = new ArrayList<>();
    for (Relationship rel : rels) {
        humanFood.add((String) rel.getEndNode().getProperty("name"));
        counts.add((Long) rel.getProperty("count"));
        labels.add((String) rel.getProperty("label"));
    }
    assertThat(humanFood.size(), is(4));
    assertThat(humanFood, hasItems("Arius felis", "Canis lupus"));
    assertThat(counts, hasItems(10L, 1L));
    assertThat(labels, hasItems("eats"));
}
Also used : NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) ArrayList(java.util.ArrayList) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) 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