code: def remove_overlapping_entities(
      sorted_spacy_format_entities: List[Tuple[int, int, str]]
  ) -> List[Tuple[int, int, str]]:
      """
      Removes overlapping entities from the entity set, by greedilytaking the longest
      entity from each overlapping chain. The input list of entities should be sorted
      and follow the spacy format.
      """
      spacy_format_entities_without_overlap = []
      current_overlapping_chain: List[Tuple[int, int, str]] = []
      current_overlapping_chain_start = 0
      current_overlapping_chain_end = 0
      for i, current_entity in enumerate(sorted_spacy_format_entities):
          current_entity = sorted_spacy_format_entities[i]
          current_entity_start = current_entity[0]
          current_entity_end = current_entity[1]
  
          if len(current_overlapping_chain) == 0:
              current_overlapping_chain.append(current_entity)
              current_overlapping_chain_start = current_entity_start
              current_overlapping_chain_end = current_entity_end
          else:
              min_end = min(
                  current_entity_end, current_overlapping_chain_end
              )
              max_start = max(
                  current_entity_start, current_overlapping_chain_start
              )
              if min_end - max_start > 0:
                  current_overlapping_chain.append(current_entity)
                  current_overlapping_chain_start = min(
                      current_entity_start,
                      current_overlapping_chain_start,
                  )
                  current_overlapping_chain_end = max(
                      current_entity_end, current_overlapping_chain_end
                  )
              else:
                  selections_from_chain = (
                      select_subset_of_overlapping_chain(
                          current_overlapping_chain
                      )
                  )
  
                  current_overlapping_chain = []
                  spacy_format_entities_without_overlap.extend(
                      selections_from_chain
                  )
                  current_overlapping_chain.append(current_entity)
                  current_overlapping_chain_start = current_entity_start
                  current_overlapping_chain_end = current_entity_end
  
      spacy_format_entities_without_overlap.extend(
          select_subset_of_overlapping_chain(current_overlapping_chain)
      )
  
      return sorted(
          spacy_format_entities_without_overlap, key=lambda x: x[0]
      )
  
file_path: scispacy/scispacy/data_util.py
imports: from typing import Optional, NamedTuple, List, Iterator, Dict, Tuple
  import tarfile
  import atexit
  import os
  import shutil
  import tempfile
  from scispacy.file_cache import cached_path
label_desc: Use image node_id 4 for calling a global function with example usage: remove_overlapping_entities(sorted_spacy_format_entities) and returns: sorted