Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"))
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"))
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())
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"))
import sys
import keyvi
d=keyvi.Dictionary("normalization.keyvi")
n=keyvi.FsaTransform(d)
for line in sys.stdin:
print n.Normalize(line)
def stats(input_file):
print (json.dumps(keyvi.Dictionary(input_file).GetStatistics(), indent=4, sort_keys=True))
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')