diff --git a/nemubot/tools/human.py b/nemubot/tools/human.py index a18cde2..f0e947f 100644 --- a/nemubot/tools/human.py +++ b/nemubot/tools/human.py @@ -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