<commit_before>require 'yaml'
require 'json'

module Prmd
  def self.load_schema_file(filename)
    data = File.read(filename)
    extname = File.extname(filename)

    case extname.downcase
    when '.yaml', '.yml'
      YAML.load(data)
    when '.json'
      JSON.load(data)
    else
      abort "Cannot load schema file #{filename}, (unsupported file extension #{extname})"
    end
  end
end<commit_msg>load_schema_file, avoid loading the file before verifying it can be loaded<commit_after>require 'yaml'
require 'json'

module Prmd
  def self.load_schema_file(filename)
    extname = File.extname(filename)
    File.open(filename) do |file|
      case extname.downcase
      when '.yaml', '.yml'
        YAML.load(file.read)
      when '.json'
        JSON.load(file.read)
      else
        abort "Cannot load schema file #{filename}" \
              "(unsupported file extension #{extname})"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10583153347732181, 'fraction_numerical': 0.0, 'mean_word_length': 2.814814814814815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6691403', 'n_tokens_mistral': 294, 'n_tokens_neox': 289, 'n_words': 83}