How to use the keyvi.MultiWordCompletion function in keyvi

To help you get started, we’ve selected a few keyvi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KeyviDev / keyvi / python / examples / completion / multiword_completion_tester.py View on Github external
import keyvi

MULTIWORD_QUERY_SEPARATOR = '\x1b'

query = ""

d=keyvi.Dictionary("mw-completion.keyvi")
c=keyvi.MultiWordCompletion(d)

def get_lookup_key(query):
    l = query.split(" ")
    l_bow = " ".join(sorted(l[:-1]) + l[-1:])

    return l_bow


while query!="exit":
    query = raw_input("Query:")
    for m in c.GetCompletions(get_lookup_key(query.strip())):
        print "{} {}".format(m.GetMatchedString(), m.GetAttribute("weight"))