<commit_before>require 'json'
require 'eventmachine'

require_relative 'channel'
require_relative 'core_emitter'
require_relative 'core_interface'
require_relative 'core_processor'
require_relative 'core_reporter'
require_relative 'debug'
require_relative 'logging'
require_relative 'plugin_channel'
require_relative 'processor'
require_relative 'protocol'
require_relative 'statistics'
require_relative 'utils'

module EVD
  class Core
    include EVD::Logging

    def initialize plugins, opts={}
      @tunnel_plugins = plugins[:tunnel] || []
      @input_plugins = plugins[:input] || []
      @output_plugins = plugins[:output] || []

      @statistics_opts = opts[:statistics] || {}
      @debug_opts = opts[:debug]
      @core_opts = opts[:core] || {}
      @processor_opts = opts[:processor] || {}

      @output_channel = EVD::PluginChannel.new 'output'
      @input_channel = EVD::PluginChannel.new 'input'

      @tunnels = @tunnel_plugins.map do |plugin|
        plugin.setup self
      end

      @debug = nil

      if @debug_opts
        @debug = EVD::Debug.setup @debug_opts
      end

      @processors = EVD::Processor.load @processor_opts

      @emitter = CoreEmitter.new @output_channel, @core_opts
      @processor = CoreProcessor.new @emitter, @processors

      # Configuration for statistics module.
      @statistics = nil

      if config = @statistics_opts
        @statistics = EVD::Statistics.setup @emitter, config
      end

      @interface = CoreInterface.new(
        @tunnels, @processors, @debug, @statistics, @core_opts)

      @input_instances = @input_plugins.map do |plugin|
        plugin.setup @interface
      end

      @output_instances = @output_plugins.map do |plugin|
        plugin.setup @interface
      end

      reporters = [@output_channel, @input_channel]
      reporters += @output_instances.select{|i| EVD.is_reporter?(i)}
      reporters += @processor.reporters
      reporters << @output_channel

      @reporter = CoreReporter.new reporters

      @statistics.register "core", @reporter
    end

    #
    # Main entry point.
    #
    # Starts an EventMachine and runs the given set of plugins.
    #
    def run
      EM.run do<commit_msg>core: duplicate reporting of output channel.<commit_after>require 'json'
require 'eventmachine'

require_relative 'channel'
require_relative 'core_emitter'
require_relative 'core_interface'
require_relative 'core_processor'
require_relative 'core_reporter'
require_relative 'debug'
require_relative 'logging'
require_relative 'plugin_channel'
require_relative 'processor'
require_relative 'protocol'
require_relative 'statistics'
require_relative 'utils'

module EVD
  class Core
    include EVD::Logging

    def initialize plugins, opts={}
      @tunnel_plugins = plugins[:tunnel] || []
      @input_plugins = plugins[:input] || []
      @output_plugins = plugins[:output] || []

      @statistics_opts = opts[:statistics] || {}
      @debug_opts = opts[:debug]
      @core_opts = opts[:core] || {}
      @processor_opts = opts[:processor] || {}

      @output_channel = EVD::PluginChannel.new 'output'
      @input_channel = EVD::PluginChannel.new 'input'

      @tunnels = @tunnel_plugins.map do |plugin|
        plugin.setup self
      end

      @debug = nil

      if @debug_opts
        @debug = EVD::Debug.setup @debug_opts
      end

      @processors = EVD::Processor.load @processor_opts

      @emitter = CoreEmitter.new @output_channel, @core_opts
      @processor = CoreProcessor.new @emitter, @processors

      # Configuration for statistics module.
      @statistics = nil

      if config = @statistics_opts
        @statistics = EVD::Statistics.setup @emitter, config
      end

      @interface = CoreInterface.new(
        @tunnels, @processors, @debug, @statistics, @core_opts)

      @input_instances = @input_plugins.map do |plugin|
        plugin.setup @interface
      end

      @output_instances = @output_plugins.map do |plugin|
        plugin.setup @interface
      end

      reporters = [@output_channel, @input_channel]
      reporters += @output_instances.select{|i| EVD.is_reporter?(i)}
      reporters += @processor.reporters

      @reporter = CoreReporter.new reporters

      @statistics.register "core", @reporter
    end

    #
    # Main entry point.
    #
    # Starts an EventMachine and runs the given set of plugins.
    #
    def run
      EM.run do
{'fraction_non_alphanumeric': 0.10391086857662574, 'fraction_numerical': 0.0, 'mean_word_length': 3.2216890595009597, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4284388', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1275, 'n_words': 308}