split string

35 views
Skip to first unread message

Dennis D

unread,
Jun 15, 2018, 9:48:51 AM6/15/18
to Gremlin-users
Hi,
I'm new to Gremlin, using the console so far.
The nodes of my graph have names that represent file system paths, like "a/b/c".
I would like to add an additional property to each node that represents just the last part, "c" in case of the above example.
Can I use string manipulation like split('/')?
Thanks,
Dennis.

Robert Dale

unread,
Jun 15, 2018, 11:39:37 AM6/15/18
to gremli...@googlegroups.com

You would have to use a lambda to do it in a traversal. 

# add a test node
g.addV().property('name','a/b/c')

# create new property from name
g.V().property('leaf', __.values('name').map({it.get().split('/').last()}))

# show result
g.V().has('name','a/b/c').valueMap(true)
==>[id:1,label:vertex,name:[a/b/c],leaf:[c]]


Robert Dale


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/c5434d23-fabd-4b65-b0c6-42c10f00c871%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dennis D

unread,
Jun 19, 2018, 9:54:42 AM6/19/18
to Gremlin-users
Thanks a lot. This works for me.
A related question: I would like to get a list of all nodes whose 'name' property contains a certain character (say "~").
(I tried a lot of queries, but none works.)

Daniel Kuppitz

unread,
Jun 19, 2018, 10:49:05 AM6/19/18
to gremli...@googlegroups.com
The same thing, you'll need a lambda.

If it's guaranteed that all vertices have a name property:

g.V().filter {it.get().value("name").contains("~")}

Otherwise:

g.V().has("name").filter {it.get().value("name").contains("~")}  // or
g.V().filter {p = it.get().property("name") ; p.isPresent() && p.value().contains("~")}

Cheers,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/b41afa76-273f-474e-954c-3d42a95b3689%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages