not() in groovy vs. gremlin-python

320 views
Skip to first unread message

Mark Novak

unread,
Apr 29, 2019, 7:47:07 PM4/29/19
to Gremlin-users
I have a the following working line in groovy (trying to find how many vertices connect to vertex with label A that are not labeled B:

g.V().hasLabel('A').in().not(hasLabel('B')).count()

When I switch to gremlin-python, however, and try this:

g.V().hasLabel('A').in_().not_(hasLabel('B')).count()

I get an error: NameError: name 'hasLabel' is not defined.

How do I restate the query so it works in Python?

kelvin.r...@gmail.com

unread,
Apr 29, 2019, 9:55:37 PM4/29/19
to Gremlin-users
Hi Mark, when you use Gremlin from one of the GLV clients you either need to statically import the "__" (double under bar) class or use it explicitly when you have an anonymous traversal (one not dot connected to a prior step). So you could write your query as:

g.V().hasLabel('A').in_().not_(__.hasLabel('B')).count()


Cheers
Kelvin

Mark Novak

unread,
Apr 30, 2019, 1:06:54 PM4/30/19
to gremli...@googlegroups.com
Unfortunately that did not work. The output now consists of a list such as:
[]
[['V'], ['hasLabel', 'internet', [...
I am expecting a simple number - the output of Count().

--
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/7693bdba-8b0c-4a53-9c0b-d0f2acc7bb3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Kuppitz

unread,
Apr 30, 2019, 1:45:09 PM4/30/19
to gremli...@googlegroups.com
Note, that the query can be simplified to:

g.V().hasLabel('A').in_().hasLabel(neq('B')).count().next()

Cheers,
Daniel


--
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.

kelvin.r...@gmail.com

unread,
Apr 30, 2019, 2:04:07 PM4/30/19
to Gremlin-users
You are seeing the byte code representation of your traversal. As Daniel showed in his example you need to terminate the query with something like next() or toList() when calling from code. The Gremlin Console behind the scenes does that for you. From code you need to be explicit.

Cheers
Kelvin


On Tuesday, April 30, 2019 at 12:06:54 PM UTC-5, Mark Novak wrote:
Unfortunately that did not work. The output now consists of a list such as:
[]
[['V'], ['hasLabel', 'internet', [...
I am expecting a simple number - the output of Count().

On Mon, Apr 29, 2019 at 6:55 PM <kelvin....@gmail.com> wrote:
Hi Mark, when you use Gremlin from one of the GLV clients you either need to statically import the "__" (double under bar) class or use it explicitly when you have an anonymous traversal (one not dot connected to a prior step). So you could write your query as:

g.V().hasLabel('A').in_().not_(__.hasLabel('B')).count()


Cheers
Kelvin

On Monday, April 29, 2019 at 6:47:07 PM UTC-5, Mark Novak wrote:
I have a the following working line in groovy (trying to find how many vertices connect to vertex with label A that are not labeled B:

g.V().hasLabel('A').in().not(hasLabel('B')).count()

When I switch to gremlin-python, however, and try this:

g.V().hasLabel('A').in_().not_(hasLabel('B')).count()

I get an error: NameError: name 'hasLabel' is not defined.

How do I restate the query so it works in Python?

--
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 gremli...@googlegroups.com.

Mark Novak

unread,
Apr 30, 2019, 8:14:47 PM4/30/19
to Gremlin-users
Unfortunately that does not work either. I get this error:

    g.V().hasLabel('A').in_().hasLabel(neq('B')).count().next()
NameError: name 'neq' is not defined

On Tuesday, April 30, 2019 at 10:45:09 AM UTC-7, Daniel Kuppitz wrote:
Note, that the query can be simplified to:

g.V().hasLabel('A').in_().hasLabel(neq('B')).count().next()

Cheers,
Daniel


On Mon, Apr 29, 2019 at 4:47 PM Mark Novak <mr.ma...@gmail.com> wrote:
I have a the following working line in groovy (trying to find how many vertices connect to vertex with label A that are not labeled B:

g.V().hasLabel('A').in().not(hasLabel('B')).count()

When I switch to gremlin-python, however, and try this:

g.V().hasLabel('A').in_().not_(hasLabel('B')).count()

I get an error: NameError: name 'hasLabel' is not defined.

How do I restate the query so it works in Python?

--
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 gremli...@googlegroups.com.

kelvin.r...@gmail.com

unread,
Apr 30, 2019, 9:55:10 PM4/30/19
to Gremlin-users
Hi Mark, try using P.neq instead

The notes here may help. It is written about Java but applies equally well to Python for the most part.

Cheers,
Kelvin
Reply all
Reply to author
Forward
0 new messages