mpollmeier / gremlin-scala

[unmaintained] Scala wrapper for Apache TinkerPop 3 Graph DSL
Apache License 2.0
481 stars 75 forks source link

Please add a match step example #63

Closed tacone closed 9 years ago

tacone commented 9 years ago

Hello, could you add an example on how to perform the match-select pattern with gremilin scala?

This is an example from the Tinkerpop documentation:

gremlin> g.V().match('a',
            __.as('a').out('created').as('b'),
            __.as('b').has('name', 'lop'),
            __.as('b').in('created').as('c'),
            __.as('c').has('age', 29)).
          select('a', 'c').by('name')

Being a total newcomer I tried to invoke the match step on a GremlinScala class, but seems to me it's not implemented yet. Then I tried to invoke it directly on the graph object. This is the code I have right now:

    val graph = TinkerGraph.open()
    var gs = GremlinScala(graph)
    val vertex = gs.addVertex("hello")
    var vertex2 = gs.addVertex("world")
    vertex.addEdge("followed_by", vertex2, Map())

    val result = graph.V.outE().`match`(
      "a",
      __.as("a").inV().as("b") // what to put here ?
    ) // .....

Which does not seem to work. What should I substitute to __ to have the code compile?

Perhaps a little example in the readme would help many others :)

tacone commented 9 years ago

Hello, after much digging I found a solution inside the Tinkerpop 3.0.0M6 documentation (yes, the previous version).

    val graph = TinkerGraph.open()
    var gs = GremlinScala(graph)
    val vertex = gs.addVertex("hello")
    var vertex2 = gs.addVertex("world")
    vertex.addEdge("followed_by", vertex2, Map())

    val result = graph.V.outE().`match`(
      "a",
      graph.of().as("a").inV().as("b")
    ).select()

Hope it will be useful for somebody else.

Bye!

mpollmeier commented 9 years ago

Thanks for sharing. I will provide a sample usage for all steps, however at the moment the API is moving too much and my time is limited.