有没有人玩过Neo4j Open Graph Data Science库?在Open GDS的基础上开发扩展算法插件。
发布于 4 个月前 作者 icejean 269 次浏览 来自 问答

Hi,大家好, 我想在Eclipse里建个Maven项目,在Open Graph Data Science库的基础上开发一些扩展的算法,作为Plugin与GDS一起使用,之前的Neo4j community 4.4+Open GDS 2.0.2已经搞定了,现在想跟进一下Neo4j的版本升级,Neo4j community 5.10.0+ Open GDS 2.5.5, 建立 Eclipse Maven项目后,导入一些算法,比如spanningtree, 编译没有问题,算法的junit测试也没有问题,但调用算法的procedure的junit测试就不行,比如org.neo4j.gds.paths.spanningtree.SpanningTreeStatsProcTest,test-utils加载测试用的Neo4j实例时就出错了。详情请阅community.neo4j.com上的帖子Github Open GDS项目上的帖子。 我主要是要在Open GDS上开发无向图的K最小生成树及有向图的最小树形图算法,之前的研究可以看看我的几篇研究文章: 《Neo4j自定义过程开发之K最小生成树算法》:https://www.meipian.cn/3gj6iqhz 《在网络分析中使用Neo4j用户自定义函数与过程》:https://www.meipian.cn/459u8wpz 《机场航线环路分析》:https://www.meipian.cn/451a6tnz 请大家多多指教! 有向图入度方向的最小树形图 arborescence-1.PNG 有向图出度方向的最小树形图 arborescence-2.PNG Neo4j community 4.4.5+ Open GDS 2.0.2 Eclipse扩展算法插件项目 Eclipse.PNG

3 回复

测试的Cypher语句:

//---最小树形图测试   入度方向 供应链--------------------------------------------------------------------------------------------------------------------------------

         
match(n) detach delete n;

        

CREATE(a:Node {name: 'a'}), 
			(b:Node {name: 'b'}),
			(c:Node {name: 'c'}), 
			(d:Node {name: 'd'}),
			(e:Node {name: 'e'}), 
			(b)-[:TYPE {cost:17}]->(a),	(c)-[:TYPE {cost:16}]->(a),	(d)-[:TYPE {cost:19}]->(a),	(e)-[:TYPE {cost:16}]->(a), 
			(c)-[:TYPE {cost:3}]->(b),	(d)-[:TYPE {cost:3}]->(b), (e)-[:TYPE {cost:11}]->(b), 
			(b)-[:TYPE {cost:3}]->(c), (d)-[:TYPE {cost:4}]->(c), (e)-[:TYPE {cost:8}]->(c),
			(b)-[:TYPE {cost:3}]->(d),(c)-[:TYPE {cost:4}]->(d), (e)-[:TYPE {cost:12}]->(d),
			(b)-[:TYPE {cost:11}]->(e),	(c)-[:TYPE {cost:8}]->(e), (d)-[:TYPE {cost:12}]->(e);

 
CALL gds.graph.project(
  'graph',
  'Node',
  {
    LINK: {
      type: 'TYPE',
      properties: 'cost',
      orientation: 'NATURAL'
    }
  }
)     


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescence.minimum.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'MINSA',
  weightWriteProperty: 'cost'
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescence.kmin.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'KMINSA',
  weightWriteProperty: 'cost',
  k: 4
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescence.maximum.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'MAXSA',
  weightWriteProperty: 'cost'
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescence.kmax.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'KMAXSA',
  weightWriteProperty: 'cost',
  k: 4
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


match (n)-[r]->(m) return n,r,m;



//---最小树形图测试  出度方向  销售链--------------------------------------------------------------------------------------------------------------------------------

CALL gds.graph.drop( 'graph');

match(n) detach delete n;

CREATE(a:Node {name: 'a'}), 
			(b:Node {name: 'b'}),
			(c:Node {name: 'c'}), 
			(d:Node {name: 'd'}),
			(e:Node {name: 'e'}), 
			(b)<-[:TYPE {cost:17}]-(a),	(c)<-[:TYPE {cost:16}]-(a),	(d)<-[:TYPE {cost:19}]-(a),	(e)<-[:TYPE {cost:16}]-(a), 
			(c)<-[:TYPE {cost:3}]-(b),	(d)<-[:TYPE {cost:3}]-(b), (e)<-[:TYPE {cost:11}]-(b), 
			(b)<-[:TYPE {cost:3}]-(c), (d)<-[:TYPE {cost:4}]-(c), (e)<-[:TYPE {cost:8}]-(c),
			(b)<-[:TYPE {cost:3}]-(d), (c)<-[:TYPE {cost:4}]-(d), (e)<-[:TYPE {cost:12}]-(d),
			(b)<-[:TYPE {cost:11}]-(e),	(c)<-[:TYPE {cost:8}]-(e), (d)<-[:TYPE {cost:12}]-(e);

CALL gds.graph.project(
  'graph',
  'Node',
  {
    LINK: {
      type: 'TYPE',
      properties: 'cost',
      orientation: 'NATURAL'
    }
  }
)     


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescenceReverse.minimum.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'MINSA',
  weightWriteProperty: 'cost'
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescenceReverse.kmin.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'KMINSA',
  weightWriteProperty: 'cost',
  k: 4
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescenceReverse.maximum.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'MAXSA',
  weightWriteProperty: 'cost'
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


MATCH (n:Node {name: 'a'})
CALL gds.alpha.spanningArborescenceReverse.kmax.write('graph', {
  startNodeId: id(n),
  relationshipWeightProperty: 'cost',
  writeProperty: 'KMAXSA',
  weightWriteProperty: 'cost',
  k: 4
})
YIELD preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN preProcessingMillis, computeMillis, writeMillis, effectiveNodeCount;


match (n)-[r]->(m) return n,r,m;

这个问题Neo4j Open GDS项目的团队已经定位了,是因为test-utils 2.5.5是用Neo4j 4.x编译的,在Neo4j 5.x上运行就会出错。他们给出了一个暂时的fix,详见Github项目主页上的issue: Hi @icejean, thank you for the code, after inspection we think that the issue is coming up because the test-utils published to Maven was compiled using Neo4j 4.4 database as default and there are some differences in the it-test-support artifact. I would suggest you make verbatim copies of org.neo4j.gds.BaseTest and org.neo4j.gds.BaseProcTest to your test package org.neo4j.gds, just rename them to not be confused with the ones provided by test-utils and use them in your tests instead of the default ones. This is sort of a quick and dirty(ish) workaround to get you unblocked, I will raise the issue with the team and we will think about more permanent and robust solution.

D:\eclipse2022\workspace\Open-GDS-Extend-2.5.5>mvn test -Dtest=org.neo4j.gds.paths.spanningtree.SpanningTreeStatsProcTest#testYields -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< cn.jean.neo4j:gds-extend >----------------------
[INFO] Building Jean's Neo4j GDS Extend 1.0.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- enforcer:3.4.1:enforce (enforce) @ gds-extend ---
[INFO] Rule 0: org.apache.maven.enforcer.rules.version.RequireJavaVersion passed
[INFO] Rule 1: org.apache.maven.enforcer.rules.version.RequireMavenVersion passed
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ gds-extend ---
[INFO] skip non existing resourceDirectory D:\eclipse2022\workspace\Open-GDS-Extend-2.5.5\src\main\resources
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ gds-extend ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 29 source files with javac [debug release 17] to target\classes
[WARNING] 注释处理不适用于隐式编译的文件。
  使用 -proc:none 禁用注释处理或使用 -implicit 指定用于隐式编译的策略。
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ gds-extend ---
[INFO] Copying 1 resource from src\test\resources to target\test-classes
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ gds-extend ---
[INFO] Changes detected - recompiling the module! :dependency
[INFO] Compiling 12 source files with javac [debug release 17] to target\test-classes
[INFO]
[INFO] --- surefire:3.1.2:test (default-test) @ gds-extend ---
[INFO] Surefire report directory: D:\eclipse2022\workspace\Open-GDS-Extend-2.5.5\target\surefire-reports
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.neo4j.gds.paths.spanningtree.SpanningTreeStatsProcTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.880 s -- in org.neo4j.gds.paths.spanningtree.SpanningTreeStatsProcTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18.927 s
[INFO] Finished at: 2024-01-10T10:00:14+08:00
[INFO] ------------------------------------------------------------------------

D:\eclipse2022\workspace\Open-GDS-Extend-2.5.5>
回到顶部