Find one-step link between number of vertex

42 views
Skip to first unread message

sitereg...@gmail.com

unread,
Dec 15, 2014, 11:14:31 PM12/15/14
to gremli...@googlegroups.com
Hi.
I'm really new to Gremlin and graph database world and can't figure out how to achieve what I want to do.
I have some number of vertex (5 for example), then I need to find vertex with direct links to all these 5 vertex.
If I don't have vertex with connections to all vertex - I need to try to find vertex with 4 direct links to some vertex in my initial list.
And so on until I've got result.
I don't mind to run query again on each iteration.
Is this possible to achieve this with Gremlin?

Thanks a lot,
Sergey

Daniel Kuppitz

unread,
Dec 16, 2014, 6:29:40 AM12/16/14
to gremli...@googlegroups.com
Hi Sergey,

let's pick the classic toy graph for this example. Let the input vertices be v2, v3 and v4, and now find those vertices, that have the most outgoing edges to the aforementioned vertices:

gremlin> g = TinkerFactory.createClassic()
==>tinkergraph[vertices:6 edges:6]
gremlin> input = g.V(2,3,4).toList()
==>v[2]
==>v[3]
==>v[4]
gremlin> sm = g.of().inject(input).unfold().in().groupCount().next().sort { -it.getValue() }
==>v[1]=3
==>v[4]=1
==>v[6]=1
gremlin> m = sm.iterator().next().getValue()
==>3
gremlin> result = sm.grep { it.getValue() == m }*.getKey()
==>v[1]

And if you're using TP2:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> input = g.v(2,3,4).toList()
==>v[2]
==>v[3]
==>v[4]
gremlin> sm = input._().in().groupCount().cap().next().sort { -it.getValue() }
==>v[1]=3
==>v[4]=1
==>v[6]=1
gremlin> m = sm.iterator().next().getValue()
==>3
gremlin> result = sm.grep { it.getValue() == m }*.getKey()
==>v[1]

As you can see, there's only one vertex that has outgoing edges to all of the 3 vertices (v1), hence this is your result.

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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/b5c9d467-a84c-4ab5-9f61-7885fabca8c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages