简体   繁体   English

Neo4j如何为同一关系调用不同的属性

[英]Neo4j How to call different properties for the same relationship

I'm using the new algo to calculate similarities, algo.similarity.jaccard and algo.similarity.overlap with the option WRITE, it means, in the relationship SIMILARITY I create properties sim_jaccard and sim_overlap. 我正在使用新的算法来计算相似性,使用选项WRITE计算algo.similarity.jaccard和algo.similarity.overlap,这意味着,在关系SIMILARITY中,我创建了sim_jaccard和sim_overlap属性。 The problem comes when I call these two properties, for example : 当我调用这两个属性时,问题就来了,例如:

MATCH (u1:User)-[s:SIMILARITY]-> (u2:User)
WITH coalesce(s.sim_jaccard,0) AS sim_jaccard, coalesce(s.sim_overlap,0)  AS sim_overlap
RETURN sim_jaccard, sim_overlap
LIMIT 25

I get: 我得到:

sim_jaccard  sim_overlap
0            0.8507462686567164
0            0.9253731343283582 
0            0.8208955223880597
0            0.8955223880597015

I think that happens because properties id are different in the relationship: 我认为发生这种情况是因为属性id在关系中是不同的:

SIMILARITY <id>: 3300778 sim_overlap: 1.0
SIMILARITY <id>: 2453827 sim_jaccard: 0.6268656716417911

I would like to have: 我想拥有:

SIMILARITY <id>: 3300778 sim_overlap: 1.0,  sim_jaccard: 0.6268656716417911

Any idea to solve that? 有解决的办法吗?

Thanks in advance. 提前致谢。

If you want to modify your graph so the relationships are combined into 1, then APOC Procedures has some refactor procs to merge relationships together (just use the combine value for the given properties). 如果要修改图形以使关系合并为1,则APOC过程具有一些重构过程以将关系合并在一起(只需将combine值用于给定的属性)。

If you just want your return to combine the values into a single line, then you can modify your query to sum the values for all rels between the two nodes: 如果只想将返回值组合成一行,则可以修改查询以将两个节点之间的所有相关项的值相加:

MATCH (u1:User)-[s:SIMILARITY]-(u2:User)
WHERE id(u1) < id(u2)
WITH u1, u2, sum(coalesce(s.sim_jaccard,0)) AS sim_jaccard, sum(coalesce(s.sim_overlap,0))  AS sim_overlap
RETURN sim_jaccard, sim_overlap
LIMIT 25

For the approach where you need to MERGE nodes, you'll want to collect the relationships with respect to the end nodes before calling the procedure: 对于需要合并节点的方法,您将需要在调用过程之前收集与端节点有关的关系:

MATCH (u1:User)-[s:SIMILARITY]-(u2:User)
WHERE id(u1) < id(u2)
WITH u1, u2, collect(s) as rels
CALL apoc.refactor.mergeRelationships(rels, {properties:'combine'}) YIELD rel
RETURN count(rel)

sum(coalesce(s.sim_jaccard,0)) AS sim_jaccard, sum(coalesce(s.sim_overlap,0)) AS sim_overlap RETURN sim_jaccard, sim_overlap LIMIT 25 sum(coalesce(s.sim_jaccard,0))AS sim_jaccard,sum(coalesce(s.sim_overlap,0))AS sim_overlap返回sim_jaccard,sim_overlap LIMIT 25

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM