def swap_chars(self, word): """ Randomly swap letters between two positions in a word. """ i, j = utils.rand_index(word), utils.rand_index(word) if i > j: i, j = j, i # swaps i and j uword = word[:i] + word[j] + word[i + 1:j] + word[i] + word[j + 1:] log.debug("[swap char] {} -> {}: %s".format(word, uword)) return uword
def flip_char(self, word): """ Randomly flip letters between two positions in a word. """ log.debug("flip change---before: %s" % word) i, j = utils.rand_index(word), utils.rand_index(word) if i > j: i, j = j, i # swaps i and j word = word[:i] + word[j] + word[i + 1:j] + word[i] + word[j + 1:] log.debug("flip change---after: %s" % word) return word
def repeat_char(self, word): """ Randomly repeat a letter in a word. """ pos = utils.rand_index(word) uword = word[:pos] + word[pos] + word[pos:] log.debug("[repeat char] {} -> {}: %s".format(word, uword)) return uword
def flip_rand_pairs(self, word): """ Randomly flip two neighboring letters in a word. """ pos = utils.rand_index(word) i, j = (pos - 1, pos) if pos > 0 else (pos, pos + 1) uword = word[:i] + word[j] + word[i] + word[j + 1:] return uword
def add_char(self, word): """ Randomly add a vowel or a letter from a word. """ pos = utils.rand_index(word) addition = random.choice(list(word + 'aeiou')) uword = word[:pos] + addition + word[pos:] log.debug("[add char] {} -> {}: %s".format(word, uword)) return uword
def repeat_char(self, word): """ Randomly repeat a letter in a word. """ log.debug("repeat change---before: %s" % word) pos = utils.rand_index(word) word = word[:pos] + word[pos] + word[pos:] log.debug("repeat change---after: %s" % word) return word
def swap_char(self, word): """ Randomly swap two neighboring letters in a word. """ log.debug("swap change---before: %s" % word) pos = utils.rand_index(word) i, j = (pos - 1, pos) if pos > 0 else (pos, pos + 1) word = word[:i] + word[j] + word[i] + word[j + 1:] log.debug("swap change---after: %s" % word) return word
def add_char(self, word): """ Randomly add vowel to word. """ log.debug("addition change---before: %s" % word) pos = utils.rand_index(word) addition = random.choice(list(word+'aeiou')) word = word[:pos] + addition + word[pos:] log.debug("addition change---after: %s" % word) return word
def drop_char(self, word): """ Drop char in a word. TODO test [vowel or double] only. """ pos = utils.rand_index(word) if pos == 0: pos += 1 # don't drop first letter of a word uword = word[:pos] + word[pos + 1:] log.debug("[drop char] {} -> {}: %s".format(word, uword)) return uword
def drop_char(self, word): """ Drop char in a word. TODO test [vowel or double] only. """ log.debug("drop change---before: %s" % word) pos = utils.rand_index(word) if pos == 0: pos += 1 # don't drop first letter of a word uword = word[:pos] + word[pos+1:] log.debug("drop change---after: %s" % word) return uword