我有一个具有功能的用户的gremlin图。图形的边缘从用户那里出来并输入要素。用户没有传入的边缘,要素也没有传出的边缘。每个用户顶点都有许多打出的边进入要素顶点。
I want to find the subset of female users who are connected to feature_a
and feature_b
vertices. I am using gremlinpython
and I know I can do some kind of set intersection in python with the code below. Is there a way in gremlin to achieve this?
q = '''g.V('feature_a').
inv().has('gender','Female')'''
res1 = client.submit(q).all().result()
q2 = '''g.V('feature_b').
inv().has('gender','Female')'''
res2 = client.submit(q2).all().result()
vs_in_common = set(res2).intersection(set(res1)))
What Michael posted works, but it's a full scan across all users in the graph (unless gender
is indexed, but this would cause other issues, sooner or later). You should rather do something like the following:
g.V().hasId('feature_a').
in().has('gender', 'Female').
filter(out().hasId('feature_b'))
Also, if possible, provide an edge label in the in
and out
steps.