code: def read_full_med_mentions(
      directory_path: str,
      label_mapping: Optional[Dict[str, str]] = None,
      span_only: bool = False,
      spacy_format: bool = True,
      use_umls_ids: bool = False,
  ):
      def _cleanup_dir(dir_path: str):
          if os.path.exists(dir_path):
              shutil.rmtree(dir_path)
  
      resolved_directory_path = cached_path(directory_path)
      if "tar.gz" in directory_path:
          # Extract dataset to temp dir
          tempdir = tempfile.mkdtemp()
          print(
              f"extracting dataset directory {resolved_directory_path} to temp dir {tempdir}"
          )
          with tarfile.open(resolved_directory_path, "r:gz") as archive:
              archive.extractall(tempdir)
          # Postpone cleanup until exit in case the unarchived
          # contents are needed outside this function.
          atexit.register(_cleanup_dir, tempdir)
  
          resolved_directory_path = tempdir
  
      expected_names = [
          "corpus_pubtator.txt",
          "corpus_pubtator_pmids_all.txt",
          "corpus_pubtator_pmids_dev.txt",
          "corpus_pubtator_pmids_test.txt",
          "corpus_pubtator_pmids_trng.txt",
      ]
  
      corpus = os.path.join(resolved_directory_path, expected_names[0])
      examples = med_mentions_example_iterator(corpus)
  
      train_ids = {
          x.strip()
          for x in open(
              os.path.join(resolved_directory_path, expected_names[4])
          )
      }
      dev_ids = {
          x.strip()
          for x in open(
              os.path.join(resolved_directory_path, expected_names[2])
          )
      }
      test_ids = {
          x.strip()
          for x in open(
              os.path.join(resolved_directory_path, expected_names[3])
          )
      }
  
      train_examples = []
      dev_examples = []
      test_examples = []
  
      def label_function(label):
          if span_only:
              return "ENTITY"
          if label_mapping is None:
              return label
          else:
              return label_mapping[label]
  
      for example in examples:
          spacy_format_entities = [
              (
                  x.start,
                  x.end,
                  label_function(x.mention_type)
                  if not use_umls_ids
                  else x.umls_id,
              )
              for x in example.entities
          ]
          spacy_format_entities = remove_overlapping_entities(
              sorted(spacy_format_entities, key=lambda x: x[0])
          )
          spacy_example = (
              example.text,
              {"entities": spacy_format_entities},
          )
          if example.pubmed_id in train_ids:
              train_examples.append(
                  spacy_example if spacy_format else example
              )
  
          elif example.pubmed_id in dev_ids:
              dev_examples.append(
                  spacy_example if spacy_format else example
              )
  
          elif example.pubmed_id in test_ids:
              test_examples.append(
                  spacy_example if spacy_format else example
              )
  
      return train_examples, dev_examples, test_examples
  
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 5 for calling a global function with example usage: read_full_med_mentions(directory_path, label_mapping, span_only, spacy_format, use_umls_ids) and returns: train_examples,  dev_examples,  test_examples, str, label, label_mapping