<commit_before>require "http2" unless ::Kernel.const_defined?(:Http2)
require "cgi" unless ::Kernel.const_defined?(:CGI)
require "json" unless ::Kernel.const_defined?(:JSON)
require "string-cases" unless ::Kernel.const_defined?(:StringCases)

class GenderizeIoRb
  attr_reader :cache_db
  
  def self.const_missing(name)
    require_relative "../include/#{::StringCases.camel_to_snake(name)}"
    raise LoadError, "Still not defined: '#{name}'." unless ::GenderizeIoRb.const_defined?(name)
    return ::GenderizeIoRb.const_get(name)
  end
  
  INITIALIZE_VALID_ARGS = [:cache_as, :cache_db]
  def initialize(args = {})
    args.each do |key, val|
      raise "Invalid key: '#{key}'." unless INITIALIZE_VALID_ARGS.include?(key)
    end
    
    @args = args
    @http = Http2.new(:host => "api.genderize.io")
    
    # Make sure the database-version is up-to-date.
    @cache_db = args[:cache_db]
    if @cache_db
      Baza::Revision.new.init_db(:db => @cache_db, :schema => GenderizeIoRb::DatabaseSchema::SCHEMA)
    end
    
    @cache_as = args[:cache_as]
  end
  
  def info_for_name(name)
    name = name.to_s.strip
    name_lc = name.downcase
    
    # If a database-cache is enabled, try to look result up there first.
    if @cache_db
      cache_db_res = @cache_db.single(:genderize_io_rb_cache, {:name => name_lc})
      if cache_db_res
        res = ::GenderizeIoRb::Result.new(
          :data => JSON.parse(cache_db_res[:result]),
          :genderize_io_rb => self
        )
      end
    end
    
    cache_as_key = "genderize_io_rb_#{name_lc}"
    if @cache_as
      cache_as_res = @cache_as.read(cache_as_key)
      puts "CacheAsRes: #{cache_as_res}"
      
      if cache_as_res
        res = ::GenderizeIoRb::Result.new(
          :data => JSON.parse(cache_as_res),<commit_msg>Removed debug code.<commit_after>require "http2" unless ::Kernel.const_defined?(:Http2)
require "cgi" unless ::Kernel.const_defined?(:CGI)
require "json" unless ::Kernel.const_defined?(:JSON)
require "string-cases" unless ::Kernel.const_defined?(:StringCases)

class GenderizeIoRb
  attr_reader :cache_db
  
  def self.const_missing(name)
    require_relative "../include/#{::StringCases.camel_to_snake(name)}"
    raise LoadError, "Still not defined: '#{name}'." unless ::GenderizeIoRb.const_defined?(name)
    return ::GenderizeIoRb.const_get(name)
  end
  
  INITIALIZE_VALID_ARGS = [:cache_as, :cache_db]
  def initialize(args = {})
    args.each do |key, val|
      raise "Invalid key: '#{key}'." unless INITIALIZE_VALID_ARGS.include?(key)
    end
    
    @args = args
    @http = Http2.new(:host => "api.genderize.io")
    
    # Make sure the database-version is up-to-date.
    @cache_db = args[:cache_db]
    if @cache_db
      Baza::Revision.new.init_db(:db => @cache_db, :schema => GenderizeIoRb::DatabaseSchema::SCHEMA)
    end
    
    @cache_as = args[:cache_as]
  end
  
  def info_for_name(name)
    name = name.to_s.strip
    name_lc = name.downcase
    
    # If a database-cache is enabled, try to look result up there first.
    if @cache_db
      cache_db_res = @cache_db.single(:genderize_io_rb_cache, {:name => name_lc})
      if cache_db_res
        res = ::GenderizeIoRb::Result.new(
          :data => JSON.parse(cache_db_res[:result]),
          :genderize_io_rb => self
        )
      end
    end
    
    cache_as_key = "genderize_io_rb_#{name_lc}"
    if @cache_as
      cache_as_res = @cache_as.read(cache_as_key)
      
      if cache_as_res
        res = ::GenderizeIoRb::Result.new(
          :data => JSON.parse(cache_as_res),
{'fraction_non_alphanumeric': 0.12889637742207244, 'fraction_numerical': 0.0016849199663016006, 'mean_word_length': 3.296743063932449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3477216', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1255, 'n_words': 244}