textflint.common.utils.word_op¶
-
textflint.common.utils.word_op.
get_start_end
(word, skip_first=False, skip_last=False)[source]¶ Get valid operation range of one word.
- Parameters
word (str) – target word string
skip_first (bool) – whether operate first char
skip_last (bool) – whether operate last char
- Returns
start index, last index
-
textflint.common.utils.word_op.
get_random_letter
(src_char=None)[source]¶ Get replaced letter according src_char format.
- Parameters
src_char (char) –
- Returns
default return a lower letter
-
textflint.common.utils.word_op.
swap
(word, num=1, skip_first=False, skip_last=False)[source]¶ Swaps random characters with their neighbors.
- Parameters
word (str) – target word
num (int) – number of typos to add
skip_first (bool) – whether swap first char of word
skip_last (bool) – whether swap last char of word
- Returns
perturbed strings
-
textflint.common.utils.word_op.
insert
(word, num=1, skip_first=False, skip_last=False)[source]¶ Perturb the word with 1 random character inserted.
- Parameters
word (str) – target word
num (int) – number of typos to add
skip_first (bool) – whether insert char at the beginning of word
skip_last (bool) – whether insert char at the end of word
- Returns
perturbed strings
-
textflint.common.utils.word_op.
delete
(word, num=1, skip_first=False, skip_last=False)[source]¶ Perturb the word wityh 1 letter deleted.
- Parameters
word (str) – number of typos to add
num (int) – number of typos to add
skip_first (bool) – whether delete the char at the beginning of word
skip_last (bool) – whether delete the char at the end of word
- Returns
perturbed strings
-
textflint.common.utils.word_op.
replace
(word, num=1, skip_first=False, skip_last=False)[source]¶ Perturb the word with 1 letter substituted for a random letter.
- Parameters
word (str) – target word
num (int) – number of typos to add
skip_first (bool) – whether replace the char at the beginning of word
skip_last (bool) – whether replace the char at the beginning of word
- Returns
perturbed strings