Cypher : representing nested graphs?

206 Views Asked by At

How would you represent graph of graphs in Graph DB. F.e. mnemonically it may look like this :

((a)->(b))->(c)
((a)->(b))->((c)->(d))

In a sense (a)->(b) for (c) act as a single node, but is internally two linked nodes. And of course you should be able to nest them further.

Is there some graph structure that I can use to represent this.


  (a)<-[:1]-(ab)-[:2]->(b)
  (ab)<-[:1]-(abc)-[:2]->(c)

???


@bouteillebleu : second variant

 (a)-[:fst]->(ab)-[:snd]->(b)
 (ab)->(c)
1

There are 1 best solutions below

2
On

Probably the simplest and most concise way for a node to reference an entire subgraph of any size and complexity would be to store in that node a cypher property whose value is a Cypher query string that would produce the desired subgraph.

As an example, here's how you might represent the assertion that a specific subgraph1 contains a given subgraph2:

CREATE
  (subgraph1:Graph {cypher: 'MATCH p=(f:Foo)-[:HAS]->(:Bar) WHERE f.id = 123 RETURN p'}),
  (subgraph2:Graph {cypher: 'MATCH (f:Foo) WHERE f.id = 123 RETURN f'}),
  (subgraph1)-[:CONTAINS]->(subgraph2)

If the actual subgraph represented by subgraph1 consisted of several billion nodes and relationships, there may be no other practical way to represent the subgraph.