in augly/text/augmenters/contraction.py [0:0]
def substitute_contractions(self, text: str) -> str:
"""
Returns a text where random words are replaced using the specified mapping
@param text: the text to which the word substitution will be applied
"""
results = []
tokens = tokenize(text)
for c_len in range(2, self.max_contraction_length + 1):
i = 0
while i <= len(tokens) - c_len:
result = tokens[i]
if self.rng.rand() <= self.aug_p:
contraction = self.contraction_mapping.replace(
" ".join(tokens[i : i + c_len])
)
if contraction is not None:
result = contraction
i += c_len - 1
results.append(result)
i += 1
results.extend(tokens[-c_len + 1 :])
return detokenize(results)