How to find the edges of a node that have a weight of x or greater?
I have a graph with nodes that are connected to one another, and I have weights on the edges that connect these nodes.
On this query g.V().has("person", "name", "A").out("is friends with").values("name").to_list() returns the names of people that person "A" has the relation "is friends with". But I would like to filter by the weight value. Person A has a weight of 0.9 with Person B, and a weight of 0.7 with Person C. I would like to only get back the people person A has an edge with a weight of greater than 0.8, how can I do that? I am using gremlin-python. I have tried g.V().has("person", "name", "A").out("is friends with").has("weight", gte(0.8)) but I get an error saying NameError: name "gte" is not defined. Did you mean: 'g'?
Solution:Jump to solution
g.V().has("person", "name", "A").out(...
returns Vertices
to get edges need to use outE()
something like
a_friends = g.V().has("person", "name", "A").outE("is friends with").has("weight", P.gt(0.75)).inV().to_list()
...4 Replies
Try P.gte instead, with the correct import from the gremlin-python library, that should do it
Oh yeah, I also tried that, and for some reason, it didn't work. My query was as follows:
And it returned an empty list even though I have that person C has a weight of 0.9 with person A
Also btw, I am assuming the way I am setting weights for the edges is correct:
Solution
g.V().has("person", "name", "A").out(...
returns Vertices
to get edges need to use outE()
something like
a_friends = g.V().has("person", "name", "A").outE("is friends with").has("weight", P.gt(0.75)).inV().to_list()
Thank you, this helped me fix my problem 🙂