2

I'm new to gremlin and have been working on creating an ego network using Gremlin.

Ego-alter connections are pretty easy to find, but the problem lies in finding alter-alter connections. Is there a way to write a query which extracts all the alter-alter connections along with ego-alter connections in a n-radius ego network ?

enter image description here

For example in the Graph of the gods. 1-Radius ego network for 'jupiter' has ego-alter connections as 'Jupiter-neptune', 'Jupiter-pluto'. While the alter-alter connection is 'Neptune-Pluto'. How do I retrieve these connections.

Thanks in advance.

Shubham Yadav
  • 561
  • 7
  • 16

1 Answers1

1

This is my attempt for finding the 'alter-alter' connections

g.V().has('name', 'jupiter').as('ego').repeat(out()).times(1).emit()
.dedup().aggregate('alter')
.as('from').out()
.where(within('alter'))
.as('to').select('from', 'to').by('name').dedup()

The number inside the times step is your redius.

In addition I created the graph in gremlify, so you can play with this query:

https://gremlify.com/1p

gremlify
  • 121
  • 1
  • 5
  • 2
    Welcome to Stack Overflow! Excessive promotion of a specific product/resource may be perceived by the community as **spam**. Take a look at the [help], specially [What kind of behavior is expected of users?](//stackoverflow.com/help/behavior)'s last section: _Avoid overt self-promotion_. You might also be interested in [How to not be a spammer](//stackoverflow.com/help/promotion) and [How do I advertise on Stack Overflow?](//www.stackoverflowbusiness.com/advertising). – Machavity Feb 03 '20 at 19:17
  • 2
    You should add emit() after times(1) so that the loop outputs all the nodes. Currently it only outputs nodes from the last n-th hop. – Shubham Yadav Feb 04 '20 at 11:22
  • There is another bug which results in only alter-alter connections especially in 1-hop network, because it doesn't aggregate source vertex. To resolve this write 'emit()' before repeat step. – Shubham Yadav Feb 06 '20 at 07:04