class_docstr: Entity position swap with paraphrase(birth related)
docstr: Swap entity position through paraphrasing
  
  :param RESample sample: sample input
  :param int n: number of generated samples (no more than one)
  :return list: transformed sample list 
code: def _transform(self, sample, n=1, field="x", **kwargs):
      r"""
      Swap entity position through paraphrasing
  
      :param RESample sample: sample input
      :param int n: number of generated samples (no more than one)
      :return list: transformed sample list
      """
      assert isinstance(sample, RESample), (
          f"the type of 'sample' should be RESample, "
          f"got {type(sample)} instead"
      )
      assert isinstance(n, int), (
          f"the type of 'n' should be int, " f"got {type(n)} instead"
      )
  
      words, relation = sample.get_sent()
      if "birth" not in relation:
          return [sample]
      sh, st, oh, ot = sample.get_en()
      pos_tag = sample.get_pos(field)
      head_pos = [sh, st]
      subj = " ".join(words[sh : st + 1])
      obj = " ".join(words[oh : ot + 1])
      new_sample = {}
      new_sample["x"] = words
  
      if "birth" in relation:
          deprels, heads = sample.get_dp()
          new_sen = []
          words[sh : st + 1] = ["<SUBJ>"] * (st - sh + 1)
          words[oh : ot + 1] = ["<OBJ>"] * (ot - oh + 1)
          for i, word in enumerate(words):
              if word == "born":
                  if head_pos[1] < i:
                      new_sen = self.generate_new_sen_for_birth(
                          i, words, pos_tag, heads, deprels
                      )
  
          if new_sen:
              new_sh = new_sen.index("<SUBJ>")
              new_st = new_sh + (st - sh)
              new_oh = new_sen.index("<OBJ>")
              new_ot = new_oh + (ot - oh)
              sh, st, oh, ot = new_sh, new_st, new_oh, new_ot
              new_sen[new_sh : new_st + 1] = subj.split()
              new_sen[new_oh : new_ot + 1] = obj.split()
              new_sample["x"] = new_sen
  
      new_sample["subj"], new_sample["obj"], new_sample["y"] = (
          [sh, st],
          [oh, ot],
          relation,
      )
      trans_samples = sample.replace_sample_fields(new_sample)
  
      return [trans_samples]
  
file_path: textflint/textflint/generation/transformation/RE/swap_birth.py
imports: from ....input.component.sample import RESample
  from ...transformation import Transformation
label_desc: Use image node_id 6 for calling the SwapBirth obj's underlying member method code with example usage: obj._transform(sample, n, field) and returns: list, list