text: """
  Utilities for working with the local dataset cache.
  This file is adapted from the AllenNLP library at https://github.com/allenai/allennlp
  Copyright by the AllenNLP authors.
  """
  from __future__ import (absolute_import, division, print_function, unicode_literals)
  
  import logging
  import os
  import sys
  
  from urllib.parse import urlparse
  
  
  try:
      from pathlib import Path
      PYTORCH_PRETRAINED_BERT_CACHE = Path(os.getenv('PYTORCH_PRETRAINED_BERT_CACHE',
                                                     Path.home() / '.pytorch_pretrained_bert'))
  except (AttributeError, ImportError):
      PYTORCH_PRETRAINED_BERT_CACHE = os.getenv('PYTORCH_PRETRAINED_BERT_CACHE',
                                                os.path.join(os.path.expanduser("~"), '.pytorch_pretrained_bert'))
  
  CONFIG_NAME = "config.json"
  WEIGHTS_NAME = "pytorch_model.bin"
  
  logger = logging.getLogger(__name__)  # pylint: disable=invalid-name
  
  
  def cached_path(url_or_filename, cache_dir=None):
      """
      Given something that might be a URL (or might be a local path),
      determine which. If it's a URL, download the file and cache it, and
      return the path to the cached file. If it's already a local path,
      make sure the file exists and then return the path.
      """
      if cache_dir is None:
          cache_dir = PYTORCH_PRETRAINED_BERT_CACHE
      if sys.version_info[0] == 3 and isinstance(url_or_filename, Path):
          url_or_filename = str(url_or_filename)
      if sys.version_info[0] == 3 and isinstance(cache_dir, Path):
          cache_dir = str(cache_dir)
  
      parsed = urlparse(url_or_filename)
  
      if os.path.exists(url_or_filename):
          # File, and it exists.
          return url_or_filename
      elif parsed.scheme == '':
          # File, but it doesn't exist.
          raise EnvironmentError("file {} not found".format(url_or_filename))
      else:
          # Something unknown
          raise ValueError("unable to parse {} as a URL or as a local path".format(url_or_filename))