create (bird:Class {name:'bird'})-[:isSubClassOf]->(animal:Class {name:'animal'})
create (animal)-[:hasOrgan {condition:'Exists (({x})-[:isInstanceOf]->(bird))'}]->(wing:organ {name:'wing'})
create (x:bird:instance {name:'pigeon_1'})-[:isInstanceOf]->(bird)
如何创建查询来读取条件表达式的值,并根据其值MATCH(bird:Class {name:'bird'})-[:isSubClassOf]->(animal:Class {name:'animal'})决定是否创建(pigeon_1)-[:hasOrgan]->(:wing)
我创建了以下查询,但得到了一个错误,我应该如何修复它?
MATCH (animal)-[hasOrgan:hasOrgan]->(wing:organ)
WHERE hasOrgan.condition IS NOT NULL
WITH x, hasOrgan, wing, hasOrgan.condition AS condition
CALL apoc.cypher.doIt('RETURN ' + condition + ' AS value', {x: x, wing: wing})
YIELD value
WITH x, hasOrgan, wing, value AS conditionValue
WHERE conditionValue
CREATE (x)-[:hasOrgan]->(wing)
1条答案
按热度按时间3ks5zfa01#
以下查询可能对您有用。它假设您首先更改数据模型,将非常复杂的关系模式
[:hasOrgan {condition:'Exists (({x})-[:isInstanceOf]->(bird))'}]
替换为简单得多的[:hasOrgan {ifClass: 'bird'}]
。查询执行此操作的顺序是:
1.找到每个具有
ifClass
属性的hasOrgan
关系以及关联的类cls
和器官organ
。1.找到每个
instance
的所有类(直接或间接)在类cls
中,如果它不属于hasOrgan.ifClass
指定的类,则过滤掉一个示例。1.使用
MERGE
创建hasOrgan
关系(如果不存在)。