textflint.common.utils.list_op¶
-
textflint.common.utils.list_op.
trade_off_sub_words
(sub_words, sub_indices, trans_num=None, n=1)[source]¶ Select proper candidate words to maximum number of transform result. Select words of top n substitutes words number.
- Parameters
sub_words (list) – list of substitutes word of each legal word
sub_indices (list) – list of indices of each legal word
trans_num (int) – max number of words to apply substitution
n (int) –
- Returns
sub_words after alignment + indices of sub_words
-
textflint.common.utils.list_op.
normalize_scope
(scope)[source]¶ Convert various scope input to list format of [left_bound, right_bound]
- Parameters
scope (int|list|tuple|slice) – can be int indicate replace single item like 1 or 3. can be list like (0,3) indicate replace items from 0 to 3(not included) or their list like [5,6] can be slice which would be convert to list or their list.
- Return list
[left_bound, right_bound]
-
textflint.common.utils.list_op.
replace_at_scopes
(origin_list, scopes, new_items)[source]¶ Replace items of given list. Notice: just support isometric replace.
- Parameters
origin_list (list) –
scopes (list) –
list of int/list/slice can be int indicate replace single item or their list like [1, 2, 3]. can be list like (0,3) indicate replace items from 0 to 3(not included)
or their list like [(0, 3), (5,6)]
can be slice which would be convert to list or their list. Watch out! Each range must be the same type!
new_items (list) – items corresponding scopes.
- Returns
-
textflint.common.utils.list_op.
replace_at_scope
(origin_list, scope, new_items)[source]¶ Replace items of given list instance.
- Parameters
origin_list (list) –
scope (int|list|slice) –
can be int indicate replace single item or their list like 1. can be list like (0,3) indicate replace items from 0 to 3(not included)
or their list like [0, 3]
can be slice which would be convert to list or their list.
new_items – list
- Return list
new list
-
textflint.common.utils.list_op.
delete_at_scopes
(origin_list, scopes)[source]¶ Delete items of origin_list of given scopes.
- Parameters
origin_list (list) –
scopes (list) –
list of int/list/tuple/slice can be int indicate replace single item or their list like [1, 2, 3]. can be list like (0,3) indicate replace items from 0 to 3(not included)
or their list like [5,6]
can be slice which would be convert to list or their list.
- Return list
new list
-
textflint.common.utils.list_op.
delete_at_scope
(origin_list, scope)[source]¶ Delete items of origin_list of given scope.
- Parameters
origin_list (list) –
scope (int|list|tuple|slice) –
can be int indicate replace single item or their list like [1, 2, 3]. can be list like (0,3) indicate replace items from 0 to 3(not included)
or their list like [5,6]
can be slice which would be convert to list or their list.
- Returns
-
textflint.common.utils.list_op.
handle_empty_insertion
(new_items)[source]¶ Handle inserting new items to an empty list, by concatenating all new items Warning if multiple items are fed.
- Parameters
new_items (list) – list
- Return list
new list
-
textflint.common.utils.list_op.
insert_before_indices
(origin_list, indices, new_items)[source]¶ Insert items to origin_list before given indices.
- Parameters
origin_list (list) –
indices (list) –
new_items (list) –
- Return list
-
textflint.common.utils.list_op.
insert_before_index
(origin_list, index, new_items)[source]¶ Insert items to origin_list before given index.
- Parameters
origin_list (list) –
index (int) –
new_items (list) –
- Return list
-
textflint.common.utils.list_op.
insert_after_indices
(origin_list, indices, new_items)[source]¶ Insert items to origin_list after given indices.
- Parameters
origin_list (list) –
indices (list) –
new_items (list) –
- Return list
-
textflint.common.utils.list_op.
insert_after_index
(origin_list, index, new_items)[source]¶ Insert items to origin_list after given index.
- Parameters
origin_list (list) –
index (int) –
new_items (list) –
- Returns
-
textflint.common.utils.list_op.
swap_at_index
(origin_list, first_index, second_index)[source]¶ Swap items between first_index and second_index of origin_list
- Parameters
origin_list (list) –
first_index (int) –
second_index (int) –
- Return list
-
textflint.common.utils.list_op.
unequal_replace_at_scopes
(origin_list, scopes, new_items)[source]¶ Replace items of given list.
Notice: support unequal replace. :param list origin_list: :param list scopes: list of int/list/slice
can be int indicate replace single item or their list like [1, 2, 3]. can be list like (0,3) indicate replace items from 0 to 3(not included)
or their list like [(0, 3), (5,6)]
can be slice which would be convert to list or their list.
- Parameters
new_items –
:return list :