toco moco
toco moco

Reputation: 13

Constraints for graph models

I have four possible chains that can be formed with 6 different chain links:

 G0 -> G1 -> G2
 E0 -> E1 -> E2
 G0 -> E1 -> G2
 E0 -> G1 -> G2

Now I want to express this four chains using a graph model which would look like the following picture:

enter image description here

If I use a graph query language to ask eg give me all paths having G0 as first vertex and E2 as last vertex, I would get a path G0 -> E1 -> E2 which is not a valid path or chain out of the four...

So my question is is there a possibility to express such constraints such that I only receive "valid" paths?

Upvotes: 0

Views: 94

Answers (2)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

I don't understand why you say that the path G0 -> E1 -> E2 is not valid. By your definition, it should be the only valid path. This query should return the desired result:

g.V(G0).               /* G0 as first vertex */
  repeat(out()).
    until(__.is(E2)).  /* E2 as last vertex  */
  path()               /* all paths          */

Upvotes: 2

Tezra
Tezra

Reputation: 8833

In the motto of the simplest solution is usually the best, I would do this.

1) For each chain, create a node to represent that chain.

2) Create a relation from that node to each node in the chain, and add an index property on the relationship. (You may use a first/end relationship for the first and last element, or add that as a property for easier Cyphers)

3) Run Cyphers on your "chain" nodes instead.

Any other way of doing this will make the Cypher either overly complex, or risk corrupting your original data to the point where it is barley usable. This is the easiest and most flexible setup.

Upvotes: 0

Related Questions