<commit_before>module Neo4j

  class << self
    extend Forwardable

    ##
    # Returns the current version of the database.
    # This version has been set by running one or more migrations.
    # The version is stored on the reference node, with property 'db_version'
    # (Delegates to the Reference Node that includes the MigrationMixin.)
    #
    # === See Also
    # Neo4j::MigrationMixin#db_version
    #
    # :singleton-method: db_version

    ##
    # Force Neo4j.rb to perform migrations
    #
    # === See Also
    # Neo4j::MigrationMixin#migrate!
    #
    # :singleton-method: migrate!

    ##
    # Specifies a single migration.
    #
    # === Example
    # Notice that the reference node is the context in the up and down blocks.
    #
    #   Neo4j.migration 1, :create_articles do
    #    up do
    #      rels.outgoing(:colours) << Neo4j.new :colour => 'red'  << Neo4j.new :colour => 'blue'
    #    end
    #    down do
    #      rels.outgoing(:colours).each {|n| n.del }
    #    end
    #  end
    #
    # === See Also
    # Neo4j::MigrationMixin::ClassMethods#migration
    # Neo4j::ReferenceNode
    #
    # :singleton-method: migration

    ##
    # Returns all migrations that has been defined.
    #
    # === See Also
    # Neo4j::MigrationMixin::ClassMethods#migrations
    #
    # :singleton-method: migrations

    def_delegators :@ref_node, :db_version, :migrate!
    def_delegators Neo4j::ReferenceNode, :migration, :migrations



    # Starts neo4j unless it is not already started.
    # Before using neo4j it has to be started and the location of the Neo database on the file system must
    # have been configured, Neo4j::Config[:storage_path]. You do not have to call this method since
    # neo4j will be started automatically when needed.
    # Registers an at_exit handler that stops neo4j (see Neo4j::stop)
    #
    # === Parameters
    # neo_instance:: optional, an instance of org.neo4j.graphdb.GraphDatabaseService
    #
    # === Examples
    # Neo4j::Config[:storage_path] = '/var/neo4j-db'
    # Neo4j.start
    #
    # === Returns
    # nil
    #
    def start(neo_instance=nil)
      return if running?
      at_exit do
        Neo4j.stop
      end
      @neo = neo_instance || org.neo4j.kernel.EmbeddedGraphDatabase.new(Neo4j::Config[:storage_path])
      @ref_node = Neo4j::Transaction.run do
        ReferenceNode.new(@neo.getReferenceNode())
      end

      Neo4j::Transaction.run do
        Neo4j.event_handler.neo_started(self)
      end

      Neo4j::Transaction.run { @ref_node.migrate!}
      nil
    end

    # Return the org.neo4j.kernel.EmbeddedGraphDatabase
    #
    #
    def instance
      start unless running?
      @neo
    end

    # Stops the current instance unless it is not started.
    #
    def stop
      if running?
        Neo4j::Transaction.finish # just in case
        @neo.shutdown
        Neo4j.event_handler.neo_stopped(self)
      end
      @neo = nil
    end

    #
    # Returns true if neo4j is running
    #
    def running?
      !@neo.nil?
    end


    # Create a Neo4j::Node
    # This is the same as Neo4j::Node.new.
    # All nodes are created by this method
    def create_node(props = {}) # :nodoc:
      node = instance.createNode
      props.each_pair{|k,v| node[k] = v}
      node
    end

    # Creates a new Relationship
    # All relationships are created by this method.
    def create_rel(type, from_node, to_node, props = {}) # :nodoc:
      rel = from_node.add_rel(type, to_node)
      props.each_pair {|k,v| rel[k] = v}
      rel
    end

    # Return a Neo4j node.
    #
    # ==== Parameters
    # node_id<String, to_i>:: the unique neo id for one node
    # raw<true|false(default)> :: if the raw Java node object should be returned or the Ruby wrapped node.
    #
    # ==== Returns
    # The node object or nil if not found
    def load_node(node_id, raw = false)
      neo_node = @neo.getNodeById(node_id.to_i)
      if (raw)
        neo_node
       else
        neo_node.wrapper
      end
    rescue org.neo4j.graphdb.NotFoundException
      nil
    end


    # Return a Neo4j relationship.
    #
    # ==== Parameters
    # rel_id<String, to_i>:: the unique neo id for one node
    # raw<true|false(default)> :: if the raw Java relationship object should be returned or the Ruby wrapped node.
    #
    # ==== Returns
    # The node object or nil if not found
    #
    def load_rel(rel_id, raw = false)
      neo_rel = @neo.getRelationshipById(rel_id.to_i)
      if (raw)
        neo_rel
      else
        neo_rel.wrapper
      end
    rescue org.neo4j.graphdb.NotFoundException<commit_msg>minor rdoc stuff<commit_after>module Neo4j

  class << self
    extend Forwardable

    ##
    # Returns the current version of the database.
    # This version has been set by running one or more migrations.
    # The version is stored on the reference node, with property 'db_version'
    # (Delegates to the Reference Node that includes the MigrationMixin.)
    #
    # === See Also
    # Neo4j::MigrationMixin#db_version
    #
    # :singleton-method: db_version

    ##
    # Force Neo4j.rb to perform migrations
    #
    # === See Also
    # Neo4j::MigrationMixin#migrate!
    #
    # :singleton-method: migrate!

    ##
    # Specifies a single migration.
    #
    # === Example
    # Notice that the reference node is the context in the up and down blocks.
    #
    #   Neo4j.migration 1, :create_articles do
    #    up do
    #      rels.outgoing(:colours) << Neo4j.new :colour => 'red'  << Neo4j.new :colour => 'blue'
    #    end
    #    down do
    #      rels.outgoing(:colours).each {|n| n.del }
    #    end
    #  end
    #
    # === See Also
    # Neo4j::MigrationMixin::ClassMethods#migration
    # Neo4j::ReferenceNode
    #
    # :singleton-method: migration

    ##
    # Returns all migrations that has been defined.
    #
    # === See Also
    # Neo4j::MigrationMixin::ClassMethods#migrations
    #
    # :singleton-method: migrations

    def_delegators :@ref_node, :db_version, :migrate!
    def_delegators Neo4j::ReferenceNode, :migration, :migrations



    # Starts neo4j unless it is not already started.
    # Before using neo4j it has to be started and the location of the Neo database on the file system must
    # have been configured, Neo4j::Config[:storage_path]. You do not have to call this method since
    # neo4j will be started automatically when needed.
    # Registers an at_exit handler that stops neo4j (see Neo4j::stop)
    #
    # === Parameters
    # neo_instance:: optional, an instance of org.neo4j.graphdb.GraphDatabaseService
    #
    # === Examples
    #   Neo4j::Config[:storage_path] = '/var/neo4j-db'
    #   Neo4j.start
    #
    # === Returns
    # nil
    #
    def start(neo_instance=nil)
      return if running?
      at_exit do
        Neo4j.stop
      end
      @neo = neo_instance || org.neo4j.kernel.EmbeddedGraphDatabase.new(Neo4j::Config[:storage_path])
      @ref_node = Neo4j::Transaction.run do
        ReferenceNode.new(@neo.getReferenceNode())
      end

      Neo4j::Transaction.run do
        Neo4j.event_handler.neo_started(self)
      end

      Neo4j::Transaction.run { @ref_node.migrate!}
      nil
    end

    # Return the org.neo4j.kernel.EmbeddedGraphDatabase
    #
    #
    def instance
      start unless running?
      @neo
    end

    # Stops the current instance unless it is not started.
    #
    def stop
      if running?
        Neo4j::Transaction.finish # just in case
        @neo.shutdown
        Neo4j.event_handler.neo_stopped(self)
      end
      @neo = nil
    end

    #
    # Returns true if neo4j is running
    #
    def running?
      !@neo.nil?
    end


    # Create a Neo4j::Node
    # This is the same as Neo4j::Node.new.
    # All nodes are created by this method
    def create_node(props = {}) # :nodoc:
      node = instance.createNode
      props.each_pair{|k,v| node[k] = v}
      node
    end

    # Creates a new Relationship
    # All relationships are created by this method.
    def create_rel(type, from_node, to_node, props = {}) # :nodoc:
      rel = from_node.add_rel(type, to_node)
      props.each_pair {|k,v| rel[k] = v}
      rel
    end

    # Return a Neo4j node.
    #
    # ==== Parameters
    # node_id:: the unique neo id for one node, should respond to 'to_i'
    # raw:: if the raw Java node object should be returned or the Ruby wrapped node, default false.
    #
    # ==== Returns
    # The node object or nil if not found
    #
    def load_node(node_id, raw = false)
      neo_node = @neo.getNodeById(node_id.to_i)
      if (raw)
        neo_node
       else
        neo_node.wrapper
      end
    rescue org.neo4j.graphdb.NotFoundException
      nil
    end


    # Return a Neo4j relationship.
    #
    # ==== Parameters
    # rel_id<String, to_i>:: the unique neo id for one node
    # raw<true|false(default)> :: if the raw Java relationship object should be returned or the Ruby wrapped node.
    #
    # ==== Returns
    # The node object or nil if not found
    #
    def load_rel(rel_id, raw = false)
      neo_rel = @neo.getRelationshipById(rel_id.to_i)
      if (raw)
        neo_rel
      else
        neo_rel.wrapper
      end
    rescue org.neo4j.graphdb.NotFoundException
{'fraction_non_alphanumeric': 0.09518150388936905, 'fraction_numerical': 0.008426966292134831, 'mean_word_length': 2.3370583994232157, 'pattern_counts': {'":': 0, '<': 21, '<?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': '5784188', 'n_tokens_mistral': 3061, 'n_tokens_neox': 2961, 'n_words': 848}