Find one-step link between number of vertex

42 views

sitereg...@gmail.com

Dec 15, 2014, 11:14:31 PM12/15/14
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

Dec 16, 2014, 6:29:40 AM12/16/14
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.