简体   繁体   English

neo4j中的双向数据建模问题

[英]Bidirectional Data modeling issue in neo4j

I have two nodes, A and B, A talks to B and B talks to A, (A)-[:talksTo]-(B) 我有两个节点,A和B,A与B对话,B与A对话,(A)-[:talksTo]-(B)

A has a sentiment value towards B, and B has a sentiment value towards A. A对B具有情感价值,B对A具有情感价值。

So there is the problem, I need A to B relationship to store a value that the B to A relationship will also want to store (same key). 所以有一个问题,我需要A与B的关系来存储B与A的关系也要存储的值(相同的键)。

So I will try to do queries such as, MATCH (A:person)-[:talksTo]-(B:person) where A.sentiment < -2 return A; 因此,我将尝试执行诸如MATCH(A:person)-[:talksTo]-(B:person)之类的查询,其中A.sentiment <-2返回A;

So here A's sentiment toward B will be different the B's sentiment toward A, thus the needed separation. 因此,这里A对B的情感与B对A的情感有所不同,因此需要分开。

I have tried to make unique key names to specify direction - but that makes queries difficult unless I can query with a wild card ex: ... where A.Asentiment < -2 would be queried as ... where A.*sentiment < -2 我试图使用唯一的键名来指定方向-但是除非我可以使用通配符ex进行查询,否则这将使查询变得困难:...其中A.Asentiment <-2将被查询为...其中A. * sentiment < -2

Another way I can think of to do this is make two different graphs, 1) A talks to B graph and B talks to A graph... but this would make queries tricky as I may get back more then one node for single node queries OR if I have to update a single node key:value to something else. 我可以想到的另一种方式是制作两个不同的图,1)A与B图交谈,B与A图交谈...但这将使查询变得棘手,因为我可能会为一个单节点查询返回多个节点或者,如果我必须将单个节点的key:value更新为其他值。 I would prefer to have one node name per person. 我希望每人拥有一个节点名称。

Any ideas? 有任何想法吗?

I don't know that this is a solution, but I don't think I understand enough so it might be a foil for better understanding: 我不知道这是一个解决方案,但是我认为我不够了解,因此它可能是增进理解的障碍:

MATCH (A:Person)-[dir1:talksTo]->(B:Person), (A)<-[dir2:talksTo]-(B)
WHERE dir1.sentiment < 2
RETURN A, B

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

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