Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
k-ivey committed Oct 5, 2023
1 parent cc59ec5 commit 93e522e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions textattack/transformations/word_swaps/word_swap_change_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,26 @@ def _get_transformations(self, current_text, indices_to_modify):
for j in range(1, len(idx)):
indices_to_delete.append(i + j)

transformed_texts.append(current_text.replace_words_at_indices(
location_to_indices[word] + indices_to_delete,
([r] * len(location_to_indices[word]))
+ ([""] * len(indices_to_delete)),
))
transformed_texts.append(
current_text.replace_words_at_indices(
location_to_indices[word] + indices_to_delete,
([r] * len(location_to_indices[word]))
+ ([""] * len(indices_to_delete)),
)
)

# Delete this word to mark it as replaced
del location_to_indices[word]
else:
# If the original location is more than a single word, keep only the starting word
# and replace the starting word with the new word
indices_to_delete = idx[1:]
transformed_texts.append(current_text.replace_words_at_indices([idx[0]] + indices_to_delete, [r] + [""] * len(indices_to_delete)))
transformed_texts.append(
current_text.replace_words_at_indices(
[idx[0]] + indices_to_delete,
[r] + [""] * len(indices_to_delete),
)
)

return transformed_texts

Expand Down

0 comments on commit 93e522e

Please sign in to comment.