Returns a new AttackedText object where the word at ``index`` is replaced with a new word.
(self, index: int, new_word: str)
| 350 | return self.generate_new_attacked_text(words) |
| 351 | |
| 352 | def replace_word_at_index(self, index: int, new_word: str) -> AttackedText: |
| 353 | """Returns a new AttackedText object where the word at ``index`` is |
| 354 | replaced with a new word.""" |
| 355 | if not isinstance(new_word, str): |
| 356 | raise TypeError( |
| 357 | f"replace_word_at_index requires ``str`` new_word, got {type(new_word)}" |
| 358 | ) |
| 359 | return self.replace_words_at_indices([index], [new_word]) |
| 360 | |
| 361 | def delete_word_at_index(self, index: int) -> AttackedText: |
| 362 | """Returns a new AttackedText object where the word at ``index`` is |