gremlinpython

gremlin_python query 'object is not callable' error when trying to filter


I have some experience with using gremlin in the console but I'm fairly new to gremlin in python. I have found a query that does what I want it to do in the console but I get a 'GraphTraversal' object is not callable error when I try to convert it to gremlin python. The query merges two vertices with the same specified property into one containing the edges of both.

Here is the adapted query:

g.V().has('id', 12345) \
    .fold().filter(count(local).is_(gt(1))).unfold(). \
    sideEffect(properties().group("p").by(key).by(value())). \
    sideEffect(outE().group("o").by(label).by(project("p","iv").by(valueMap()).by(inV()).fold())). \
    sideEffect(inE().group("i").by(label).by(project("p","ov").by(valueMap()).by(outV()).fold())). \
    sideEffect(drop()). \
    cap("p","o","i").as_("poi"). \
    addV("User").as_("u"). \
    sideEffect(
        select("poi").select("p").unfold().as_("kv"). \
        select("u").property(select("kv").select(keys), select("kv").select(values))). \
      sideEffect(
        select("poi").select("o").unfold().as_("x").select(values). \
        unfold().addE(select("x").select(keys)).from_(select("u")).to(select("iv"))). \
    sideEffect(
        select("poi").select("i").unfold().as_("x").select(values). \
        unfold().addE(select("x").select(keys)).from_(select("ov")).to(select("u"))).iterate()

and this is the error I'm getting:

TypeError                                 Traceback (most recent call last)
<ipython-input-165-9ce00a27d167> in <module>
      1 g.V().has('id', 12345) \
----> 2     .fold().filter(count(local).is_(gt(1))).unfold(). \
      3     sideEffect(properties().group("p").by(key).by(value())). \
      4     sideEffect(outE().group("o").by(label).by(project("p","iv").by(valueMap()).by(inV()).fold())). \
      5     sideEffect(inE().group("i").by(label).by(project("p","ov").by(valueMap()).by(outV()).fold())). \

TypeError: 'GraphTraversal' object is not callable

I suspect it's an issue with my gremlin_python translation. Any help would be greatly appreciated.


Solution

  • When using Python, certain reserved words conflict with Gremlin steps and need to be suffixed with an underscore. Also certain things like gt are part of the P enum and I prefer to write them out in full. So for the line in question it becomes:

    .fold().filter_(__.count(Scope.local).is_(P.gt(1))).unfold().