Changed suggestion system to give more suggestions also if the help entry catches the exact match.

This commit is contained in:
Griatch 2012-04-22 21:54:28 +02:00
parent e4006bf386
commit 3fba0bdbe3

View file

@ -713,8 +713,7 @@ def string_suggestions(string, vocabulary, cutoff=0.6, maxnum=3):
Returns: Returns:
list of suggestions from vocabulary (could be empty if there are no matches) list of suggestions from vocabulary (could be empty if there are no matches)
""" """
if string in vocabulary: #if string in vocabulary:
return [string] # return [string]
# no exact match. Determine suggestions and return sorted with highest match first.
return [tup[1] for tup in sorted([(string_similarity(string, sugg), sugg) for sugg in vocabulary], return [tup[1] for tup in sorted([(string_similarity(string, sugg), sugg) for sugg in vocabulary],
key=lambda tup: tup[0], reverse=True) if tup[0] >= cutoff][:maxnum] key=lambda tup: tup[0], reverse=True) if tup[0] >= cutoff][:maxnum]