code: def select_subset_of_overlapping_chain(
      chain: List[Tuple[int, int, str]]
  ) -> List[Tuple[int, int, str]]:
      """
      Select the subset of entities in an overlapping chain to return by greedily choosing the
      longest entity in the chain until there are no entities remaining
      """
      sorted_chain = sorted(
          chain, key=lambda x: x[1] - x[0], reverse=True
      )
      selections_from_chain: List[Tuple[int, int, str]] = []
      chain_index = 0
      # dump the current chain by greedily keeping the longest entity that doesn't overlap
      while chain_index < len(sorted_chain):
          entity = sorted_chain[chain_index]
          match_found = False
          for already_selected_entity in selections_from_chain:
              max_start = max(entity[0], already_selected_entity[0])
              min_end = min(entity[1], already_selected_entity[1])
              if len(range(max_start, min_end)) > 0:
                  match_found = True
                  break
  
          if not match_found:
              selections_from_chain.append(entity)
  
          chain_index += 1
  
      return selections_from_chain
  
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 3 for calling a global function with example usage: select_subset_of_overlapping_chain(chain) and returns: selections_from_chain