class_docstr: Swap entities with other entities of the same category.
class_docstr_tok: ["Swap","entities","with","other","entities","of","the","same","category","."]
docstr: Transform text string according transform_field.
  
  :param ~Sample sample: input data, normally one data component.
  :param str field:  indicate which field to transform.
  :param int n: number of generated samples
  :param kwargs:
  :return list trans_samples: transformed sample list.
docstr_tok: ["Transform","text","string","according","transform_field",".",":","param","~Sample","sample",":","input","data",",","normally","one","data","component",".",":","param","str","field",":","indicate","which","field","to","transform",".",":","param","int","n",":","number","of","generated","samples",":","param","kwargs",":",":","return","list","trans_samples",":","transformed","sample","list","."]
code: def _transform(self, sample, field="x", n=1, **kwargs):
      r"""
      Transform text string according transform_field.
  
      :param ~Sample sample: input data, normally one data component.
      :param str field:  indicate which field to transform.
      :param int n: number of generated samples
      :param kwargs:
      :return list trans_samples: transformed sample list.
  
      """
      trans_samples = []
      entities_info = sample.get_ner(field)
  
      # replace sub strings by contractions
      indices, entities, categories = self.decompose_entities_info(
          entities_info
      )
      candidates = self._get_random_entities(categories, n)
      candidates, indices = trade_off_sub_words(
          candidates, indices, n=n
      )
  
      if not indices:
          return []
  
      for i in range(len(candidates)):
          candidate = candidates[i]
          trans_samples.append(
              sample.unequal_replace_field_at_indices(
                  field, indices, candidate
              )
          )
  
      return trans_samples
  
file_path: textflint/textflint/generation/transformation/UT/swap_named_ent.py
imports: from ..transformation import Transformation
  from ....common.settings import ENTITIES_PATH, CORENLP_ENTITY_MAP
  from ....common.utils.load import json_loader
  from ....common.utils.list_op import trade_off_sub_words
  from ....common.utils.install import download_if_needed
label_desc: Use image node_id 3 for calling the SwapNamedEnt obj's underlying member method code with example usage: obj._transform(sample, field, n) and returns: trans_samples, list