<commit_before>require "yaml"

module ZConfig
  class Data
    def initialize(data_path)
      @data_path = data_path
      @values = {}
    end

    def get(*args)
      # TODO: this lookup logic is hard to read
      config_name, lookup_path = args.map(&:to_s)
      load(config_name) unless @values[config_name]

      unless lookup_path
        @values[config_name]
      else
        @values[config_name].fetch(lookup_path, nil) if @values[config_name]
      end
    end

    def load_file(filename)
      path = File.join(@data_path, filename)
      if File.exists?(path)
        @values[filename[0..-5]] = YAML.load(File.read(path))
      end
    end

    private

    def load(config_name)
      load_file("#{config_name}.yml")
    end
  end<commit_msg>split Data#get method<commit_after>require "yaml"

module ZConfig
  class Data
    def initialize(data_path)
      @data_path = data_path
      @values = {}
    end

    def get(*args)
      root_name, lookup_path = args.map(&:to_s)
      root = get_root(root_name)

      return root unless root && lookup_path
      root.fetch(lookup_path, nil)
    end

    def load_file(filename)
      path = File.join(@data_path, filename)
      if File.exists?(path)
        @values[filename[0..-5]] = YAML.load(File.read(path))
      end
    end

    private

    def get_root(root_name)
      load(root_name) unless @values[root_name]
      @values[root_name]
    end

    def load(root_name)
      load_file("#{root_name}.yml")
    end
  end
{'fraction_non_alphanumeric': 0.10702341137123746, 'fraction_numerical': 0.0026755852842809363, 'mean_word_length': 2.5704057279236276, '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': '6496523', 'n_tokens_mistral': 509, 'n_tokens_neox': 495, 'n_words': 107}