将具有公共关系的节点与关系进行匹配-Neo4j Cypher [英] Match nodes with common nodes with a relationship - 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.
推荐答案
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屋!