neo4j-contrib / neo4j-graph-algorithms

Efficient Graph Algorithms for Neo4j
https://github.com/neo4j/graph-data-science/
GNU General Public License v3.0
770 stars 194 forks source link

How can I use your algorithm in scenario of embedding Java application? #915

Closed smanalysis closed 5 years ago

smanalysis commented 5 years ago

I use java code to create and load a embedded neo4j database like (version 3.5.8): db = new GraphDatabaseFactory().newEmbeddedDatabase(dbDirectory);

I download your standalone file from https://neo4j.com/download-center/, and add the jar to my application.

However, when I try to execute the code: Result lr = db.execute("CALL algo.list()");

I receive the error msg:

Exception in thread "main" org.neo4j.graphdb.QueryExecutionException: There is no procedure with the name algo.list registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.

What should I do before calling your proceduces?

jjaderberg commented 5 years ago

When running Neo4j embedded, procedures aren't registered automatically, like they are for jars in the plugins/ directory when running Neo4j normally. You have to register the procedures explicitly. If you have the jar on classpath, do:

    GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder(storeDir).setConfig(config).newGraphDatabase();
    Procedures procedures = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Procedures.class);
    procedures.registerProcedure(ListProc.class);

This will load the algo.list procedure. You will have to enumerate all the procedures that you want to use and explicitly register them this way.

I'm curious, why are you running algos over Neo4j embedded?

jjaderberg commented 5 years ago

@smanalysis Closing as resolved. Drop a note if you still have trouble.