Removing duplicate Edges

587 views
Skip to first unread message

Dylan Millikin

unread,
Sep 28, 2016, 9:57:54 AM9/28/16
to gremli...@googlegroups.com
Hey guys,

I'm looking for a recipe to remove "duplicate" edges. "Duplicate" might not be the exact term but here's what I mean by duplicate: An edge with the same label, inV, and outV as another edge.

I would like to decide on an edge label and remove all edges that have that label and the same direction between the same vertices (except for one of those edges that we would consider as the "original").

I don't know where these edges may be, we should assume that I can't manually find them so the query would need to be graph wide.

I've given this a few runs but I just can't seem to figure out how to find duplicate in/out vertices (the kind that would be cleansed by dedup()). So if anyone knows how to do this it would push me in the right direction.

Any help would be greatly appreciated. 

Cheers.

Daniel Kuppitz

unread,
Sep 28, 2016, 5:32:42 PM9/28/16
to gremli...@googlegroups.com
Hey Dylan,

check this out:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]

gremlin> g.V(1).as("a").V(3).addE("created").from("a")
==>e[12][1-created->3]
gremlin> g.V(1).outE()
==>e[9][1-created->3]
==>e[12][1-created->3]
==>e[7][1-knows->2]
==>e[8][1-knows->4]

gremlin> g.V().as("ov").outE().as("e1").inV().as("iv").inE().
           where(neq("e1")).
           where(outV().as("ov")).as("e2").
           filter(select("e1","e2").by(label).where("e1", eq("e2"))).drop()

gremlin> g.V(1).outE()
==>e[9][1-created->3]
==>e[7][1-knows->2]
==>e[8][1-knows->4]


Cheers,
Daniel


--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAE0QJepO8ZyFSKtkj8U%2BxKL-BKg_6Dcu1ifpqxM1yB%3DkB3NNpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Dylan Millikin

unread,
Sep 30, 2016, 6:14:13 PM9/30/16
to gremli...@googlegroups.com
Awesome thanks a lot Daniel!

Reply all
Reply to author
Forward
0 new messages