admin管理员组文章数量:1277516
I have a graph that where 'App' nodes connect either directly to other App nodes using a REQUIRES relationship, or via an intermediate Interface object. eg either:
(:App)-[:CONSUMES]->(:Interface)<-[:PROVIDES]-(:App)
or
(:App)-[:REQUIRES]->(:App)
I'm trying to do this using quantified paths to follow these relationships across multiple steps since that allows me to apply conditions (using a WHERE clause) to each step. But I'm having trouble expressing the fact that I want to allow each step between App nodes to be either of these alternatives.
I'm conceptually trying to do the following...
MATCH (a0:App {name: "origin"})
( (a1:App)-[c2:CONSUMES]->(i:Interface)<-[c3:PROVIDES]->(a2:App)
| // <- this isn't valid syntax
(a3:App)-[c4:REQUIRES]->(a4:App)
Where a1.name <> "some condition"
) {1,5}
RETURN ....
Any suggestions on how such alternatives can be described would be appreciated.
I have a graph that where 'App' nodes connect either directly to other App nodes using a REQUIRES relationship, or via an intermediate Interface object. eg either:
(:App)-[:CONSUMES]->(:Interface)<-[:PROVIDES]-(:App)
or
(:App)-[:REQUIRES]->(:App)
I'm trying to do this using quantified paths to follow these relationships across multiple steps since that allows me to apply conditions (using a WHERE clause) to each step. But I'm having trouble expressing the fact that I want to allow each step between App nodes to be either of these alternatives.
I'm conceptually trying to do the following...
MATCH (a0:App {name: "origin"})
( (a1:App)-[c2:CONSUMES]->(i:Interface)<-[c3:PROVIDES]->(a2:App)
| // <- this isn't valid syntax
(a3:App)-[c4:REQUIRES]->(a4:App)
Where a1.name <> "some condition"
) {1,5}
RETURN ....
Any suggestions on how such alternatives can be described would be appreciated.
Share Improve this question edited Feb 25 at 11:24 Charlotte Skardon 6,2802 gold badges33 silver badges42 bronze badges asked Feb 24 at 9:24 M LewisM Lewis 1611 silver badge6 bronze badges 1 |3 Answers
Reset to default 0This isn't possible in a single statement today. It is a feature that is being considered (and if so might actually get the syntax you proposed). For now, you would have to do a UNION between two QPP's.
MATCH (a0:App {name: "origin"})
( (a1:App)-[c2:CONSUMES]->(i:Interface)<-[c3:PROVIDES]->(a2:App)
Where a1.name <> "some condition"
) {1,5}
RETURN ....
UNION
MATCH (a0:App {name: "origin"})
(a3:App)-[c4:REQUIRES]->(a4:App)
Where a1.name <> "some condition"
) {1,5}
RETURN ....
You just need to make sure that the two RETURN statements returns the same things (the same columns)
The alternation syntax you're suggesting is not supported (yet). You could instead insert a relationship REQIURES_VIA_INTERFACE
like so:
MATCH (a:App)-[:CONSUMES]->(:Interface)<-[:PROVIDES]-(b:App)
WHERE NOT EXISTS { (a)-[:REQUIRES_VIA_INTERFACE]->(b) }
CREATE (a)-[:REQUIRES_VIA_INTERFACE]->(b)
Then your query above could become:
MATCH (a0:App {name: "origin"})
( (a1:App)-[c:REQUIRES|REQUIRES_VIA_INTERFACE]->(a2:App)
WHERE a1.name <> "some condition" ){1,5}
RETURN *
You can use the APOC procedure apoc.path.expandConfig instead.
For example, to meet your 2 stated conditions, and assuming you do not want any paths that contain an App
node whose name
is "some condition":
MATCH (a0:App {name: "origin"})
CALL apoc.path.expandConfig(a0, {
minLevel: 1,
maxLevel: 5,
sequence: 'App,CONSUMES>,Interface,<PROVIDES,App|App,REQUIRES>,App',
uniqueness: 'NODE_PATH'
}) YIELD path
WHERE ALL(a1 IN NODES(path) WHERE NOT a1:App OR a1.name <> "some condition")
RETURN path
In this example, the uniqueness value of 'NODE_PATH' is used to prevent any returned path from having cycles (where the same node appears multiple times). You may want to read the docs to see which value is appropriate for your use case.
本文标签: How to specify alternative steps using quantified paths in CypherNeo4jStack Overflow
版权声明:本文标题:How to specify alternative steps using quantified paths in CypherNeo4j? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741282653a2370096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
App
nodes to pass the <> test, or justa1
, or justa1
anda3
? Please update your question. – cybersam Commented Feb 24 at 22:20