<commit_before>require 'delegate'
require 'active_support/core_ext/hash'

class KVDAG
  class KeyPathHashProxy < DelegateClass(Hash)
    class KeyPath < Array
      private :initialize
      def initialize(keypath)
        keypath = keypath.split(".") if keypath.is_a?(String)
        super
      end
    end

    private :initialize
    def initialize(hash = {})
      raise TypeError.new("Must be initialized with a `hash`") unless hash.is_a?(Hash)
      @hash = hash.deep_stringify_keys
      super(@hash)
    end
    
    def merge(other, &block)
      self.class.new(@hash.deep_merge(other.deep_stringify_keys, &block))
    end

    def merge!(other, &block)
      @hash.deep_merge!(other.deep_stringify_keys, &block)
      self
    end

    # :call-seq:
    #   fetch("key.path")      -> value or KeyError
    #   fetch(["key", "path"]) -> value or KeyError
    #
    # Return the value at a specified keypath. If the keypath
    # does not specify a terminal value, return the remaining
    # subtree instead.
    #
    # Raises a KeyError exception if the keypath is not found.

    def fetch(keypath)
      *keysubpath, key = KeyPath.new(keypath)
      hash = @hash

      keysubpath.each {|key| hash = hash.fetch(key)}
      hash.fetch(key)
    rescue KeyError
      raise KeyError.new("keypath not found: #{keypath.inspect}")
    end

    # :call-seq:
    #   fetch("key.path")      -> value or nil
    #   fetch(["key", "path"]) -> value or nil
    #
    # Return the value at a specified keypath. If the keypath<commit_msg>Correct documentation error for []<commit_after>require 'delegate'
require 'active_support/core_ext/hash'

class KVDAG
  class KeyPathHashProxy < DelegateClass(Hash)
    class KeyPath < Array
      private :initialize
      def initialize(keypath)
        keypath = keypath.split(".") if keypath.is_a?(String)
        super
      end
    end

    private :initialize
    def initialize(hash = {})
      raise TypeError.new("Must be initialized with a `hash`") unless hash.is_a?(Hash)
      @hash = hash.deep_stringify_keys
      super(@hash)
    end
    
    def merge(other, &block)
      self.class.new(@hash.deep_merge(other.deep_stringify_keys, &block))
    end

    def merge!(other, &block)
      @hash.deep_merge!(other.deep_stringify_keys, &block)
      self
    end

    # :call-seq:
    #   fetch("key.path")      -> value or KeyError
    #   fetch(["key", "path"]) -> value or KeyError
    #
    # Return the value at a specified keypath. If the keypath
    # does not specify a terminal value, return the remaining
    # subtree instead.
    #
    # Raises a KeyError exception if the keypath is not found.

    def fetch(keypath)
      *keysubpath, key = KeyPath.new(keypath)
      hash = @hash

      keysubpath.each {|key| hash = hash.fetch(key)}
      hash.fetch(key)
    rescue KeyError
      raise KeyError.new("keypath not found: #{keypath.inspect}")
    end

    # :call-seq:
    #   []("key.path")      -> value or nil
    #   [](["key", "path"]) -> value or nil
    #
    # Return the value at a specified keypath. If the keypath
{'fraction_non_alphanumeric': 0.11273080660835763, 'fraction_numerical': 0.0, 'mean_word_length': 2.586527293844367, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3066836', 'n_tokens_mistral': 996, 'n_tokens_neox': 965, 'n_words': 271}