<commit_before>require 'nutcracker/version'
require 'socket'
require 'json'
require 'yaml'
require 'redis'
require 'timeout'

module Nutcracker
  # Syntactic sugar for launching the Nutcracker service ( see {Wrapper#initialize} )
  # @return [Wrapper] Nutcracker process wrapper
  # @example
  #  Nutcracker.start config_file: 'conf/nutcracker.yaml'
  def self.start options
    Nutcracker::Wrapper.new(options).start
  end

  # Connect to a running instance of Nutcracker ( see {Wrapper#initialize} )
  # @return [Wrapper] Nutcracker process wrapper
  # @example
  #  Nutcracker.attach :config_file: 'conf/nutcracker.yaml', :stats_port => 22222
  def self.attach options
    Nutcracker::Wrapper.new options.merge attached: true
  end

  # Returns the Nutcracker executable path that is embeded with the gem
  def self.executable
    File.expand_path("../../ext/nutcracker/src/nutcracker", __FILE__)
  end

  # Returns the version string
  def self.version
    Nutcracker::VERSION
  end

  class Wrapper
    attr_reader :pid

    # Initialize a new Nutcracker process wrappper
    # @param [Hash] options
    # @option options [String] :config_file (conf/nutcracker.yaml) path to nutcracker's configuration file
    # @option options [String] :stats_port (22222) Nutcracker stats listing port
    # @option options [Array] :args ([]) array with additional command line arguments
    def initialize options
      @options = validate defaults.merge options
    end

    # launching the Nutcracker service
    def start *args
      return self if attached? or running?
      @pid = ::Process.spawn Nutcracker.executable, *command
      sleep 1
      abort "Nutcracker failed to start" unless running?
      Kernel.at_exit { kill if running? }
      self
    end<commit_msg>fixing travis<commit_after>require 'nutcracker/version'
require 'socket'
require 'json'
require 'yaml'
require 'redis'
require 'timeout'

module Nutcracker
  # Syntactic sugar for launching the Nutcracker service ( see {Wrapper#initialize} )
  # @return [Wrapper] Nutcracker process wrapper
  # @example
  #  Nutcracker.start config_file: 'conf/nutcracker.yaml'
  def self.start options
    Nutcracker::Wrapper.new(options).start
  end

  # Connect to a running instance of Nutcracker ( see {Wrapper#initialize} )
  # @return [Wrapper] Nutcracker process wrapper
  # @example
  #  Nutcracker.attach :config_file: 'conf/nutcracker.yaml', :stats_port => 22222
  def self.attach options
    Nutcracker::Wrapper.new options.merge attached: true
  end

  # Returns the Nutcracker executable path that is embeded with the gem
  def self.executable
    File.expand_path("../../ext/nutcracker/src/nutcracker", __FILE__)
  end

  # Returns the version string
  def self.version
    Nutcracker::VERSION
  end

  class Wrapper
    attr_reader :pid

    # Initialize a new Nutcracker process wrappper
    # @param [Hash] options
    # @option options [String] :config_file (conf/nutcracker.yaml) path to nutcracker's configuration file
    # @option options [String] :stats_port (22222) Nutcracker stats listing port
    # @option options [Array] :args ([]) array with additional command line arguments
    def initialize options
      @options = validate defaults.merge options
    end

    # launching the Nutcracker service
    def start *args
      return self if attached? or running?
      @pid = ::Process.spawn Nutcracker.executable, *command
      Process.detach(@pid)
      sleep 1
      abort "Nutcracker failed to start" unless running?
      Kernel.at_exit { kill if running? }
      self
    end
{'fraction_non_alphanumeric': 0.08354359405663023, 'fraction_numerical': 0.006167647883375385, 'mean_word_length': 3.6824146981627295, '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': '2801035', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1036, 'n_words': 343}