<commit_before># encoding: utf-8

require 'logger'

# Processor is a core of Myasorubka. This class prepares the environment
# and starts the processing adapter.
#
# Basic usage:
#
#   configuration = { :adapter => Myasorubka::AOT }
#   Myasorubka::Processor.new(configuration).run!
#
class Myasorubka::Processor
  attr_reader :adapter, :path

  # Create a new Processor with given +configuration+ hash.
  #
  # Important options are: <tt>:adapter</tt> and <tt>:path</tt>.
  # Processor gives to +adapter+ entire +configuration+ hash
  # without any changes.
  #
  def initialize(configuration = {})
    raise ArgumentError unless @adapter_class = configuration[:adapter]
    @adapter = @adapter_class.new(configuration)
    @path = configuration[:path] || Dir.getwd
  end

  # Executes the adapter with given configuration.
  #
  def run!
    Myaso::Database.new(Dir.getwd, :manage).tap do |db|
      db.reindex
      adapter.run! db, logger
      db.close!
    end
  end

  # Logger instance.
  #
  def logger
    @logger ||= Logger.new(STDOUT)
  end
end<commit_msg>add start/finish notifications to processor<commit_after># encoding: utf-8

require 'logger'

# Processor is a core of Myasorubka. This class prepares the environment
# and starts the processing adapter.
#
# Basic usage:
#
#   configuration = { :adapter => Myasorubka::AOT }
#   Myasorubka::Processor.new(configuration).run!
#
class Myasorubka::Processor
  attr_reader :adapter, :path

  # Create a new Processor with given +configuration+ hash.
  #
  # Important options are: <tt>:adapter</tt> and <tt>:path</tt>.
  # Processor gives to +adapter+ entire +configuration+ hash
  # without any changes.
  #
  def initialize(configuration = {})
    raise ArgumentError unless @adapter_class = configuration[:adapter]
    @adapter = @adapter_class.new(configuration)
    @path = configuration[:path] || Dir.getwd
  end

  # Executes the adapter with given configuration.
  #
  def run!
    logger.info 'Started'
    Myaso::Database.new(Dir.getwd, :manage).tap do |db|
      db.reindex
      adapter.run! db, logger
      db.close!
    end
    logger.info 'Finished'
  end

  # Logger instance.
  #
  def logger
    @logger ||= Logger.new(STDOUT)
  end
end
{'fraction_non_alphanumeric': 0.11311401532221721, 'fraction_numerical': 0.0009013068949977468, 'mean_word_length': 3.625, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5600851', 'n_tokens_mistral': 708, 'n_tokens_neox': 690, 'n_words': 199}