<commit_before>class Hash
  # Merges self with another hash, recursively.
  #
  # This code was lovingly stolen from some random gem:
  # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
  #
  # Thanks to whoever made it.
  def deep_merge(hash)
    target = Marshal.load(Marshal.dump(self))
    target.deep_merge!(hash)
  end

  def deep_merge!(hash)
    hash.keys.each do |key|
      if hash[key].is_a? Hash and self[key].is_a? Hash
        self[key] = self[key].deep_merge!(hash[key])
        next
      end

      self[key] = hash[key]
    end

    self.deep = true
    self
  end
  
  def deep_clone
    dest = {}.deep!
    each do |k, v|
      dest[k] = case v
      when Hash
        v.deep_clone
      when Array
        v.clone
      else
        v
      end
    end
    dest
  end

  def lookup(path)
    path.split("/").inject(self) {|m,i| m[i].nil? ? (return nil) : m[i]}
  end
  
  def set(path, value)
    leafs = path.split("/")
    k = leafs.pop
    h = leafs.inject(self) {|m, i| m[i].is_a?(Hash) ? m[i] : (m[i] = {})}
    h[k] = value
  end
  
  attr_accessor :deep

  alias_method :old_get, :[]
  def [](k)
    if @deep && k.is_a?(String) && k =~ /\//
      lookup(k)
    elsif @deep && k.is_a?(Symbol)
      old_get(k.to_s)
    else
      old_get(k)
    end
  end
  
  alias_method :old_set, :[]=
  def []=(k, v)
    if @deep && k.is_a?(String) && k =~ /\//
      set(k, v)
    elsif @deep && k.is_a?(Symbol)
      old_set(k.to_s, v)
    else
      old_set(k, v)
    end
  end
  
  alias_method :old_merge, :merge
  def merge(hash)
    if @deep || hash.deep
      deep_merge(hash)
    else
      old_merge(hash)
    end
  end
  
  alias_method :old_merge!, :merge!
  def merge!(hash)
    if @deep || hash.deep
      deep_merge!(hash)
    else
      old_merge!(hash)
    end
  end
  
  def deep!
    @deep = true
    self
  end
end

class String
  def camelize
    split('_').collect(&:capitalize).join
  end
end<commit_msg>Add support code for part titles<commit_after>class Hash
  # Merges self with another hash, recursively.
  #
  # This code was lovingly stolen from some random gem:
  # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
  #
  # Thanks to whoever made it.
  def deep_merge(hash)
    target = Marshal.load(Marshal.dump(self))
    target.deep_merge!(hash)
  end

  def deep_merge!(hash)
    hash.keys.each do |key|
      if hash[key].is_a? Hash and self[key].is_a? Hash
        self[key] = self[key].deep_merge!(hash[key])
        next
      end

      self[key] = hash[key]
    end

    self.deep = true
    self
  end
  
  def deep_clone
    dest = {}.deep!
    each do |k, v|
      dest[k] = case v
      when Hash
        v.deep_clone
      when Array
        v.clone
      else
        v
      end
    end
    dest
  end

  def lookup(path)
    path.split("/").inject(self) {|m,i| m[i].nil? ? (return nil) : m[i]}
  end
  
  def set(path, value)
    leafs = path.split("/")
    k = leafs.pop
    h = leafs.inject(self) {|m, i| m[i].is_a?(Hash) ? m[i] : (m[i] = {})}
    h[k] = value
  end
  
  attr_accessor :deep

  alias_method :old_get, :[]
  def [](k)
    if @deep && k.is_a?(String) && k =~ /\//
      lookup(k)
    elsif @deep && k.is_a?(Symbol)
      old_get(k.to_s)
    else
      old_get(k)
    end
  end
  
  alias_method :old_set, :[]=
  def []=(k, v)
    if @deep && k.is_a?(String) && k =~ /\//
      set(k, v)
    elsif @deep && k.is_a?(Symbol)
      old_set(k.to_s, v)
    else
      old_set(k, v)
    end
  end
  
  alias_method :old_merge, :merge
  def merge(hash)
    if @deep || hash.deep
      deep_merge(hash)
    else
      old_merge(hash)
    end
  end
  
  alias_method :old_merge!, :merge!
  def merge!(hash)
    if @deep || hash.deep
      deep_merge!(hash)
    else
      old_merge!(hash)
    end
  end
  
  def deep!
    @deep = true
    self
  end
end

class String
  def titlize(all_capitals = false)
    all_capitals ? 
      self.gsub("-", " ").gsub(/\b('?[a-z])/) {$1.capitalize} :
      self.gsub("-", " ").capitalize
  end

  def camelize
    split('_').collect(&:capitalize).join
  end
end

class Fixnum
  ROMAN = %w[0 I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX
    XX XXI XXII XXIII XXIV XXV XXVI XXVII XXVIII XXIX XXX]
  
  def to_roman
    ROMAN[self]
  end
end

{'fraction_non_alphanumeric': 0.14085494043447794, 'fraction_numerical': 0.001868722261153936, 'mean_word_length': 2.087238644556597, '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': '2321529', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1696, 'n_words': 413}