class_docstr: Word replace transformation to implement normal word replace functions.
class_docstr_tok: ["Word","replace","transformation","to","implement","normal","word","replace","functions","."]
docstr: Transform text string according field.
  
  :param dict sample: input data, normally one data component.
  :param str fields: indicate which field to apply transformation
  :param int n: number of generated samples
  :return list: transformed sample list.
docstr_tok: ["Transform","text","string","according","field",".",":","param","dict","sample",":","input","data",",","normally","one","data","component",".",":","param","str","fields",":","indicate","which","field","to","apply","transformation",":","param","int","n",":","number","of","generated","samples",":","return","list",":","transformed","sample","list","."]
code: def _transform(self, sample, field="x", n=1, **kwargs):
      r"""
      Transform text string according field.
  
      :param dict sample: input data, normally one data component.
      :param str fields: indicate which field to apply transformation
      :param int n: number of generated samples
      :return list: transformed sample list.
  
      """
  
      tokens = sample.get_words(field)
      tokens_mask = sample.get_mask(field)
  
      # return up to (len(sub_indices) * n) candidates
      pos_info = sample.get_pos(field) if self.get_pos else None
      legal_indices = self.skip_aug(tokens, tokens_mask, pos=pos_info)
  
      if not legal_indices:
          return []
  
      sub_words, sub_indices = self._get_substitute_words(
          tokens, legal_indices, pos=pos_info, n=n
      )
      # select property candidates
      trans_num = self.get_trans_cnt(len(tokens))
      sub_words, sub_indices = trade_off_sub_words(
          sub_words, sub_indices, trans_num, n
      )
  
      if not sub_words:
          return []
  
      trans_samples = []
  
      for i in range(len(sub_words)):
          single_sub_words = sub_words[i]
          trans_samples.append(
              sample.replace_field_at_indices(
                  field, sub_indices, single_sub_words
              )
          )
  
      return trans_samples
  
file_path: textflint/textflint/generation/transformation/word_substitute.py
imports: import string
  from abc import abstractmethod
  from ..transformation import Transformation
  from ...common.settings import STOP_WORDS, ORIGIN
  from ...common.utils.list_op import trade_off_sub_words
label_desc: Use image node_id 2 for calling the WordSubstitute obj's underlying member method code with example usage: obj._transform(sample, field, n) and returns: trans_samples, list, list