1
0
Fork 0

guess: allow to give a maximal depth for search

This commit is contained in:
nemunaire 2016-07-08 22:33:32 +02:00
parent db1e4e9266
commit 522d0efdb5
1 changed files with 6 additions and 2 deletions

View File

@ -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