Here is my graph:
Here is graph building code:
<code> Vertex a = g.addV("Person")
.property(T.id, "A")
.next();
Vertex b = g.addV("Person")
.property(T.id, "B")
.next();
Vertex c = g.addV("Person")
.property(T.id, "C")
.next();
Vertex d = g.addV("Person")
.property(T.id, "D")
.next();
Vertex e = g.addV("Person")
.property(T.id, "E")
.next();
Vertex r1 = g.addV("Right")
.property(T.id, "1")
.property(VertexProperty.Cardinality.set, "types", 1)
.property(VertexProperty.Cardinality.set, "types", 2)
.next();
Vertex r2 = g.addV("Right")
.property(T.id, "2")
.property(VertexProperty.Cardinality.set, "types", 2)
.property(VertexProperty.Cardinality.set, "types", 3)
.next();
Vertex r3 = g.addV("Right")
.property(T.id, "3")
.property(VertexProperty.Cardinality.set, "types", 4)
.property(VertexProperty.Cardinality.set, "types", 5)
.next();
Vertex r4 = g.addV("Right")
.property(VertexProperty.Cardinality.set, "types", 3)
.property(T.id, "4")
.next();
g.addE("receives").from(r1).to(a)
.property(T.id, "a")
.next();
g.addE("receives").from(b).to(r1)
.property(T.id, "b")
.next();
g.addE("receives").from(r2).to(b)
.property(T.id, "c")
.next();
g.addE("receives").from(r3).to(b)
.property(T.id, "d")
.next();
g.addE("receives").from(d).to(r3)
.property(T.id, "e")
.next();
g.addE("receives").from(c).to(r2)
.property(T.id, "f")
.next();
g.addE("receives").from(r4).to(c)
.property(T.id, "g")
.next();
g.addE("receives").from(e).to(r4)
.property(T.id, "h")
.next();
</code>
<code> Vertex a = g.addV("Person")
.property(T.id, "A")
.next();
Vertex b = g.addV("Person")
.property(T.id, "B")
.next();
Vertex c = g.addV("Person")
.property(T.id, "C")
.next();
Vertex d = g.addV("Person")
.property(T.id, "D")
.next();
Vertex e = g.addV("Person")
.property(T.id, "E")
.next();
Vertex r1 = g.addV("Right")
.property(T.id, "1")
.property(VertexProperty.Cardinality.set, "types", 1)
.property(VertexProperty.Cardinality.set, "types", 2)
.next();
Vertex r2 = g.addV("Right")
.property(T.id, "2")
.property(VertexProperty.Cardinality.set, "types", 2)
.property(VertexProperty.Cardinality.set, "types", 3)
.next();
Vertex r3 = g.addV("Right")
.property(T.id, "3")
.property(VertexProperty.Cardinality.set, "types", 4)
.property(VertexProperty.Cardinality.set, "types", 5)
.next();
Vertex r4 = g.addV("Right")
.property(VertexProperty.Cardinality.set, "types", 3)
.property(T.id, "4")
.next();
g.addE("receives").from(r1).to(a)
.property(T.id, "a")
.next();
g.addE("receives").from(b).to(r1)
.property(T.id, "b")
.next();
g.addE("receives").from(r2).to(b)
.property(T.id, "c")
.next();
g.addE("receives").from(r3).to(b)
.property(T.id, "d")
.next();
g.addE("receives").from(d).to(r3)
.property(T.id, "e")
.next();
g.addE("receives").from(c).to(r2)
.property(T.id, "f")
.next();
g.addE("receives").from(r4).to(c)
.property(T.id, "g")
.next();
g.addE("receives").from(e).to(r4)
.property(T.id, "h")
.next();
</code>
Vertex a = g.addV("Person")
.property(T.id, "A")
.next();
Vertex b = g.addV("Person")
.property(T.id, "B")
.next();
Vertex c = g.addV("Person")
.property(T.id, "C")
.next();
Vertex d = g.addV("Person")
.property(T.id, "D")
.next();
Vertex e = g.addV("Person")
.property(T.id, "E")
.next();
Vertex r1 = g.addV("Right")
.property(T.id, "1")
.property(VertexProperty.Cardinality.set, "types", 1)
.property(VertexProperty.Cardinality.set, "types", 2)
.next();
Vertex r2 = g.addV("Right")
.property(T.id, "2")
.property(VertexProperty.Cardinality.set, "types", 2)
.property(VertexProperty.Cardinality.set, "types", 3)
.next();
Vertex r3 = g.addV("Right")
.property(T.id, "3")
.property(VertexProperty.Cardinality.set, "types", 4)
.property(VertexProperty.Cardinality.set, "types", 5)
.next();
Vertex r4 = g.addV("Right")
.property(VertexProperty.Cardinality.set, "types", 3)
.property(T.id, "4")
.next();
g.addE("receives").from(r1).to(a)
.property(T.id, "a")
.next();
g.addE("receives").from(b).to(r1)
.property(T.id, "b")
.next();
g.addE("receives").from(r2).to(b)
.property(T.id, "c")
.next();
g.addE("receives").from(r3).to(b)
.property(T.id, "d")
.next();
g.addE("receives").from(d).to(r3)
.property(T.id, "e")
.next();
g.addE("receives").from(c).to(r2)
.property(T.id, "f")
.next();
g.addE("receives").from(r4).to(c)
.property(T.id, "g")
.next();
g.addE("receives").from(e).to(r4)
.property(T.id, "h")
.next();
My requirement is to traverse the graph from A to E, checking the types property of Right vertices for intersections along the way – if the types intersect with the types from last step then select the edge for traversal, otherwise stop ignoring the Right where the types do not intersect.
Here is what I tried so far:
<code>g.V("A")
.repeat(
inE("receives").outV().as("lastRight").inE("receives").outV()
.inE("receives").outV().as("thisRight").inE("receives").outV()
.simplePath()
)
.until(or(
inE().hasLabel("receives").count().is(0),
loops().is(10)
))
.path()
.toList();
</code>
<code>g.V("A")
.repeat(
inE("receives").outV().as("lastRight").inE("receives").outV()
.inE("receives").outV().as("thisRight").inE("receives").outV()
.simplePath()
)
.until(or(
inE().hasLabel("receives").count().is(0),
loops().is(10)
))
.path()
.toList();
</code>
g.V("A")
.repeat(
inE("receives").outV().as("lastRight").inE("receives").outV()
.inE("receives").outV().as("thisRight").inE("receives").outV()
.simplePath()
)
.until(or(
inE().hasLabel("receives").count().is(0),
loops().is(10)
))
.path()
.toList();
There are 2 problems with this query:
- It does not do the filtering using intersections between one Right and another along the Path
- It its current version – without the filtering using intersections – it should discover 2 paths, one from A – D and one from A to E – it discovers only one A – D. If I simplify the traversal query in the repeat statement, it does find 2 but I need to keep it complex to get a reference to the last Right vertex traversed along the path so I can reason about its types…
Can I achieve such dynamic, step-scoped filtering using intersections with Gremlin in Neptune?