class_docstr: Add extra entity-related clause to text
class_docstr_tok: ["Add","extra","entity-related","clause","to","text"]
docstr: Transform text string according to its entities
  
  :param RESample sample: sample input
  :param int n:  number of generated samples (no more than one)
  :return list: transformed sample list
docstr_tok: ["Transform","text","string","according","to","its","entities",":","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"""
      Transform text string according to its entities
  
      :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, got "
          f"{type(sample)} instead"
      )
      assert isinstance(n, int), (
          f"the type of 'n' should be int, " f"got {type(n)} instead"
      )
  
      sh, st, oh, ot = sample.get_en()
      text, relation = sample.get_sent()
  
      trans_sample = {}
      head_entity_span = [sh, st]
      head_entity_name = " ".join(
          text[head_entity_span[0] : head_entity_span[1] + 1]
      )
      tail_entity_span = [oh, ot]
      tail_entity_name = " ".join(
          text[tail_entity_span[0] : tail_entity_span[1] + 1]
      )
      new_text = text
      query = head_entity_name.replace(" ", "%20")
      clauseadd = self.get_clause(query).split()
  
      if clauseadd:
          if head_entity_span[1] < tail_entity_span[0]:  # head ... tail
              (
                  tail_entity_span[0],
                  tail_entity_span[1],
              ) = tail_entity_span[0] + len(
                  clauseadd
              ), tail_entity_span[
                  1
              ] + len(
                  clauseadd
              )
          new_text = (
              new_text[: head_entity_span[1] + 1]
              + clauseadd
              + new_text[head_entity_span[1] + 1 :]
          )
      query = tail_entity_name.replace(" ", "%20")
      clauseadd = self.get_clause(query).split()
  
      if clauseadd:
          if tail_entity_span[1] < head_entity_span[0]:  # tail ... head
              (
                  head_entity_span[0],
                  head_entity_span[1],
              ) = head_entity_span[0] + len(
                  clauseadd
              ), head_entity_span[
                  1
              ] + len(
                  clauseadd
              )
          new_text = (
              new_text[: tail_entity_span[1] + 1]
              + clauseadd
              + new_text[tail_entity_span[1] + 1 :]
          )
  
      assert head_entity_name == " ".join(
          new_text[head_entity_span[0] : head_entity_span[1] + 1]
      )
      assert tail_entity_name == " ".join(
          new_text[tail_entity_span[0] : tail_entity_span[1] + 1]
      )
  
      (
          trans_sample["x"],
          trans_sample["subj"],
          trans_sample["obj"],
          trans_sample["y"],
      ) = (new_text, head_entity_span, tail_entity_span, relation)
      trans_samples = sample.replace_sample_fields(trans_sample)
  
      return [trans_samples]
  
file_path: textflint/textflint/generation/transformation/RE/insert_clause.py
imports: import urllib.request
  import wikidata
  from wikidata.client import Client
  import random
  import json
  from ....common.utils.error import FlintError
  from ...transformation import Transformation
  from ....input.component.sample.re_sample import RESample
  from ....common.settings import WIKIDATA_STATEMENTS_no_zero, CLAUSE_HEAD_no_zero, scbase
label_desc: Use image node_id 6 for calling the InsertClause obj's underlying member method code with example usage: obj._transform(sample, n, field) and returns: list