Augments words by swapping characters out for other characters.
| 129 | |
| 130 | |
| 131 | class CharSwapAugmenter(Augmenter): |
| 132 | """Augments words by swapping characters out for other characters.""" |
| 133 | |
| 134 | def __init__(self, **kwargs): |
| 135 | from textattack.transformations import ( |
| 136 | CompositeTransformation, |
| 137 | WordSwapNeighboringCharacterSwap, |
| 138 | WordSwapRandomCharacterDeletion, |
| 139 | WordSwapRandomCharacterInsertion, |
| 140 | WordSwapRandomCharacterSubstitution, |
| 141 | ) |
| 142 | |
| 143 | transformation = CompositeTransformation( |
| 144 | [ |
| 145 | # (1) Swap: Swap two adjacent letters in the word. |
| 146 | WordSwapNeighboringCharacterSwap(), |
| 147 | # (2) Substitution: Substitute a letter in the word with a random letter. |
| 148 | WordSwapRandomCharacterSubstitution(), |
| 149 | # (3) Deletion: Delete a random letter from the word. |
| 150 | WordSwapRandomCharacterDeletion(), |
| 151 | # (4) Insertion: Insert a random letter in the word. |
| 152 | WordSwapRandomCharacterInsertion(), |
| 153 | ] |
| 154 | ) |
| 155 | super().__init__(transformation, constraints=DEFAULT_CONSTRAINTS, **kwargs) |
| 156 | |
| 157 | |
| 158 | class CheckListAugmenter(Augmenter): |
no outgoing calls