编辑:这不起作用,因为它是一个二分图。我得先做个投影。我会在解决后更新请随时评论/回答。
当我在Neo4桌面中运行以下代码时,得到以下错误:Neo.ClientError.Procedure.ProcedureCallFailed:Failed to invoke Procedurealgo.louvain
:原因:java.lang.ArrayIndexOutOfBoundsException:-1
我知道我可能在患者节点和has_处方关系之间有索引不匹配。例如,并不是每个病人都有处方如何使Neo4j忽略此错误或如何修复它?
对于上下文,其他算法(如algo.scc过程)在同一组节点和关系上工作我要补充的是,我确实有一些限制,迫使病人和处方节点是不同的。
CALL algo.louvain('PATIENTS', 'HAS_PRESCRIPTION',
{write:true, writeProperty:'community'})
YIELD nodes, communityCount, iterations, loadMillis, computeMillis,
writeMillis;
我希望algo.louvain过程至少编译并返回节点、communityCount、iterations、loadMillis、computeMilis和writeMillis。
最佳答案
结果是,由于这是一个二部图,病人节点只连接到处方节点,所以我不得不归纳出这样一个病人-病人图:
CALL algo.louvain.stream(
'MATCH (i:PRESCRIPTION) RETURN id(i) as id',
'MATCH (i1:PRESCRIPTION)<--(:PATIENTS)-->(i2:PRESCRIPTION)
WITH i1,i2,count(*) as common_patients
WHERE common_patients > 20
RETURN id(i1) as source,id(i2) as target, common_patients as weight'
,{graph:'cypher'}) yield nodeId, community
MATCH (p:PRESCRIPTION) where id(p)=nodeId
RETURN community,
count(*) as communitySize,
collect(p.SHORT_TITLE) as ps
ORDER BY communitySize desc limit 5
这来自以下来源:https://tbgraph.wordpress.com/2017/11/27/neo4j-graph-algorithms-projecting-a-virtual-graph/
关于algorithm - 如何在运行Neo4j的Louvain算法的上下文中解决以下错误:java.lang.ArrayIndexOutOfBoundsException:-1?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57574145/