Gremlin Query to get longest common subsequence for a given source from the Azure Cosmos graph

29 views Asked by At

lets assume I have got list of all longest common paths for given source say A using below query g.V().hasLabel('A').repeat(out()).until(__.not(out())).path().by('id')

Result: [ { "objects": [ "k", "B", "C" ] },

{ "objects": [ "A", "B", "E" ] },

{ "objects": [ "D", "B", "E" ] } ]

From above result im expecting B,E as longest common subsequence as this path is repeated for path{"A", "B", "E" } and path {"D", "B", "E"}

1

There are 1 answers

0
Kelvin Lawrence On

There is no simple way in Gremlin to take a set of paths results, analyze them, and return common patterns seen across all of the paths. The closest I can think of is to groupCount by all of the possible sub-parts of the path. If I can think of a clean way to do this in Gremlin I will update the answer, but my initial thinking on this one is that it will be much easier done in application code after the query has run.

If the backend implementation allows use of closures/lambdas, that might be an alternative. In general their use is discouraged and many of the TinkerPop implementations disallow them.