<commit_before># -*- coding: utf-8 -*-

require 'MeCab'
current_dir = File.expand_path(File.dirname(__FILE__))
$:.unshift current_dir + '/betsey'
require 'mecab_utf8_only'
require 'betsey_dsl'

class Betsey
  include BetseyDSL
  @@tagger = MeCab::Tagger.new
  def initialize(script_path = nil)
    @initials = []
    @finals = []
    @quits = []
    @keyword_detectors = []
    script_path ||= default_script_path
    eval(open(script_path).read)
  end

  def greet
    @initials.shuffle.first
  end

  def response(string)
    compose(@@tagger.parse_to_node(string))
  end

  def say_goodbye
    @finals.shuffle.first
  end

  private
  def default_script_path
    File.expand_path(File.dirname(__FILE__)) + '/betsey/script.rb'
  end

  def compose(node)
    @keyword_detectors.find_all{|detector|
      detector.compose_response(node)
    }.max_by{|response| response.priority}
  end
end
<commit_msg>shortened the lines of loading the script file<commit_after># -*- coding: utf-8 -*-

require 'MeCab'
current_dir = File.expand_path(File.dirname(__FILE__))
$:.unshift current_dir + '/betsey'
require 'mecab_utf8_only'
require 'betsey_dsl'

class Betsey
  include BetseyDSL
  @@tagger = MeCab::Tagger.new
  def initialize(script_path = nil)
    @initials = []
    @finals = []
    @quits = []
    @keyword_detectors = []
    eval(open(script_path || default_script_path).read)
  end

  def greet
    @initials.shuffle.first
  end

  def response(string)
    compose(@@tagger.parse_to_node(string))
  end

  def say_goodbye
    @finals.shuffle.first
  end

  private
  def default_script_path
    File.expand_path(File.dirname(__FILE__)) + '/betsey/script.rb'
  end

  def compose(node)
    @keyword_detectors.find_all{|detector|
      detector.compose_response(node)
    }.max_by{|response| response.priority}
  end
end

{'fraction_non_alphanumeric': 0.11923076923076924, 'fraction_numerical': 0.002197802197802198, 'mean_word_length': 3.779527559055118, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1819291', 'n_tokens_mistral': 673, 'n_tokens_neox': 648, 'n_words': 120}