1

I'm building an application that sits on a graph data set, and nodes in this graph can be other smaller graphs, in wich the nodes can have connections to the main graph's nodes.

A (badly drawn, sorry :D ) ASCII art to compensate my (bad, sorry :D) english:

               //       \\BAR
              ||(x)---(y)||
              ||      /  ||\
              ||    (z)  ||\\
               \\    |  //  \\
              //     |       \\_________
             //      |                  \
            //       |             //    \           \\
FOO        //        |             ||(harry)---(terry)||
 //       \\         |             ||          /      ||WORLD
||(a)---(b)||        |            /||    (jerry)      ||
||  \      ||        |           // \\                //
||   (c)   ||       /  //      \\/
 \\   |   //       /  || HELLO ||
      \___________/    \\     //

Node x,y and z are nodes of the BAR graph, a,b and c of the FOO graph, same for harry ecc.. and the WORLD graph.

FOO, BAR, WORLD and HELLO are nodes of the main big Graph.

Inside this structure a node of FOO is connected to a node in BAR (c -> z) and, this is the tricky part) a node of WORLD is connected to BAR (harry -> BAR).

I know how to achieve this with Networkx in python, but how can I save this to a db?

I'm thinking of solutions myself but I want to know if there is a theory or some techniques for similar situations.

So far my solution (using neo4j) is label a b and c with the tag "FOO", and making a separate graph that connects FOO to BAR, ecc.. Am I in the right direction? Do you know some smarter solutions?

Thanks

[edit: corrected a name]

1 Answer 1

1

You did not label "J" in your diagram, so I will ignore it (and HELLO, whatever that is) in this answer.

[EDITED]

You just need a single node instance of each subgraph, and they can all have the label Subgraph. I'll name these nodes foo, bar, and world below.

(foo:Subgraph {name: "Foo"})
(bar:Subgraph {name: "Bar"})
(world:Subgraph {name: "World"})

Then you can indicate which nodes are members of which subgraph:

(foo)-[:MEMBER]->(a)
(foo)-[:MEMBER]->(b)
(foo)-[:MEMBER]->(c)

(bar)-[:MEMBER]->(x)
(bar)-[:MEMBER]->(y)
(bar)-[:MEMBER]->(z)

(world)-[:MEMBER]->(harry)
(world)-[:MEMBER]->(terry)
(world)-[:MEMBER]->(jerry)

And you can also have relationships that connect member nodes as wells as entire subgraphs:

(c)-[rel1]->(z)
(harry)-[rel2]->(bar)
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah sorry I changed J with HELLO but not in the text... - With this solution the labels do not become superfluous? I'm thinking of labeling my subgraphs nodes as Subgraph so I can query only the connections between subgraphs (MATCH (node1:Subgraph)-[:rel1]->(node2:Subgraph)).. Is this correct?
Yes, you are right. And if you still wanted to name each subgraph, you could just have a name property in each Subgraph instance. I will edit my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.