Gremlin-Python and Janusgraph Gremlin-Server Full-Text Predicates (textContains*)

400 views
Skip to first unread message

Nick Meves

unread,
Apr 8, 2019, 2:01:58 PM4/8/19
to Gremlin-users
Hey everyone,

Does anyone have any experience successfully extending (or monkeypatching or using Lambdas) the gremlin-python library to add the additional full-text search capabilities Janusgraph provides on top of its elasticsearch index?

Particularly:

import static org.janusgraph.core.attribute.Text.*
g.V().has('booksummary', textContains('unicorns'))
g.V().has('booksummary', textContainsPrefix('uni'))
g.V().has('booksummary', textContainsRegex('.*corn.*'))
g.V().has('booksummary', textContainsFuzzy('unicorn'))

I imagine a lot of monkeypatching to __, GraphTraversal & statics in this module:
https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py

Doesn't anything else need to happen on the gremlin-server python/jython engine side to register those predicates as well?

Any help or peer confirmation that someone else has successfully done this would be greatly appreciated!

Thanks all,
Nick

HadoopMarc

unread,
Apr 8, 2019, 2:29:32 PM4/8/19
to Gremlin-users
Hi Nick,

You may want to check out this pre-alpha work (not my own work, but from janusgraph committers):


In particular, look for a unit test that does what you want.

Cheers,    Marc

Op maandag 8 april 2019 20:01:58 UTC+2 schreef Nick Meves:

Nick Meves

unread,
Apr 8, 2019, 3:00:24 PM4/8/19
to Gremlin-users
Thanks Marc.  Not quite seeing what I need, but gives me ideas.  I'm going to give this a shot -- fingers crossed it works:

from gremlin_python import statics
from gremlin_python.process.traversal import P

class FullTextP(P):
    """Extend P with JanusGraph Full-Text search predicates"""
    def __init__(self, operator, value, other=None):
        P.__init__(self, operator, value, other)

    @staticmethod
    def textContains(*args):
        return FullTextP("textContains", *args)

    @staticmethod
    def textContainsFuzzy(*args):
        return FullTextP("textContainsFuzzy", *args)

    @staticmethod
    def textContainsPrefix(*args):
        return FullTextP("textContainsPrefix", *args)

    @staticmethod
    def textContainsRegex(*args):
        return FullTextP("textContainsRegex", *args)

    @staticmethod
    def textFuzzy(*args):
        return FullTextP("textFuzzy", *args)

    @staticmethod
    def textPrefix(*args):
        return FullTextP("textPrefix", *args)

    @staticmethod
    def textRegex(*args):
        return FullTextP("textRegex", *args)

def textContains(*args):
    return FullTextP.textContains(*args)
statics.add_static('textContains', textContains)

def textContainsFuzzy(*args):
    return FullTextP.textContainsFuzzy(*args)
statics.add_static('textContainsFuzzy', textContainsFuzzy)

def textContainsPrefix(*args):
    return FullTextP.textContainsPrefix(*args)
statics.add_static('textContainsPrefix', textContainsPrefix)

def textContainsRegex(*args):
    return FullTextP.textContainsRegex(*args)
statics.add_static('textContainsRegex', textContainsRegex)

def textFuzzy(*args):
    return FullTextP.textFuzzy(*args)
statics.add_static('textFuzzy', textFuzzy)

def textPrefix(*args):
    return FullTextP.textPrefix(*args)
statics.add_static('textPrefix', textPrefix)

def textRegex(*args):
    return FullTextP.textRegex(*args)
statics.add_static('textRegex', textRegex)

Florian Hockmann

unread,
Apr 9, 2019, 4:18:47 AM4/9/19
to Gremlin-users
What's missing in that library for text predicates? What you're looking for should be in this class:
Reply all
Reply to author
Forward
0 new messages