1
votes
gremlin> g.V().filter{it.get().property('state').value() == 'A*'}

I'm using AWS Neptune GraphDB. I need to get the vertices having the state names starting with 'A'. could you please help me with these text predicates, which works on AWS Neptune gremlin.

{ TextConatinsPrefix(), TextPrefix(), Text.contains(), .matches(), .contains(), .startWith() these didn't worked through any combinations }

3

3 Answers

3
votes

It may depend on what Neptune allows but here are some examples taken from my book that will work if Neptune allows these types of Lambda.

g.V().hasLabel('airport').
      filter{it.get().property('desc').value().contains('Dallas')}

// Using a filter to search using a regular expression
g.V().has('airport','type','airport').
      filter{it.get().property('city').
        value ==~/Dallas|Austin/}.values('code')

// A regular expression to find any airport with a city 
//name that begins with "Dal"

g.V().has('airport','type','airport').
    filter{it.get().property('city').value()==~/^Dal\w*/}.values('city')

You can avoid Lambdas if all you need is the behavior of a startsWith:

g.V().hasLabel('airport').
      has('city',between('Dal','Dam')).
      values('city')

For completeness here is a URL to the book and related material (all open source) https://github.com/krlawrence/graph

Cheers Kelvin

1
votes

Adding another answer now that it is 2019 to point out that in Apache TinkerPop 3.4 new text predicates were introduced. These include startingWith(), endingWith() and containing() as well as their inverses notStartingWith() etc. Any graph database (including Amazon Neptune) supporting Apache TinkerPop at the 3.4 level or higher should offer these predicates.

Hope this helps folks finding this question today as the original was from 2018.

Cheers Kelvin

-1
votes

Thanks Kelvin. I got this answer, which is working fine with AWS-Neptune GDB

gremlin> g.V().values('state').filter{(''+it).startsWith('A')}

instead of startsWith(), we can use some java methods similar to text predicates.