MCPcopy
hub / github.com/QData/TextAttack / replace_word_at_index

Method replace_word_at_index

textattack/shared/attacked_text.py:352–359  ·  view source on GitHub ↗

Returns a new AttackedText object where the word at ``index`` is replaced with a new word.

(self, index: int, new_word: str)

Source from the content-addressed store, hash-verified

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

Callers 15

delete_word_at_indexMethod · 0.95
_get_index_orderMethod · 0.80
_get_transformationsMethod · 0.80
_get_transformationsMethod · 0.80
_get_merged_wordsMethod · 0.80
_get_transformationsMethod · 0.80
_get_transformationsMethod · 0.80
_get_transformationsMethod · 0.80
_get_transformationsMethod · 0.80
_get_transformationsMethod · 0.80

Calls 1

Tested by 1

test_word_replacementMethod · 0.64