<commit_before># Allows instant aliasing of commands. If only one alias matches a command,
# the command is loaded and executed via the autoloader. Otherwise, the matching commands are printed.
module MethMissing
  class <<self
    def after_included
      Boson::Runner.define_autoloader
      main_object_missing
      namespace_missing
    end

    def namespace_missing
      original_method_missing = Boson::Namespace.instance_method(:method_missing)
      Boson::Namespace.send(:define_method, :method_missing) do |meth,*args|
        Boson::Index.read
        meths = MethMissing.underscore_search(meth.to_s, self.boson_commands)
        if meths.size > 1
          puts "Multiple methods match: #{meths.join(', ')}"
        elsif (meths.size == 1) && respond_to?(meths[0])
          puts "Found method #{meths[0]}" if Boson::Runner.verbose?
          Boson::BinRunner.command = Boson::BinRunner.command.sub(meth.to_s, meths[0]) if Boson.const_defined?(:BinRunner)
          send(meths[0], *args)
        else
          original_method_missing.bind(self).call(meth,*args)
        end
      end
    end

    def main_object_missing
      class << Boson.main_object
        original_method_missing = Boson.main_object.method(:method_missing)
        define_method :method_missing do |meth,*args|
          Boson::Index.read
          possible_commands = Boson::Index.all_main_methods.sort
          meths = MethMissing.underscore_search(meth.to_s, possible_commands)
          meths = [meth.to_s] if possible_commands.include?(meth.to_s)
          if meths.size > 1
            puts "Multiple methods match: #{meths.join(', ')}"
          elsif (meths.size == 1)
            puts "Found method #{meths[0]}" if Boson::Runner.verbose?
            Boson::BinRunner.command = Boson::BinRunner.command.sub(meth.to_s, meths[0]) if Boson.const_defined?(:BinRunner)
            original_method_missing.call(meths[0],*args)
          else
            original_method_missing.call(meth,*args)
          end
        end
      end
    end

    # Allows aliasing of underscored words. For example 'some_dang_long_word' can be specified as 's_d_l_w'.
    def underscore_search(input, list)
      if input.include?("_")
        index = 0
        input.split('_').inject(list) {|new_list,e|
          new_list = new_list.select {|f| f.split(/_+/)[index] =~ /^#{Regexp.escape(e)}/ };
          index +=1; new_list
        }<commit_msg>tweaked meth_missing to handle loaded commands that aren't indexed<commit_after># Allows instant aliasing of commands. If only one alias matches a command,
# the command is loaded and executed via the autoloader. Otherwise, the matching commands are printed.
module MethMissing
  class <<self
    def after_included
      Boson::Runner.define_autoloader
      main_object_missing
      namespace_missing
    end

    def namespace_missing
      original_method_missing = Boson::Namespace.instance_method(:method_missing)
      Boson::Namespace.send(:define_method, :method_missing) do |meth,*args|
        Boson::Index.read
        meths = MethMissing.underscore_search(meth.to_s, self.boson_commands)
        if meths.size > 1
          puts "Multiple methods match: #{meths.join(', ')}"
        elsif (meths.size == 1) && respond_to?(meths[0])
          puts "Found method #{meths[0]}" if Boson::Runner.verbose?
          Boson::BinRunner.command = Boson::BinRunner.command.sub(meth.to_s, meths[0]) if Boson.const_defined?(:BinRunner)
          send(meths[0], *args)
        else
          original_method_missing.bind(self).call(meth,*args)
        end
      end
    end

    def main_object_missing
      class << Boson.main_object
        original_method_missing = Boson.main_object.method(:method_missing)
        define_method :method_missing do |meth,*args|
          Boson::Index.read
          possible_commands = (Boson.commands.map {|e| e.name} + Boson::Index.all_main_methods).uniq.sort
          meths = MethMissing.underscore_search(meth.to_s, possible_commands)
          meths = [meth.to_s] if possible_commands.include?(meth.to_s)
          if meths.size > 1
            puts "Multiple methods match: #{meths.join(', ')}"
          elsif (meths.size == 1)
            puts "Found method #{meths[0]}" if Boson::Runner.verbose?
            Boson::BinRunner.command = Boson::BinRunner.command.sub(meth.to_s, meths[0]) if Boson.const_defined?(:BinRunner)
            Boson.can_invoke?(meths[0]) ? Boson.invoke(meths[0], *args) : original_method_missing.call(meths[0],*args)
          else
            original_method_missing.call(meth,*args)
          end
        end
      end
    end

    # Allows aliasing of underscored words. For example 'some_dang_long_word' can be specified as 's_d_l_w'.
    def underscore_search(input, list)
      if input.include?("_")
        index = 0
        input.split('_').inject(list) {|new_list,e|
          new_list = new_list.select {|f| f.split(/_+/)[index] =~ /^#{Regexp.escape(e)}/ };
          index +=1; new_list
        }
{'fraction_non_alphanumeric': 0.11375449820071971, 'fraction_numerical': 0.005597760895641743, 'mean_word_length': 2.878294573643411, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '1780012', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1575, 'n_words': 332}