How to use the keyvi.Dictionary 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"))
github KeyviDev / keyvi / python / examples / completion / prefix_completion_tester.py View on Github external
import keyvi

query = ""

d=keyvi.Dictionary("prefix-completion.keyvi")
c=keyvi.PrefixCompletion(d)

def get_lookup_key(query):
    return query

while query!="exit":
    query = raw_input("Query:")
    for m in c.GetCompletions(get_lookup_key(query.strip())):
        print "{} ({})".format(m.GetMatchedString(), m.GetAttribute("weight"))
github KeyviDev / keyvi / python / examples / lookup / text_lookup_tester.py View on Github external
import keyvi

query = ""

d=keyvi.Dictionary("cities.keyvi")

def get_lookup_key(query):
    return query

while query!="exit":
    query = raw_input("Query:")
    for m in d.LookupText(get_lookup_key(query.strip())):
        print "{}".format(m.GetMatchedString())
github KeyviDev / keyvi / python / examples / completion / prefix_completion_fuzzy_tester.py View on Github external
import keyvi

query = ""

d=keyvi.Dictionary("prefix-completion.keyvi")
c=keyvi.PrefixCompletion(d)

def get_lookup_key(query):
    return query

while query!="exit":
    query = raw_input("Query:")
    for m in c.GetFuzzyCompletions(get_lookup_key(query.strip()), 3):
        print "{} {}".format(m.GetMatchedString(), m.GetAttribute("weight"))
github KeyviDev / keyvi / python / examples / normalization / normalize.py View on Github external
import sys
import keyvi

d=keyvi.Dictionary("normalization.keyvi")
n=keyvi.FsaTransform(d)


for line in sys.stdin:
    print n.Normalize(line)
github KeyviDev / keyvi / python / src / py / keyvi / cli / cli.py View on Github external
def stats(input_file):
    print (json.dumps(keyvi.Dictionary(input_file).GetStatistics(), indent=4, sort_keys=True))
github KeyviDev / keyvi / python / src / py / keyvi / cli / cli.py View on Github external
def dump(args):
    dictionary = keyvi.Dictionary(args.input_file)
    with open(args.output_file, 'w') as file_out:
        for key, value in dictionary.GetAllItems():
            if args.json_dumps:
                key = json.dumps(key)
            if isinstance(key, bytes):
                key = key.decode()
            file_out.write(key)
            if value:
                if args.json_dumps:
                    value = json.dumps(value)
                file_out.write('\t{}'.format(value))
            file_out.write('\n')