<commit_before>require 'json'

module DismalTony
  class QueryHandler
    attr_accessor :handler_name
    attr_accessor :patterns
    attr_accessor :data
    attr_accessor :vi

    def initialize(virtual = DismalTony::VIBase.new)
      @vi = virtual
      @patterns = []
      @data = {}
      self.handler_start
      @patterns.map! { |e| Regexp.new(e, Regexp::IGNORECASE) } unless @patterns.all? { |e| e.is_a? Regexp }
    end

    def data_json
      @data.to_json
    end

    class << self
      attr_reader :list
    end
    @list = []

    def self.inherited(klass)
      @list << klass
    end

    def error_out
      nil
    end

    def handler_start; end

    def activate_handler!; end

    def activate_handler; end

    def check_understanding(query)
      parse query
      response = 'Okay, I got:\n\n'
      @data.keys.each do |key|
        response += "  #{key}: #{@data[key]}\n"
      end
      response
    end

    def responds?(query)
      parse(query)
    end

    def set_value(index, value)
      @data[index] = value
    end

    def []=(left, right)
      @data[left] = right
    end

    def [](value)
      @data[value]
    end

    def parse(query)
      match_data = nil
      @patterns.each do |pattern|
        match_data ||= pattern.match query
        next if match_data.nil?
        @data.merge!(match_data.named_captures) { |_k, _o, n| n} unless match_data.nil?
      end
      return match_data
    end
  end
end<commit_msg>fixed a bug preventing heroku deployment<commit_after>require 'json'

module DismalTony
  class QueryHandler
    attr_accessor :handler_name
    attr_accessor :patterns
    attr_accessor :data
    attr_accessor :vi

    def initialize(virtual = DismalTony::VIBase.new)
      @vi = virtual
      @patterns = []
      @data = {}
      self.handler_start
      @patterns.map! { |e| Regexp.new(e, Regexp::IGNORECASE) } unless @patterns.all? { |e| e.is_a? Regexp }
    end

    def data_json
      @data.to_json
    end

    class << self
      attr_reader :list
    end
    @list = []

    def self.inherited(klass)
      @list << klass
    end

    def error_out
      nil
    end

    def handler_start; end

    def activate_handler!; end

    def activate_handler; end

    def check_understanding(query)
      parse query
      response = 'Okay, I got:\n\n'
      @data.keys.each do |key|
        response += "  #{key}: #{@data[key]}\n"
      end
      response
    end

    def responds?(query)
      parse(query)
    end

    def set_value(index, value)
      @data[index] = value
    end

    def []=(left, right)
      @data[left] = right
    end

    def [](value)
      @data[value]
    end

    def parse(query)
      match_data = nil
      @patterns.each do |pattern|
        match_data ||= pattern.match query
        next if match_data.nil?

        begin
          caps = match_data.named_captures
          @data.merge!(caps) { |_k, _o, n| n} unless match_data.nil?
        rescue Exception => e #on the off chance named captures doesn't work? (Found on Heroku)
          caps = = {}
          match_data.names.each do |name|
            caps[name] = match_data[name]
          end
          @data.merge!(caps) { |_k, _o, n| n} unless match_data.nil?
        end

      end
      return match_data
    end
  end
end
{'fraction_non_alphanumeric': 0.10267314702308628, 'fraction_numerical': 0.0, 'mean_word_length': 2.0689655172413794, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, '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': '7534297', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1096, 'n_words': 282}