Deleting X nodes when there is no incoming Y nodes to them

Hello, In my case, a team has many Member and each member works only for one company. a company can also works for another company. I want to delete all companies that no member of team works for them. In the following example company W and Z must be deleted but company Y should not. because member A works for X and X works for Y.
g.addV('team').property('name', 'backend').as('t').
addV('person').property('name', 'A').as('a').
addV('company').property('name', 'X').as('x').
addV('company').property('name', 'Y').as('y').
addV('company').property('name', 'Z').as('z').
addV('company').property('name', 'W').as('w').
addE('member').from('t').to('a').
addE('cooperate').from('t').to('y').
addE('cooperate').from('t').to('x').
addE('cooperate').from('t').to('z').
addE('cooperate').from('t').to('w').
addE('work').from('a').to('x').
addE('work').from('x').to('y').
addE('work').from('z').to('y').
addE('work').from('w').to('z').
next()
g.addV('team').property('name', 'backend').as('t').
addV('person').property('name', 'A').as('a').
addV('company').property('name', 'X').as('x').
addV('company').property('name', 'Y').as('y').
addV('company').property('name', 'Z').as('z').
addV('company').property('name', 'W').as('w').
addE('member').from('t').to('a').
addE('cooperate').from('t').to('y').
addE('cooperate').from('t').to('x').
addE('cooperate').from('t').to('z').
addE('cooperate').from('t').to('w').
addE('work').from('a').to('x').
addE('work').from('x').to('y').
addE('work').from('z').to('y').
addE('work').from('w').to('z').
next()
I wrote following query (and tried many other queries) but It delete all companies that does not have any direct member.
g.V().has('team', 'name', 'backend').
outE("cooperate").inV().not_(__.inE("work")).emit().repeat(__.out()).times(3).
dedup().fold().coalesce(__.unfold().drop()).toList()
g.V().has('team', 'name', 'backend').
outE("cooperate").inV().not_(__.inE("work")).emit().repeat(__.out()).times(3).
dedup().fold().coalesce(__.unfold().drop()).toList()
3 is the maximum depth of companies that can work with other companies. I really appreciate your help
1 Reply
Flynnt
Flynnt2y ago
Hello, you can try something like : //select the team g.V().has('team','name','backend').as("team") //select the team's members .out("member") //select the companies that the members work for (and company of company...) .repeat(out("work")).emit().times(3) //aggregate that .aggregate("worked") //limit(1) to return to one traverser, select the team to restart with .limit(1).select("team") //go to the cooperating companies out("cooperate").hasLabel("company") // collect all the compagnies chained 3 times .emit().repeat(out("work")).times(3) //deduplicate (always in case of..) .dedup() //remove the comagnies thats your teams members works for and for .where(without("worked")) //and drop ! .drop() Tell me if it works for you
Want results from more Discord servers?
Add your server