简体   繁体   English

Neo4j关系设计

[英]Neo4j Relationship design

Revisiting Neo4j after a long absence. 久违后重温Neo4j。 I have read a lot of articles but still find I have a few questions to get me going again.... 我已经阅读了很多文章,但是仍然发现我有一些问题可以让我再次前进。

  1. Bidirectional relationships I have a “connected to”-type scenario where 2 nodes are connected to each other. 双向关系我有一个“连接到”类型的场景,其中2个节点相互连接。 In fact, the idea is to model a type of flow. 实际上,该想法是对一种流进行建模。 However, the flow in both directions is not always the same. 但是,双向流动并不总是相同的。 I'm uncertain of the best method to use: 1 relationship with 2 properties or 2 distinct relationships? 我不确定要使用的最佳方法:1个具有2个属性的关系或2个不同的关系?

The former feels like the comfortable choice but then doesn't feel natural in terms of modelling the actual facts – for example: what to call the properties because FlowIn and FlowOut wouldn't make sense when looked at from each nodes' perspective. 前者感觉很舒适,但随后在建模实际事实时就感觉不自然了-例如:该调用什么属性,因为从每个节点的角度看,FlowIn和FlowOut毫无意义。 I also wonder about the performance of properties versus relationships in this case – these values will need to be updated. 我还想知道在这种情况下属性与关系的性能-这些值将需要更新。

  1. Representing Time Now I want to take a step further and represent the flow between nodes at specific times or, more accurately, between specific times. 表示时间现在,我想更进一步,表示在特定时间或更准确地说在特定时间之间节点之间的流。 So between 2pm and 3pm the flow between #1 and #2 will be x. 因此,在下午2点到下午3点之间,#1和#2之间的流量为x。

How should this be done in an optimal way? 应该如何以最佳方式完成此操作? Relationship per time frame per connection seems….verbose. 每个连接的每个时间范围的关系似乎....冗长。 Could a timeframe being represented as a node be of value?! 将时间范围表示为节点是否有价值?

  1. Are there any Maximum Flow samples with Cypher out there? 是否有Cypher外的最大流量样品? Particularly interested in push-relabel max flow problem solving. 对推送重新标记最大流量问题的解决特别感兴趣。

Thank you for any advice to might have to offer. 感谢您提供的任何建议。

While you have definitely given some thought to your problem the question is a little unclear. 尽管您已经对问题进行了一定的思考,但这个问题仍然不清楚。 This seems to be a question about Graph Data Models. 这似乎是关于图数据模型的问题。 You would like to know how best to organize a model to represent a complex relationship. 您想知道如何最好地组织模型来表示复杂的关系。 If you are trying to track the "flow" between two nodes then assign a weight property to a unidirected edge. 如果要跟踪两个节点之间的“流”,则将权重属性分配给单向边。

Bidirectional relationships should be carefully considered. 双向关系应仔细考虑。 Neo4j can process them just as fast as unidirectional relationships. Neo4j可以像处理单向关系一样快地对其进行处理。 A quote from the graphaware about using bidirectional relationships: Graphaware中关于使用双向关系的引文

Relationships in Neo4j can be traversed in both directions with the same speed. Neo4j中的关系可以以相同的速度在两个方向上遍历。 Moreover, direction can be completely ignored. 而且,方向可以完全忽略。 Therefore, there is no need to create two different relationships between nodes, if one implies the other. 因此,如果一个节点暗示另一个,则无需在节点之间创建两个不同的关系。

I believe your problems can be alleviated by gaining a better understanding of Graph data models. 我相信,通过更好地了解Graph数据模型可以缓解您的问题。 Looking at a few different models and understanding the why will help more than understanding cypher syntax at this point. 查看一些不同的模型并理解其原因,比此时理解密码语法更有帮助。 May I suggest reading this survey by 2 professors at the University of Chile titled "Survey of Graph Database Models." 可能我建议您阅读本次调查由在智利大学教授2人名为“图形数据库模型的调查。” The "Hypernode" model on page 21 may be of particular interest to you since it sounds like you are trying to model a complex cyclic object. 您可能对第21页的“超节点”模型特别感兴趣,因为这听起来像是您正在尝试对复杂的循环对象建模。 From page twenty one; 从第二十一页开始;

Hypernodes can be used to represent simple (flat) and complex objects (hierarchical, composite, and cyclic) as well as mappings and records. 超节点可用于表示简单(平面)和复杂对象(分层,复合和循环)以及映射和记录。 A key feature is its inherent ability to encapsulate information. 一个关键功能是其固有的封装信息的能力。

Hopefully that information helps you in your efforts to model a complex relationship. 希望这些信息可以帮助您建立复杂的关系。

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

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