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
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 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 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"))
def compile_file(input, output, jobs, shards):
skipped_keys = 0
compilers = {}
for i in range (0, shards):
compilers[i] = keyvi.JsonDictionaryCompiler()
if os.path.isdir(input):
input_files = [os.path.join(input,d) for d in os.listdir(input)]
else:
input_files = [input]
for input_file in input_files:
if input_file.endswith(".gz"):
input_fd = gzip.open(input_file)
else:
input_fd = open(input_file)
for line in input_fd:
try:
parts = line.split("\t")
key = parts[0]
def compile_file(input, output, jobs, shards):
skipped_keys = 0
compilers = {}
for i in range (0, shards):
compilers[i] = keyvi.JsonDictionaryCompiler()
if os.path.isdir(input):
input_files = [os.path.join(input,d) for d in os.listdir(input)]
else:
input_files = [input]
for input_file in input_files:
if input_file.endswith(".gz"):
input_fd = gzip.open(input_file)
else:
input_fd = open(input_file)
for line in input_fd:
try:
parts = line.split("\t")
key = parts[0]
def compile(args):
params = {key: value for key, value in args.compiler_params}
dict_type = args.dict_type
if dict_type == 'json':
dictionary = keyvi.JsonDictionaryCompiler(params)
elif dict_type == 'string':
dictionary = keyvi.StringDictionaryCompiler(params)
elif dict_type == 'int':
dictionary = keyvi.IntDictionaryCompiler(params)
elif dict_type == 'completion':
dictionary = keyvi.CompletionDictionaryCompiler(params)
elif dict_type == 'key-only':
dictionary = keyvi.KeyOnlyDictionaryCompiler(params)
else:
return 'Must never reach here'
with open(args.input_file) as file_in:
for line in file_in:
line = line.rstrip('\n')
try:
splits = line.split('\t')