<commit_before># encoding: utf-8
require 'blurrily/map_group'
require 'blurrily/defaults'

module Blurrily
  class CommandProcessor
    ProtocolError = Class.new(StandardError)

    def initialize(directory)
      @map_group = MapGroup.new(directory)
    end

    def process_command(line)
      command, map_name, *args = line.split(/\t/)
      raise ProtocolError, 'Unknown command' unless COMMANDS.include? command
      raise ProtocolError, 'Invalid database name' unless map_name =~ /^[a-z_]+$/
      result = send("on_#{command}", map_name, *args)
      ['OK', *result].join("\t")
    rescue ArgumentError, ProtocolError => e
      ['ERROR', e.message].join("\t")
    end

    private

    COMMANDS = %w(FIND PUT CLEAR)

    def on_PUT(map_name, needle, ref, weight = nil)<commit_msg>Fixes 1.8.7 compatibility issue<commit_after># encoding: utf-8
require 'blurrily/map_group'
require 'blurrily/defaults'

module Blurrily
  class CommandProcessor
    ProtocolError = Class.new(StandardError)

    def initialize(directory)
      @map_group = MapGroup.new(directory)
    end

    def process_command(line)
      command, map_name, *args = line.split(/\t/)
      raise ProtocolError, 'Unknown command' unless COMMANDS.include? command
      raise ProtocolError, 'Invalid database name' unless map_name =~ /^[a-z_]+$/
      result = send("on_#{command}", map_name, *args)
      ['OK', *result].compact.join("\t")
    rescue ArgumentError, ProtocolError => e
      ['ERROR', e.message].join("\t")
    end

    private

    COMMANDS = %w(FIND PUT CLEAR)

    def on_PUT(map_name, needle, ref, weight = nil)
{'fraction_non_alphanumeric': 0.12764632627646327, 'fraction_numerical': 0.00311332503113325, 'mean_word_length': 3.526760563380282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5543431', 'n_tokens_mistral': 529, 'n_tokens_neox': 503, 'n_words': 128}