my schema is as follows: A "buy" from B, C, D, E; A "know" F; F "buy" from B, G, H.
how to get B(the common seller shared by anyone the buyer knows) only from A(a buyer) in Gremlin?
my schema is as follows: A "buy" from B, C, D, E; A "know" F; F "buy" from B, G, H.
how to get B(the common seller shared by anyone the buyer knows) only from A(a buyer) in Gremlin?
When asking question about Gremlin it is best to include some sample data in the form of a script as part of your question as follows:
g.addV().property(id, 'A').as('a').
addV().property(id, 'B').as('b').
addV().property(id, 'C').as('c').
addV().property(id, 'D').as('d').
addV().property(id, 'E').as('e').
addV().property(id, 'F').as('f').
addV().property(id, 'G').as('g').
addV().property(id, 'H').as('h').
addE('buysFrom').from('a').to('b').
addE('buysFrom').from('a').to('c').
addE('buysFrom').from('a').to('d').
addE('buysFrom').from('a').to('e').
addE('knows').from('a').to('f').
addE('buysFrom').from('f').to('b').
addE('buysFrom').from('f').to('g').
addE('buysFrom').from('f').to('h').iterate()
I suppose you could approach this a few ways, but the following is the way that came immediately to my mind:
gremlin> g.V('A').as('a').out('buysFrom').
......1> where(__.in('buysFrom').both('knows').as('a'))
==>v[B]
The first line finds "A" then finds who they buy from. The second line filters those people "A" bought from by traversing back along the "buysFrom" edges to find the people who know "A".
The above code is Groovy syntax, but I see you tagged with "gremlinpython" so it only requires some minor adjustments to work in Python:
g.V('A').as_('a').out('buysFrom').
where(__.in_('buysFrom').both('knows').as_('a'))