<commit_before>require 'zookeeper'
require 'json'
require 'uri'


module ZkClient
  ROOT = '/'

  class << self

    def client
      @@client ||= create_client
    end

    def read(path)
      read_node(path)[:data]
    end

    def read_node(path)
      key = process_path(path)
      client.get(path: key)
    end

    def write(path, data)
      key = process_path(path)
      response = client.set(path: key, data: data)
      if !response[:stat].exists
        create(key, data)
      else
        response
      end
    end

    def create(path, data)
      key = process_path(path)
      resp = client.create(path: key, data: data)
    end

    def delete(path)
      key = process_path(path)
      client.delete(path: key)
    end

    def close
      client.close
    end

    def config
      if block_given?
        yield(self)
      end
    end

    def root_path
      @@root_path ||= ROOT
    end

    def root_path=(root)
      @@root_path = root
    end

    def host
      @@host ||= "localhost"
    end

    def host=(host)
      @@host = host
    end

    def port
      @@port ||= 2181
    end

    def port=(port)
      @@port = port.to_i
    end

    #def scheme
    #  @@scheme ||= 'http'
    #end

    #def scheme=(scheme)
    #  @@scheme = scheme
    #end

    def uri
      "#{host}:#{port}"
    end

    def uri=(uri)
      parsed_uri = URI(uri)

      #@@scheme    = parsed_uri.scheme
      @@host      = parsed_uri.host
      @@port      = parsed_uri.port
      @@root_path = parsed_uri.path
    end

    # Backward compatibility
    def root
      root_path
    end

    private

    def create_client
      if defined?(@@client) && @@client.respond_to?(close)<commit_msg>Removing commented out scheme methods.<commit_after>require 'zookeeper'
require 'json'
require 'uri'


module ZkClient
  ROOT = '/'

  class << self

    def client
      @@client ||= create_client
    end

    def read(path)
      read_node(path)[:data]
    end

    def read_node(path)
      key = process_path(path)
      client.get(path: key)
    end

    def write(path, data)
      key = process_path(path)
      response = client.set(path: key, data: data)
      if !response[:stat].exists
        create(key, data)
      else
        response
      end
    end

    def create(path, data)
      key = process_path(path)
      resp = client.create(path: key, data: data)
    end

    def delete(path)
      key = process_path(path)
      client.delete(path: key)
    end

    def close
      client.close
    end

    def config
      if block_given?
        yield(self)
      end
    end

    def root_path
      @@root_path ||= ROOT
    end

    def root_path=(root)
      @@root_path = root
    end

    def host
      @@host ||= "localhost"
    end

    def host=(host)
      @@host = host
    end

    def port
      @@port ||= 2181
    end

    def port=(port)
      @@port = port.to_i
    end

    def uri
      "#{host}:#{port}"
    end

    def uri=(uri)
      parsed_uri = URI(uri)

      @@host      = parsed_uri.host
      @@port      = parsed_uri.port
      @@root_path = parsed_uri.path
    end

    # Backward compatibility
    def root
      root_path
    end

    private

    def create_client
      if defined?(@@client) && @@client.respond_to?(close)
{'fraction_non_alphanumeric': 0.10515086863761049, 'fraction_numerical': 0.0024382810118866198, 'mean_word_length': 1.8415584415584416, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6929140', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1062, 'n_words': 277}