Skip to content

Commit

Permalink
Add case insensitive comparison to get_typo_correction, new test to t…
Browse files Browse the repository at this point in the history
…est this.

get_typo_correction has been updated to prefer suggesting strings
that are identical after .lower() is run on both.

A new test has also been added to help confirm this new
functionality.
  • Loading branch information
Matthew Spelchak committed Feb 16, 2018
1 parent 55452b1 commit 89b8f27
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/galaxy/jobs/dynamic_tool_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,9 +1687,9 @@ def get_typo_correction(typo_str, word_set, max_dist):
"""
returns the string in a set that closest matches the
input string, as long as the edit distance between them
is equal to or smaller than a value. If it is not
smaller than or equal to the value, nothing is returned
instead.
is equal to or smaller than a value, or the words are
the same when case is not considered. If there are no
appropriate matches, nothing is returned instead.
@type typo_str: str
@param typo_str: The string to be compared
Expand All @@ -1707,18 +1707,25 @@ def get_typo_correction(typo_str, word_set, max_dist):
being compared to are within max_dist edit distance.
"""

## Also check by making it lowercase? along with the word set, and if there's a match that's the one we want to suggest?

# Start curr_best out as the largest
# edit distance we will tolerate plus one
curr_best = max_dist + 1
suggestion = None

for valid_word in word_set:
edit_distance = get_edit_distance(typo_str, valid_word)
if edit_distance < curr_best:
suggestion = valid_word
curr_best = edit_distance
# If we've already found a best match,
# don't bother checking anything else.
if curr_best > 0:
if typo_str.lower() == valid_word.lower():
# if something matches when case insensitive,
# it is automatically set as the best
suggestion = valid_word
curr_best = 0
else:
edit_distance = get_edit_distance(typo_str, valid_word)
if edit_distance < curr_best:
suggestion = valid_word
curr_best = edit_distance

return suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ def test_typo_in_dict_tool_rule_dest(self, l):
('galaxy.jobs.dynamic_tool_destination', 'DEBUG', 'Finished config validation.')
)

@log_capture()
def test_typo_in_case(self, l):
dt.parse_yaml(path=yt.ivYMLTest170, job_conf_path=job_conf_path, test=True)
l.check(
('galaxy.jobs.dynamic_tool_destination', 'DEBUG', 'Running config validation...'),
('galaxy.jobs.dynamic_tool_destination', 'DEBUG', "Default destination 'destinationf' does not appear in the job configuration. Did you mean 'DestinationF'?"),
('galaxy.jobs.dynamic_tool_destination', 'DEBUG', 'Finished config validation.')
)

# ================================Valid yaml files==============================
@log_capture()
def test_parse_valid_yml(self, l):
Expand Down
9 changes: 9 additions & 0 deletions test/unit/jobs/dynamic_tool_destination/ymltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,3 +1328,12 @@
med: waffles_default
verbose: True
'''

# Typo in str tool rule destination
ivYMLTest170 = '''
default_destination:
priority:
med: destinationf
default_priority: med
verbose: True
'''

0 comments on commit 89b8f27

Please sign in to comment.