Gremlin each/filter syntax help

420 views
Skip to first unread message

kantube

unread,
Feb 3, 2012, 2:55:13 PM2/3/12
to ne...@googlegroups.com
i have

[1, 2, 3, 4].each{g.addEdge(g.v(it), g.v(55), 'Category') }

which works but would like to filter the ids in the array to verify that they have a NodeType property equal to 'Category'

thanks for the help.

James Thornton

unread,
Feb 4, 2012, 3:48:22 AM2/4/12
to ne...@googlegroups.com
You can do this...

g.v(1,2,3,4).filter{it.nodeType == 'Category'}.each{ g.addEdge(it, g.v(55), 'Category') }

...or...

Use Groovy's collect method to convert the list of IDs to a list of vertices, and then use Gremlin's Identity pipe to convert the list into a pipe Gremlin can use...

start = [1,2,3,4].collect{ g.v(it) }
categories = start._().filter{ it.nodeType == 'Category' }
categories.each{ g.addEdge(it, g.v(55), 'Category') }

...or as a one liner...

[1,2,3,4].collect{ g.v(it) }._().filter{it.nodeType == 'Category'}.each{ g.addEdge(it, g.v(55), 'Category') }

- James

kantube

unread,
Feb 5, 2012, 11:28:55 AM2/5/12
to ne...@googlegroups.com
what version are you able to do

g.v(1,2,3,4).filter{it.nodeType == 'Category'}

when i do this i receive and error  "No signature of method: ..."

i am using Neo4j1.5GA

Peter Neubauer

unread,
Feb 5, 2012, 11:30:03 AM2/5/12
to ne...@googlegroups.com
Uh,
that is Gremlin 1.4, packaged in Neo4j 1.6 I think.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Marko Rodriguez

unread,
Feb 5, 2012, 11:32:41 AM2/5/12
to ne...@googlegroups.com
For Neo4j 1.5GA, I believe that is running Gremlin 1.3. Thus, you need to do this:

g.v(1,2,3,4)._().filter{it.nodeType == 'Category'}

Also, note that this is faster:

g.v(1,2,3,4)._().filter{it.getProperty('nodeType') == 'Category'}


Good luck,
Marko.
Reply all
Reply to author
Forward
0 new messages