Search in sources :

Example 1 with CyNodeLoadingProcessor

use of uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor in project rdf2neo by Rothamsted.

the class CypherLoaderIT method testLoading.

@Test
public void testLoading() throws Exception {
    try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
        RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
        Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver);
        SimpleCyLoader cyloader = new SimpleCyLoader()) {
        // TODO: configurator, multiple config sets
        CyNodeLoadingHandler cyNodeHandler = new CyNodeLoadingHandler();
        CyRelationLoadingHandler cyRelHandler = new CyRelationLoadingHandler();
        cyNodeHandler.setLabelsSparql(IOUtils.readResource("dbpedia_node_labels.sparql"));
        cyNodeHandler.setNodePropsSparql(IOUtils.readResource("dbpedia_node_props.sparql"));
        cyNodeHandler.setRdfDataManager(rdfMgr);
        cyNodeHandler.setNeo4jDataManager(neoMgr);
        cyRelHandler.setRelationTypesSparql(IOUtils.readResource("dbpedia_rel_types.sparql"));
        cyRelHandler.setRelationPropsSparql(IOUtils.readResource("dbpedia_rel_props.sparql"));
        cyRelHandler.setRdfDataManager(rdfMgr);
        cyRelHandler.setNeo4jDataManager(neoMgr);
        CyNodeLoadingProcessor cyNodeProc = new CyNodeLoadingProcessor();
        cyNodeProc.setNodeIrisSparql(IOUtils.readResource("dbpedia_node_iris.sparql"));
        cyNodeProc.setConsumer(cyNodeHandler);
        CyRelationLoadingProcessor cyRelProc = new CyRelationLoadingProcessor();
        cyRelProc.setConsumer(cyRelHandler);
        cyloader.setCyNodeLoader(cyNodeProc);
        cyloader.setCyRelationLoader(cyRelProc);
        cyloader.load(RdfDataManagerTest.TDB_PATH);
    // TODO: test!
    }
// try neoDriver
}
Also used : RdfDataManager(uk.ac.rothamsted.rdf.neo4j.load.support.RdfDataManager) Neo4jDataManager(uk.ac.rothamsted.rdf.neo4j.load.support.Neo4jDataManager) Driver(org.neo4j.driver.v1.Driver) CyNodeLoadingProcessor(uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor) CyNodeLoadingHandler(uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingHandler) CyRelationLoadingHandler(uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingHandler) CyRelationLoadingProcessor(uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingProcessor) Test(org.junit.Test) RdfDataManagerTest(uk.ac.rothamsted.rdf.neo4j.load.support.RdfDataManagerTest)

Example 2 with CyNodeLoadingProcessor

use of uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor in project rdf2neo by Rothamsted.

the class CypherLoaderIT method testMultiConfigLoading.

@Test
public void testMultiConfigLoading() throws Exception {
    try (MultiConfigCyLoader cymloader = new MultiConfigCyLoader()) {
        cymloader.setCypherLoaderFactory(() -> {
            // This will eventually be managed by Spring
            RdfDataManager rdfMgr = new RdfDataManager();
            Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
            Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver);
            CyNodeLoadingHandler cyNodeHandler = new CyNodeLoadingHandler();
            CyRelationLoadingHandler cyRelHandler = new CyRelationLoadingHandler();
            cyNodeHandler.setRdfDataManager(rdfMgr);
            cyNodeHandler.setNeo4jDataManager(neoMgr);
            cyRelHandler.setRdfDataManager(rdfMgr);
            cyRelHandler.setNeo4jDataManager(neoMgr);
            CyNodeLoadingProcessor cyNodeProc = new CyNodeLoadingProcessor();
            cyNodeProc.setConsumer(cyNodeHandler);
            CyRelationLoadingProcessor cyRelProc = new CyRelationLoadingProcessor();
            cyRelProc.setConsumer(cyRelHandler);
            SimpleCyLoader cyloader = new SimpleCyLoader();
            cyloader.setCyNodeLoader(cyNodeProc);
            cyloader.setCyRelationLoader(cyRelProc);
            cyloader.setRdfDataManager(rdfMgr);
            return cyloader;
        });
        List<ConfigItem> config = new LinkedList<>();
        config.add(new ConfigItem("places", readResource("dbpedia_node_iris.sparql"), readResource("dbpedia_node_labels.sparql"), readResource("dbpedia_node_props.sparql"), readResource("dbpedia_rel_types.sparql"), readResource("dbpedia_rel_props.sparql")));
        config.add(new ConfigItem("people", readResource("dbpedia_people_iris.sparql"), readResource("dbpedia_people_labels.sparql"), readResource("dbpedia_people_props.sparql"), readResource("dbpedia_people_rel_types.sparql"), null));
        cymloader.setConfigItems(config);
        cymloader.load(RdfDataManagerTest.TDB_PATH);
    }
// TODO: test!
}
Also used : RdfDataManager(uk.ac.rothamsted.rdf.neo4j.load.support.RdfDataManager) Neo4jDataManager(uk.ac.rothamsted.rdf.neo4j.load.support.Neo4jDataManager) Driver(org.neo4j.driver.v1.Driver) ConfigItem(uk.ac.rothamsted.rdf.neo4j.load.MultiConfigCyLoader.ConfigItem) CyNodeLoadingProcessor(uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor) CyNodeLoadingHandler(uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingHandler) CyRelationLoadingHandler(uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingHandler) CyRelationLoadingProcessor(uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingProcessor) LinkedList(java.util.LinkedList) Test(org.junit.Test) RdfDataManagerTest(uk.ac.rothamsted.rdf.neo4j.load.support.RdfDataManagerTest)

Example 3 with CyNodeLoadingProcessor

use of uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor in project rdf2neo by Rothamsted.

the class MultiConfigCyLoader method load.

/**
 * Loops through {@link #getConfigItems() config items} and instantiates a {@link #getCypherLoaderFactory() new simple loader}
 * for eache item, to load nodes/relations mapped by the config item.
 */
@Override
public void load(String tdbPath, Object... opts) {
    // 
    for (int mode = 0; mode <= 1; mode++) {
        for (ConfigItem cfg : this.getConfigItems()) {
            try (SimpleCyLoader cypherLoader = this.getCypherLoaderFactory().getObject()) {
                cypherLoader.setName(cfg.getName());
                CyNodeLoadingProcessor cyNodeLoader = cypherLoader.getCyNodeLoader();
                CyRelationLoadingProcessor cyRelLoader = cypherLoader.getCyRelationLoader();
                CyNodeLoadingHandler cyNodehandler = (CyNodeLoadingHandler) cyNodeLoader.getConsumer();
                CyRelationLoadingHandler cyRelhandler = (CyRelationLoadingHandler) cyRelLoader.getConsumer();
                cyNodeLoader.setNodeIrisSparql(cfg.getNodeIrisSparql());
                cyNodehandler.setLabelsSparql(cfg.getLabelsSparql());
                cyNodehandler.setNodePropsSparql(cfg.getNodePropsSparql());
                cyRelhandler.setRelationTypesSparql(cfg.getRelationTypesSparql());
                cyRelhandler.setRelationPropsSparql(cfg.getRelationPropsSparql());
                String indexesSparql = cfg.getIndexesSparql();
                if (indexesSparql != null)
                    cypherLoader.getCypherIndexer().setIndexesSparql(indexesSparql);
                cypherLoader.load(tdbPath, mode == 0, mode == 1);
            }
        // try
        }
    // for config items
    }
// for mode
}
Also used : CyNodeLoadingProcessor(uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor) CyRelationLoadingProcessor(uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingProcessor) CyNodeLoadingHandler(uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingHandler) CyRelationLoadingHandler(uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingHandler)

Aggregations

CyNodeLoadingHandler (uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingHandler)3 CyNodeLoadingProcessor (uk.ac.rothamsted.rdf.neo4j.load.support.CyNodeLoadingProcessor)3 CyRelationLoadingHandler (uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingHandler)3 CyRelationLoadingProcessor (uk.ac.rothamsted.rdf.neo4j.load.support.CyRelationLoadingProcessor)3 Test (org.junit.Test)2 Driver (org.neo4j.driver.v1.Driver)2 Neo4jDataManager (uk.ac.rothamsted.rdf.neo4j.load.support.Neo4jDataManager)2 RdfDataManager (uk.ac.rothamsted.rdf.neo4j.load.support.RdfDataManager)2 RdfDataManagerTest (uk.ac.rothamsted.rdf.neo4j.load.support.RdfDataManagerTest)2 LinkedList (java.util.LinkedList)1 ConfigItem (uk.ac.rothamsted.rdf.neo4j.load.MultiConfigCyLoader.ConfigItem)1