Reputation: 3612
I am using python to run my gremlin queries, for which I am still getting used to / learning. Let's say I have vertex labels A
and B
, and there can be an edge from A
to B
called abEdge
. I can find B
vertices that have such edges from a particular A
vertex with:
g.V()\
.hasLabel("A")\
.has("uid", uid)\ # uid is from a variable
.outE("abEdge")\
.inV()\
.toList()
But how would I go about finding B
vertices that have no such edges from a particular A
vertex?
My instinct is to try the following:
# Find B edges without an incoming edge from a particular A vertex
gremlin.V()\
.hasLabel("B")\
.where(__.not_(inE("abEdge").from_(
V()\
.hasLabel("A")\
.has("uid", uid)
)))\
.next()
And that results in a bad query (Not sure where yet), I'm still reading up on Gremlin, but I am also under time contraints so here I am asking. If anyone can help but just using groovy
syntax that is fine too as it's not too bad to convert between the two.
Any explanations would be helpful too as I am still learning this technology.
I guess if this were a real-life question, and related to this website. We could ask (A=Person
, B=Programming-Language
, and abEdge=knows
):
Which programming languages does particular person
A
not know?
Upvotes: 2
Views: 463
Reputation: 46206
It looks like you almost had the answer:
g.V().hasLabel("B"). \
filter(__.not_(__.in_('abEdge').has("A","uid",uid))). \
toList()
I prefer filter()
when using just a single Traversal
argument, but I think you could replace with where()
if you liked.
Upvotes: 2