Search in sources :

Example 1 with LinkerTaxonIndex

use of org.eol.globi.tool.LinkerTaxonIndex 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 LinkerTaxonIndex

use of org.eol.globi.tool.LinkerTaxonIndex 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)

Aggregations

GraphServiceFactoryProxy (org.eol.globi.db.GraphServiceFactoryProxy)2 LinkerTaxonIndex (org.eol.globi.tool.LinkerTaxonIndex)2 File (java.io.File)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 NodeFactoryNeo4j2 (org.eol.globi.data.NodeFactoryNeo4j2)1 Taxon (org.eol.globi.domain.Taxon)1 TaxonImpl (org.eol.globi.domain.TaxonImpl)1 TaxonNode (org.eol.globi.domain.TaxonNode)1 CacheService (org.eol.globi.service.CacheService)1 PropertyEnricher (org.eol.globi.service.PropertyEnricher)1 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)1 CmdGenerateReport (org.eol.globi.tool.CmdGenerateReport)1 Test (org.junit.Test)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 Index (org.neo4j.graphdb.index.Index)1 IndexHits (org.neo4j.graphdb.index.IndexHits)1