As a first introduction to Gremlin, I have been trying to understand
how to project a bipartite graph towards one of its nodesets.
Fortunately I have not found any explicit answer in the docs, so it is
been a good way to get used to the language, but on the other hand it
implies that I am not sure of the efficiency nor elegance of the
methods.
What I have come to, is the following. Sat we have the network of
users and checkins of foursquare, and we want to have a network of
"user similarity" by projecting out the places. If we want to start
from the surviving nodeset, I can do
g.V.filter{it.type=='user'}.as('a').out('was_at').in('was_at').as('b').select(['a','b']).groupCount()
{
it.name}.cap()
while if we want, as it is going to happen more usually -think of a
time interval in the initial filter- from the projected subset, I can
do
g.V.filter{it.type=='place'}.sideEffect{x=it}.in('was_at').as('a').transform{x}.in('was_at').as('b').select(['a','b']).groupCount()
{
it.name}.cap()
A first question is efficiency, albeit probably it is going also to
depend of the database implementation. Are these the faster recipes,
or can it be done in a better way?
Besides efficiency, another problem I see is that the projection can
not use the relative weight of the links and then it is only
implementing the "pure intersection". This is a more complex problem,
see for instance how many functions networkx implements...
http://networkx.lanl.gov/reference/algorithms.bipartite.html#module-networkx.algorithms.bipartite.projection
... and so I do not expect a simple pattern to work, but it should be
nice to discover that there is one :-)
And third issue is pipe-bility... At least the recipe output works
via REST interface, while a lot of table based solutions fail there.
But what about creating not a select but a virtual or fake edge
between nodes 'a' and 'b', so that further pipes could just believe
they are working with a real graph entity? Well, perhaps it is not a
good idea, as the fake edge is not going to be present in the in/out
edge lists of the nodes, and something is going to fail in the long
run. But I was intrigued about this possibility, can it be done?
Yours,
Alejandro Rivero