Search code examples
graphgremlintinkerpop3

Gremlin relationship recommendations


I am trying to identify missing relationships in a graph and provide recommendations to add a user to group since his peers are in the same group. Example: Manager dave of IT has members with relationship to group. I would like to find all vertex that are sharing the same organization or manager but are not in that group.

script example:

 g.addV('person').property('name','dave').as('d').
 addV('person').property('name','rick').as('r').
 addV('person').property('name','mavis').as('m').
 addV('person').property('name','larry').as('l').
 addE('manages').from('d').to('r').
 addE('manages').from('d').to('m').
 addE('manages').from('d').to('l').
 addV('group').property('name','IT').as('IT').
 addE('isIn').from('d').to('IT').
 addE('isIn').from('r').to('IT').iterate()

What is the correct way to do this?


Solution

  • If you want to identify the missing relationships you can do something like this:

    g.V().hasLabel('group').as('group').
      in('isIn').where(outE('manages')).
      project('group name', 'manager', 'not in group').
        by(select('group').
          values('name')).by('name').
        by(out('manages').not(where(out('isIn').
              where(eq('group')))).
          values('name').fold())
    

    *I assumed each group has exactly one manager.

    example: https://gremlify.com/7i