4

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?

Jautomator
  • 149
  • 1
  • 9
  • 2
    closed for "debugging details" doesn't make sense imo - the question is pretty straightforward to those who are are familiar with graphs and gremlin. – stephen mallette Apr 23 '20 at 12:37

1 Answers1

1

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

noam621
  • 2,766
  • 1
  • 16
  • 26
  • Thanks for this, can we do it in a simple way like : g.V().has('person','name','dave').outE('manages').not(where(out('isIn').where(g.V().has('group','name','IT')) as I am not experienced in projections – Jautomator Apr 22 '20 at 13:16
  • This will work only if you already know all the groups names and managers, and you will query one group at the time. my solution will give you all the groups and mismatches in one query – noam621 Apr 22 '20 at 13:24
  • @user965992 also you need to switch the `outE` to `out`: `g.V().has('person', 'name', 'dave'). out('manages').not(where(out('isIn'). where(V().has('group', 'name', 'IT'))))` – noam621 Apr 22 '20 at 13:30
  • how would you do approach a recommendation engine? to fix missing relationships or identify similar ones – Jautomator Apr 22 '20 at 13:35
  • @user965992 If I understood what you are asking... Depending on how sensitive this data. If not too sensitive I would fix the missing relationships without identifying them first – noam621 Apr 22 '20 at 14:39
  • I need just last example would help, how would you find groups where people are in but not their direct manager (deviations/DIFF like) so if dave the manager is in IT and one of his direct reports is in HR this would be displayed – Jautomator Apr 22 '20 at 15:24
  • @user965992 The query In the answer will give you all the people without a group and also the people in the wrong group. If you want just the wrong group you can move the `not` step from before the first `where` to before the second – noam621 Apr 22 '20 at 15:31
  • anyway to add group name if the wrong group to the gremlify? I added HR group, – Jautomator Apr 22 '20 at 15:38
  • sorry if my question is not clear by recommendation I meant , I am able to show common groups and also different groups, based on my understanding of this https://tinkerpop.apache.org/docs/current/recipes/#recommendation – Jautomator Apr 22 '20 at 15:44
  • `g.V().has('person','name','dave').out('manages').as('director').out('isIn').in('isIn').out('isIn').values('name')` something like this – Jautomator Apr 22 '20 at 15:49
  • yes this is what I am looking for I wonder about execution time? for big data – Jautomator Apr 22 '20 at 15:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212276/discussion-between-noam621-and-user965992). – noam621 Apr 22 '20 at 15:54