Python, bulbs, resxter .Simplest way to check existing edge to prevent duplicate edges between a set of vertices

47 views
Skip to first unread message

Jinal Kothari

unread,
Mar 26, 2015, 5:29:40 AM3/26/15
to gremli...@googlegroups.com

This question is also on stackoverflow.

I am writing python scripts to extract data from multiple sources and put it in a graph in certain structure.

I am using bulbs models for all the data. I have models for all relevant node types and relationships. My edge models have not additional properties except name.

As it is in development I run the same script multiple times. I use get_or_create to prevent duplicate nodes but edges do not have that method. I do not have the object for existing edge since it was created in a previous run of the script.

I saw several question talking about similar things with answers from espeed like this, but I could not find a satisfactory answer for my specific issue.

What would be the simplest code for this method:

def check_edge(g, parent_v, child_v, rel_label):

Stephen Mallette

unread,
Mar 26, 2015, 6:11:49 AM3/26/15
to gremli...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e25dfcdc-7b39-4654-aee9-badf499a1be2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jinal Kothari

unread,
Mar 26, 2015, 6:58:10 AM3/26/15
to gremli...@googlegroups.com
Hey stephen, thanks for the quick answer! The code you mentioned, is it meant to be Gremlin? Bulbs does not seem to have a retain() method. I can manage to run gremlin strings via bulbs.

Stephen Mallette

unread,
Mar 26, 2015, 8:19:24 AM3/26/15
to gremli...@googlegroups.com
Yes it is gremlin code.

Jinal Kothari

unread,
Mar 27, 2015, 5:07:29 AM3/27/15
to gremli...@googlegroups.com
I am using the following function defined in my gremlin.groovy script file.

def is_connected(parent, child, edge_label) {
    return g.v(parent).out(edge_label).retain([g.v(child)]).hasNext()
}

To use from python, I do this:

g.scripts.update('gremlin_scripts/gremlin.groovy')
script = g.scripts.get('gremlin:is_connected')
params = dict(parent=parent_node.eid, child=menu_item_v.eid, edge_label='has_sub_menu_item')
response = g.gremlin.execute(script, params)
I can't quite figure out how to get the bool result into python. I've also tried the g.gremlin.query(script, param)

Any ideas?
Reply all
Reply to author
Forward
0 new messages