Z Yk
Z Yk

Reputation: 1

Gremlin - can I attach a property to a path?

So my question is, after traversal, I have got several paths, a path looks like node1-edge1-node2-edge2-node3, now I want to attach a property called 'frequency' to this specific path, and its values equals edge1's 'frequency' property value, how should I do it? Or it cannot be done using Gremlin, and I have to use Java?

I tried something like this:

    g.E().has('length', gt(1)).as('edge1')
    .outV().as('node1')
    .select('edge1')
    .inV().as('node2')
    .outE().as('edge2').where('edge1', eq('edge2').by('id'))
    .inV().as('node3')
    .path()

Upvotes: 0

Views: 25

Answers (1)

Taylor Riggan
Taylor Riggan

Reputation: 2769

"Paths" are constructed at query time. There's no concept of storing a path and attaching a property to it. However, I think what you're asking for is the ability to have a 'frequency' attribute in the result set?

If that is the case, you can try adding the following to the end of the query:

    groupCount().unfold().
    project('path','frequency').
        by(select(keys)).
        by(select(values))

That will count the number of times a path appears and return a map of path and frequency of each path.

Upvotes: 0

Related Questions