Search code examples
sparqlgremlin

A type of traversal (pattern match) in gremlin


Note: My background is in sparql, and i'm learning Property Graph and Gremlin. Just started the journey

There is one particular type of traversal that so far i am not seeing how to express very well.

The type of traversal is selecting a set of matching start node, based on how they connect to a path or a set of node along a path of multiple node.

Simple example would be:

Finding all the person that like a message that has been twitted by an Organization.

In sparql it would be something akin to

?p a Person .
?p likes ?msg .
?msg a Message .
?msg twitted_by ?Org .
?Org a Organization .

Can someone show me how to express this is Gremlin. And as i keep learning, maybe point me some tutorial that would help me grasp how to write this kind of traversal.


Solution

  • I'm, not familiar with SPARQL syntax, but from your description I think you looking for something like this:

    g.V().hasLabel("Person").where(
            out('likes').hasLabel('Message').
            out('twitted_by').hasLabel('Organization')
        )
    

    example: https://gremlify.com/ywp5cd33un

    I'd recommend you to learn Gremlin from Kevin Lawrence's book PRACTICAL GREMLIN