Skip to content

Commit

Permalink
Merge pull request #761 from jstzwj/dev
Browse files Browse the repository at this point in the history
Word Swap Qwerty Failure Bug Fix
  • Loading branch information
jxmorris12 committed Mar 5, 2024
2 parents f98fbe6 + 40343c0 commit c5531eb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions textattack/transformations/word_swaps/word_swap_qwerty.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ def _get_replacement_words(self, word):

if self.random_one:
i = random.randrange(start_idx, end_idx + 1)
candidate_word = (
word[:i] + random.choice(self._get_adjacent(word[i])) + word[i + 1 :]
)
candidate_words.append(candidate_word)
adjacent_chars = self._get_adjacent(word[i])
if len(adjacent_chars) > 0:
candidate_word = (
word[:i] + random.choice(adjacent_chars) + word[i + 1 :]
)
candidate_words.append(candidate_word)
else:
for i in range(start_idx, end_idx + 1):
for swap_key in self._get_adjacent(word[i]):
Expand Down

0 comments on commit c5531eb

Please sign in to comment.