guess: allow to give a maximal depth for search
This commit is contained in:
parent
db1e4e9266
commit
522d0efdb5
@ -57,11 +57,15 @@ def word_distance(str1, str2):
|
||||
return d[len(str1)][len(str2)]
|
||||
|
||||
|
||||
def guess(pattern, expect):
|
||||
def guess(pattern, expect, max_depth=0):
|
||||
if max_depth == 0:
|
||||
max_depth = 1 + len(pattern) / 4
|
||||
elif max_depth <= -1:
|
||||
max_depth = len(pattern) - max_depth
|
||||
if len(expect):
|
||||
se = sorted([(e, word_distance(pattern, e)) for e in expect], key=lambda x: x[1])
|
||||
_, m = se[0]
|
||||
for e, wd in se:
|
||||
if wd > m or wd > 1 + len(pattern) / 4:
|
||||
if wd > m or wd > max_depth:
|
||||
break
|
||||
yield e
|
||||
|
Loading…
x
Reference in New Issue
Block a user