本文介绍了在 neo4j v.2 (cypher) 中建模条件关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个相关的问题需要帮助.

I have two related problems I need help with.

问题 1:如何为条件关系建模?我希望我的数据表明,当测试 CLT1 的结果"属性 =高"时,CLT1 与疾病 A 有关系.如果我采用以节点为中心的方法,我想代码可能看起来像......

Problem 1: How do I model a conditional relationship?I want my data to indicate that when test CLT1's "Result" property = "High", CLT1 has relationship to Disease A. If I take a node-centric approach, I imagine that the code might look something like...

(CLT 1 {Result: "High"})  -[:INDICATES] -> (Disease A)

此外,当CLT1的Result"属性=Low"时,CLT1与疾病B有关系

Further, when CLT1's "Result" property = "Low", CLT1 has a relationship to Disease B

(CLT 1 {Result: "Low"})  -[:INDICATES] ->  (Disease B)

或者,如果我采用以关系为中心的方法,代码可能如下所示...

Alternatively, if I take a relationship-centric approach, the code might look like this...

(CLT 1) -[:INDICATES {Result: "High"}] -> (Disease A)
(CLT 1) -[:INDICATES {Result: "Low"} ] -> (Disease B)

问题 2

我有过对数据建模的经验,有 1 个节点具有唯一名称,但标签或属性不同.问题是我希望这些节点是可区分的.然而,它们与 cypher 看起来并不一样.

I have had the experience that I am modeling my data, there is 1 node with a unique name, but either different labels or properties. The thing is that I want these nodes to be distinguishable. However, they are not as they look the same to cypher.

我可以给他们多个属性、标签或不同的名称.多样性必须针对每个不同的类别……标签或属性(1+n 个标签、属性)或不同的名称.

I can either give them multiple properties, labels or different names. The diversity has to be for each different class... in labels or properties (1+n labels, properties) or in different names.

问题 2 与问题 1 相关,因为我无法对条件关系进行建模或通过其标签或属性区分同一节点 (CLT1).我可能必须通过在关系中设置可查询的条件"来解决它.

Problem 2 relates to Problem 1 in that I can't model the conditional relationship or distinguish the same node (CLT1) by its labels or properties. I may have to resolve it by making the query-able "condition" in the relationship.

我有这个权利吗?我还有其他选择吗?

DO I have this right? Do I have any other options?

推荐答案

对于你的第一个问题,我会采用以关系为中心的方法,因为这种方法代表了从结果节点到疾病的信息推断.

For your first question, I'd take the relationship-centric approach as this kind of represents the inference of the information leading from your result-node to the disease.

在建模和查询方面也应该能很好地工作.

Should work pretty well in modeling and querying too.

对于你的第二个问题.这就是节点标签的用途,因为它们代表节点可以扮演的不同角色,每个角色都具有不同的相关属性和关系.

For your second question. That's what node-labels are for they represent different roles a node can play, each with different relevant properties and relationships.

所以你可以做 MATCH (p:Person {name:"Jose"}) 并区别对待 MATCH (d:Developer {name:"Jose"})代码>.即查看其他 props 和 rels.

So you could do MATCH (p:Person {name:"Jose"}) and treat it differently from MATCH (d:Developer {name:"Jose"}). I.e look at other props and rels.

这篇关于在 neo4j v.2 (cypher) 中建模条件关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:37