<commit_before>module Oriented
  class << self
    
    def connection
      connection = Thread.current[:orient_db] || Connection.new
      Thread.current[:orient_db] = connection
      connection.connect
      connection
    end

    def graph(stop_transaction = false)
      connection 
      connection.java_connection.transaction.close if stop_transaction
      connection.graph
    end

    def close_connection
      connection.close if Thread.current[:connection]
      connection = nil 
    end

    def register_hook_class(hook_class)
      return hook_classes if hook_classes.include?(hook_class)
      hook_classes << hook_class
      return unless connection.java_connection

      current_hooks = connection.java_connection.hooks.to_a.select {|h| h.instance_of?(hook_class)}
      if current_hooks.empty?
        connection.java_connection.register_hook(hook_class.new) 
        connection.connect<commit_msg>Forgot to close the right thread var<commit_after>module Oriented
  class << self
    
    def connection
      connection = Thread.current[:orient_db] || Connection.new
      Thread.current[:orient_db] = connection
      connection.connect
      connection
    end

    def graph(stop_transaction = false)
      connection 
      connection.java_connection.transaction.close if stop_transaction
      connection.graph
    end

    def close_connection
      if conn = Thread.current[:orient_db]
        conn.close
        Thread.current[:orient_db] = nil
      end
    end

    def register_hook_class(hook_class)
      return hook_classes if hook_classes.include?(hook_class)
      hook_classes << hook_class
      return unless connection.java_connection

      current_hooks = connection.java_connection.hooks.to_a.select {|h| h.instance_of?(hook_class)}
      if current_hooks.empty?
        connection.java_connection.register_hook(hook_class.new) 
        connection.connect
{'fraction_non_alphanumeric': 0.06775210084033613, 'fraction_numerical': 0.0, 'mean_word_length': 3.0705128205128207, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1750683', 'n_tokens_mistral': 512, 'n_tokens_neox': 507, 'n_words': 107}