class_docstr: DP Sample class to hold the data info and provide atomic operations.
docstr: Insert given data before the given position.
  
  :param str field: Only value 'x' supported.
  :param int ins_index: The index where the word will be inserted after.
  :param str new_item: The word to be inserted.
  :return ~DPSample: The sentence with one word added.
docstr_tok: ["Insert","given","data","before","the","given","position",".",":","param","str","field",":","Only","value","'","x","'","supported",".",":","param","int","ins_index",":","The","index","where","the","word","will","be","inserted","after",".",":","param","str","new_item",":","The","word","to","be","inserted",".",":","return","~DPSample",":","The","sentence","with","one","word","added","."]
code: def insert_field_before_index(self, field, ins_index, new_item):
      r"""
      Insert given data before the given position.
  
      :param str field: Only value 'x' supported.
      :param int ins_index: The index where the word will be inserted after.
      :param str new_item: The word to be inserted.
      :return ~DPSample: The sentence with one word added.
  
      """
      assert field == "x"
  
      sample = self.clone(self)
      sample = super(DPSample, sample).insert_field_before_indices(
          field, [ins_index], [new_item]
      )
  
      fields_to_values = {"postag": "UNK", "head": "0", "deprel": "unk"}
  
      for _field, value in fields_to_values.items():
          field_obj = getattr(sample, _field)
          insert_values = get_align_seq([new_item], value)[0]
          rep_obj = field_obj.insert_before_index(
              ins_index, insert_values
          )
          setattr(sample, _field, rep_obj)
  
      head_obj = sample.get_value("head")
      rep_obj = sample.head
      bias_len = len(new_item) if isinstance(new_item, list) else 1
  
      for i, head in enumerate(head_obj):
          head_id = int(head)
          if head_id > ins_index:
              rep_obj = rep_obj.replace_at_index(
                  i, str(head_id + bias_len)
              )
          setattr(sample, "head", rep_obj)
  
      return sample
  
file_path: textflint/textflint/input/component/sample/dp_sample.py
imports: from .sample import Sample
  from ..field import ListField, TextField
  from ....common.utils.list_op import get_align_seq, normalize_scope
label_desc: Use image node_id 9 for calling the DPSample obj's underlying member method code with example usage: obj.insert_field_before_index(field, ins_index, new_item) and returns: sample