Warm tip: This article is reproduced from stackoverflow.com, please click
amazon-neptune graph-databases gremlin tinkerpop3

String functions on Tinkerpop Query Language

发布于 2020-04-23 15:52:26

Looking in the Tinkerpop doc, I could find a list of String functions:

TextP.startingWith(string) - Does the incoming String start with the provided String?

TextP.endingWith(string) - Does the incoming String end with the provided String? 

TextP.containing(string) - Does the incoming String contain the provided String?

TextP.notStartingWith(string) - Does the incoming String not start with the provided String?

TextP.notEndingWith(string) - Does the incoming String not end with the provided String?

TextP.notContaining(string) - Does the incoming String not contain the provided String?

But, I could not find a way to use them. I also try looking the Javadoc about the TextP in http://tinkerpop.apache.org/javadocs/current/core/org/apache/tinkerpop/gremlin/process/traversal/TextP.html, but also could not find any good information over there.

Query filters like this bellow are working fine:

g.V().has( label, within( 'cake', 'coffee' ) ).limit(3)

Some examples of queries that I have tested and did not worked:

g.V().label().startingWith('c')
g.V().label().fold().startingWith('c')
g.V().label().fold().has(__.startingWith('c'))
g.V().has(label, startingWith('c'))
g.V().has(label, TextP.startingWith('c'))
g.V().has(label.startingWith('c'))
Questioner
Thiago Mata
Viewed
45
stephen mallette 2020-02-11 19:20

TextP is meant to work like any other Predicate and some of the usage you listed is correct:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().has(label, startingWith("p")).label()
==>person
==>person
==>person
==>person
gremlin> g.V().has('name', endingWith("o")).values('name')
==>marko

As a side note I'm a bit surprised to see no examples in the documentation - I intend to get some added.