code: def rel_sort(text, rels):
      new_rels = []
      rels_mapper = {}
      for rel in rels:
          if rel["relation"] not in rels_mapper:
              type_id = random.randint(0, 1000)
              rels_mapper[rel["relation"]] = type_id
          else:
              type_id = rels_mapper[rel["relation"]]
          head_offset = match_sublist(list(text), list(rel["head"]))
          tail_offset = match_sublist(list(text), list(rel["tail"]))
          if len(head_offset) == 0 or len(tail_offset) == 0:
              continue
          head_offset = head_offset[0]
          tail_offset = tail_offset[0]
          new_rels.append(
              [rel, [head_offset[0], type_id, tail_offset[0]]]
          )
      new_rels = sorted(
          new_rels, key=lambda x: (x[1][1], x[1][0], x[1][2])
      )
      new_rels = [it[0] for it in new_rels]
      rels_list = sorted(rels_mapper.items(), key=lambda x: x[1])
      rels_list = [it[0] for it in rels_list]
      return new_rels, rels_list
  
file_path: DeepKE/example/llm/InstructKGC/kg2instruction/utils.py
imports: import random
  import json
  import hashlib
label_desc: Use image node_id 3 for calling a global function with example usage: rel_sort(text, rels) and returns: new_rels,  rels_list