TinkerPop 3 Filtering vertices on property value using a regex

2,447 views
Skip to first unread message

Robert Saccone

unread,
Feb 8, 2016, 4:44:19 PM2/8/16
to Gremlin-users
Hello,

I am currently moving my code base that was written to TinkerPop 2 to TinkerPop 3.  My code is written in Java.  Under TinkerPop 2 I had a graph query that was filtering vertices to only return those that a had a property whose value matched a regex.  A snipped of that code is as follows:


graphQuery.has(keyName, Text.REGEX, ".*string.*)



My question is under the new traversal APIs how would I do accomplish the same thing?


Thanks,

Rob Saccone

Jason Plurad

unread,
Feb 9, 2016, 12:44:48 PM2/9/16
to Gremlin-users
Hi Rob,

Have you checked out the text predicates in Titan 1.0.0?

http://s3.thinkaurelius.com/docs/titan/1.0.0/search-predicates.html#_text_predicate

-- Jason

Robert Saccone

unread,
Feb 9, 2016, 2:20:12 PM2/9/16
to Gremlin-users
Hi Jason,

That looks like it is what I want.  However I am doing this from Java and near as I can tell I probably want to use this method 

default GraphTraversal<S,E> has(String propertyKey,
                                P<?> predicate)

which is part of the GraphTraversal interface.  What I am missing is the class definitions that are the equivalent to the textContains or the textContainsRegex that I saw in the link you gave me.

Any pointers to those?

Thanks,
Rob

Jason Plurad

unread,
Feb 9, 2016, 2:27:54 PM2/9/16
to Gremlin-users

--
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/3081a6b7-9998-4ca7-a729-6ad2108f2216%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Robert Saccone

unread,
Feb 9, 2016, 3:57:50 PM2/9/16
to Gremlin-users
Hi Jason,

Thanks.  I was looking in Tinkerpop.  Didn't realize it was something specific to Titan.  I do have another query to traversal issue.  Original querying had the ability to check if a the value of a property was in a range as in below.  arg1 and arg2 where longs.  Would you know what the equivalent is under the new traversal infrastructure?

_graphQuery.interval(arg0, arg1, arg2);


Thanks,

Rob

Jason Plurad

unread,
Feb 9, 2016, 9:52:16 PM2/9/16
to Gremlin-users
Hi Rob,

Yeah, the Text and Geo predicates are Titan-specific. I think there's a JIRA about bringing some of those into core TinkerPop.

The Titan vertex-centric index doc was updated for the interval() query you asked about:

h = g.V().has('name', 'hercules').next()
g
.V(h).outE('battled').has('time', inside(10, 20)).inV()

inside() is defined in org.apache.tinkerpop.gremlin.process.traversal.P, as are a bunch of other useful predicates.

-- Jason

Robert Saccone

unread,
Feb 10, 2016, 3:23:54 PM2/10/16
to Gremlin-users
Thanks!  This is very helpful.

SathishKumar Alwar

unread,
Feb 11, 2016, 8:29:55 AM2/11/16
to Gremlin-users
Hi,
I also have a similar requirement to find/list vertices that matches part of the key's value.

I am using Titan 1.0 + Tinkerpop 3.

I came up with following code to pull vertices matching a value partially.

GraphTraversalSource tv = graph.traversal();
tv.V().has("label","test").has("dName", Text.textRegex(".*Test_NG.*")).order().by(orderByKey,sortOrder).toList().iterator();

Although i have a vertex which has "dName" as key and "Test_NGOTD" as value. However i am able to pull vertices if I use titan API
graph.query().has(indexKey, Text.REGEX,value+".*").vertices().iterator()

The key (dName) i am trying to search is not indexed. This is for your kind information.

Thanks and Regards
A.SathishKumar 

Robert Saccone

unread,
Feb 16, 2016, 10:41:20 AM2/16/16
to Gremlin-users
Hi Jason,

I tried using the Text.textContainsRegex on a property but it doesn't seem to work as it doesn't pull the vertices that contain the property.  The code is essentially this:

GraphTraversal<Vertex, Vertex> graphTraversal = graph.traversal().V().

graphTraversal.has(GraphSchema.PropertyKeys.ProjectorsKey, Text.textContainsRegex(".*RiskProjector.*"));


However if I switch to using just textContains it works as I get the expected results.


GraphTraversal<Vertex, Vertex> graphTraversal = graph.traversal().V().

graphTraversal.has(GraphSchema.PropertyKeys.ProjectorsKey, Text.textContains("RiskProjector"));


The regular expression that I am using is the same one that I used under TinkerPop 2 and was working as expected.

Thanks,
Rob

Robert Saccone

unread,
Feb 16, 2016, 11:34:48 AM2/16/16
to Gremlin-users
I did a little experimenting and I found that if I change my code so that it uses textRegex instead of textContainsRegex it works.  However I don't understand the difference between the two.  If someone can explain the details that would be much appreciated.

Regards,
Rob

Daniel Kuppitz

unread,
Feb 16, 2016, 1:10:12 PM2/16/16
to gremli...@googlegroups.com
textRegex is a string search predicate, textContainsRegex is a full-text search predicate. The former will treat the whole text as a single string, while the latter will try to find a match in the tokenized text (e.g. every single word).

Cheers,
Daniel


Reply all
Reply to author
Forward
0 new messages