code: def ent_sort(text, ents):
      new_ents = []
      ents_mapper = {}
      for ent in ents:
          if ent["entity_type"] not in ents_mapper:
              type_id = random.randint(0, 1000)
              ents_mapper[ent["entity_type"]] = type_id
          else:
              type_id = ents_mapper[ent["entity_type"]]
          ent_offset = match_sublist(list(text), list(ent["entity"]))
          if len(ent_offset) == 0:
              continue
          ent_offset = ent_offset[0]
          new_ents.append([ent, [ent_offset[0], type_id]])
      new_ents = sorted(new_ents, key=lambda x: (x[1][1], x[1][0]))
      new_ents = [it[0] for it in new_ents]
      ents_list = sorted(ents_mapper.items(), key=lambda x: x[1])
      ents_list = [it[0] for it in ents_list]
      return new_ents, ents_list
  
file_path: DeepKE/example/llm/InstructKGC/kg2instruction/utils.py
imports: import random
  import json
  import hashlib
label_desc: Use image node_id 4 for calling a global function with example usage: ent_sort(text, ents) and returns: new_ents,  ents_list