<commit_before>require 'delegate'

module Plines
  # Provides a hash that can be accessed by symbol or string keys.
  # This is useful because a plines job batch data hash is commonly
  # provided with symbol keys, but after round-tripping through
  # JSON it is converted to strings. We can't safely convert all
  # strings to symbols (as symbols are never GC'd) so instead we
  # use this for the data hash.
  #
  # Note: using this is convenient but can make things much slower
  # (see `benchmarks/using_indifferent_hash.rb`) so we recomment
  # generally not using it (see `config.exposes_indifferent_hashes`).
  class IndifferentHash < DelegateClass(Hash)
    NotAHashError = Class.new(TypeError)
    ConflictingEntriesError = Class.new(ArgumentError)

    private_class_method :new

    def self.from(original)
      return original if original.is_a?(IndifferentHash)

      unless original.is_a?(Hash)
        raise NotAHashError, "Expected a hash, got #{original.inspect}"
      end

      indif = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }

      original.each do |key, value|
        key = key.to_s

        if indif.has_key?(key)
          raise ConflictingEntriesError,
            "Hash has conflicting entries for #{key}: #{original}"
        end

        indif[key] = indifferent(value)
      end
<commit_msg>Fix typo.<commit_after>require 'delegate'

module Plines
  # Provides a hash that can be accessed by symbol or string keys.
  # This is useful because a plines job batch data hash is commonly
  # provided with symbol keys, but after round-tripping through
  # JSON it is converted to strings. We can't safely convert all
  # strings to symbols (as symbols are never GC'd) so instead we
  # use this for the data hash.
  #
  # Note: using this is convenient but can make things much slower
  # (see `benchmarks/using_indifferent_hash.rb`) so we recommend
  # generally not using it (see `config.exposes_indifferent_hashes`).
  class IndifferentHash < DelegateClass(Hash)
    NotAHashError = Class.new(TypeError)
    ConflictingEntriesError = Class.new(ArgumentError)

    private_class_method :new

    def self.from(original)
      return original if original.is_a?(IndifferentHash)

      unless original.is_a?(Hash)
        raise NotAHashError, "Expected a hash, got #{original.inspect}"
      end

      indif = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }

      original.each do |key, value|
        key = key.to_s

        if indif.has_key?(key)
          raise ConflictingEntriesError,
            "Hash has conflicting entries for #{key}: #{original}"
        end

        indif[key] = indifferent(value)
      end

{'fraction_non_alphanumeric': 0.0795964125560538, 'fraction_numerical': 0.0, 'mean_word_length': 3.1375579598145285, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3805210', 'n_tokens_mistral': 786, 'n_tokens_neox': 767, 'n_words': 281}