将具有公共关系的节点与关系进行匹配-Neo4j Cypher [英] Match nodes with common nodes with a relationship - Neo4j Cypher

查看:133
本文介绍了将具有公共关系的节点与关系进行匹配-Neo4j Cypher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个用户"节点和技能"节点.关系是技能和用户之间的关系.

I have number of User nodes and Skills nodes. The relationship is between skills and users.

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:/xyz.csv" AS row FIELDTERMINATOR '|'
WITH row
LIMIT 15

CREATE (u:User {company: row.company, salary: row.salary_float,         designation: row.designation, experience: row.experience_float})

FOREACH (s IN split(row.tag_skill, "@") |
MERGE (skill:SKILL {name: s})
ON CREATE SET skill.name = s
CREATE (u)-[:KNOWS]->(skill))

我还需要用户节点之间的关系,其中 如果用户A连接到技能节点的编号[s1,s2,s3,s4,s5,s6] 并且如果用户B已连接到[s1,s3,s4,s6]

I also need a relationship between user nodes where if User A is connected to a number for Skill nodes [s1,s2,s3,s4,s5,s6] and if User B is connected to [s1,s3,s4,s6]

如果用户A和用户B的技能中至少有50%匹配,则他们之间的关系(相似).

User A and User B are in relationship(similar) if atleast 50% of their skills match.

在此示例中,A与B有关系,因为它们的s1,s3,s4,s6的共同点大于50%匹配

in this example, A is in a relationship with B since they have s1,s3,s4,s6 in common which is more than 50% match

似乎无法弄清楚这个密码查询.

Cant seem to figure out this cypher query.

推荐答案

这是我对我们寻找具有至少一项共同技能(1)的u1u2用户.然后,我们分别收集他们的个人技能(2)并对其进行计数(3),还收集他们的相互技能(4)并对其进行计数(5).然后,我们删除(u1, u2)(u2, u1)对中的一个(例如,从(Alice, Bob)(Bob, Alice)中,我们仅保留前者(6),并检查其共同技能的数量是否超过阈值(7).(在Cypher-IIRC中,浮点运算有时会比较棘手,如果将/ 0.5移到不等式的右侧作为sXCount * 0.5,则必须使用toFloat()函数.)

We look for u1, u2 Users that have at least a single common Skill (1). We then gather their individual skills separately (2) and count them (3), and also gather their mutual Skills (4) and count them (5). We then remove one of the (u1, u2) and (u2, u1) pairs (e.g. from (Alice, Bob) and (Bob, Alice) we only keep the former (6) and check if the number of their common skills is above the threshold (7). (Floating point arithmetics is sometimes tricky in Cypher - IIRC if we move the / 0.5 to the right side of the inequality as sXCount * 0.5, we'd have to use the toFloat() function).

这篇关于将具有公共关系的节点与关系进行匹配-Neo4j Cypher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆