<commit_before>module RDF
  ##
  # An RDF blank node, also known as an anonymous or unlabeled node.
  #
  # @example Creating a blank node with an implicit identifier
  #   bnode = RDF::Node.new
  #
  # @example Creating a blank node with an UUID identifier
  #   bnode = RDF::Node.uuid
  #   bnode.to_s #=> "_:504c0a30-0d11-012d-3f50-001b63cac539"
  #
  # @see http://rubygems.org/gems/uuid
  # @see http://rubygems.org/gems/uuidtools
  class Node
    include RDF::Resource

    ##
    # Returns a blank node with a random UUID-based identifier.
    #
    # @return [RDF::Node]
    def self.uuid
      begin
        require 'uuid'
          begin
            uuid = UUID.generate(:compact)
          end until (uuid =~ /^[a-zA-Z][a-zA-Z0-9]*/)
        self.new(uuid)
      rescue LoadError => e
        begin
          require 'uuidtools'
          begin
            uuid = UUIDTools::UUID.random_create.hexdigest
          end until (uuid =~ /^[a-zA-Z][a-zA-Z0-9]*/)
          self.new(uuid)
        rescue LoadError => e
          raise LoadError.new("no such file to load -- uuid or uuidtools")
        end
      end
    end

    ##
    # Alias for `RDF::Node.new`, at the moment.
    #
    # @private
    # @param  [#to_s] id
    # @return [RDF::Node]
    # @since  0.2.0
    def self.intern(id)
      self.new(id)
    end

    # @return [String]
    attr_accessor :id

    ##
    # @param  [#to_s] id
    def initialize(id = nil)
      @id = (id || "g#{__id__.to_i.abs}").to_s
    end

    ##
    # Returns `true`.
    #
    # @return [Boolean]
    def node?
      true
    end

    ##
    # Returns `true`.
    #
    # @return [Boolean]
    def anonymous?
      true
    end

    alias_method :unlabeled?, :anonymous?

    ##
    # Returns `false`.
    #
    # @return [Boolean]
    def labeled?
      !unlabeled?
    end

    ##
    # Returns a hash code for this blank node.
    #
    # @return [Fixnum]
    def hash
      @id.hash
    end

    ##
    # Checks whether this blank node is equal to `other`.
    #
    # @param  [Node] other
    # @return [Boolean]
    def eql?(other)
      other.is_a?(Node) && self == other
    end

    ##
    # Checks whether this blank node is equal to `other`.
    #
    # @param  [Object] other
    # @return [Boolean]
    def ==(other)
      other.respond_to?(:node?) && other.node? &&
        other.respond_to?(:id) && @id == other.id
    end

    ##
    # Returns a string representation of this blank node.
    #
    # @return [String]
    def to_s
      "_:%s" % @id.to_s
    end

    ##
    # Returns a symbol representation of this blank node.
    #
    # @return [Symbol]
    # @since  0.2.0
    def to_sym
      @id.to_s.to_sym
    end
  end
end
<commit_msg>Rewrote the RDF::Node.uuid method to make use of RDF::Util::UUID.generate (#43).<commit_after>module RDF
  ##
  # An RDF blank node, also known as an anonymous or unlabeled node.
  #
  # @example Creating a blank node with an implicit identifier
  #   bnode = RDF::Node.new
  #
  # @example Creating a blank node with an UUID identifier
  #   bnode = RDF::Node.uuid
  #   bnode.to_s #=> "_:504c0a30-0d11-012d-3f50-001b63cac539"
  #
  class Node
    include RDF::Resource

    ##
    # Returns a blank node with a random UUID-based identifier.
    #
    # @param  [Hash{Symbol => Object}] options
    # @option options [Regexp] :grammar (nil)
    #   a grammar specification that the generated UUID must match
    # @return [RDF::Node]
    def self.uuid(options = {})
      case
        when options[:grammar]
          # The UUID is generated such that its initial part is guaranteed
          # to match the given `grammar`, e.g. `/^[A-Za-z][A-Za-z0-9]*/`.
          # Some RDF storage systems (e.g. AllegroGraph) require this.
          # @see http://github.com/bendiken/rdf/pull/43
          uuid = RDF::Util::UUID.generate(options) until uuid =~ options[:grammar]
          uuid
        else
          uuid = RDF::Util::UUID.generate(options)
      end
    end

    ##
    # Alias for `RDF::Node.new`, at the moment.
    #
    # @private
    # @param  [#to_s] id
    # @return [RDF::Node]
    # @since  0.2.0
    def self.intern(id)
      self.new(id)
    end

    # @return [String]
    attr_accessor :id

    ##
    # @param  [#to_s] id
    def initialize(id = nil)
      @id = (id || "g#{__id__.to_i.abs}").to_s
    end

    ##
    # Returns `true`.
    #
    # @return [Boolean]
    def node?
      true
    end

    ##
    # Returns `true`.
    #
    # @return [Boolean]
    def anonymous?
      true
    end

    alias_method :unlabeled?, :anonymous?

    ##
    # Returns `false`.
    #
    # @return [Boolean]
    def labeled?
      !unlabeled?
    end

    ##
    # Returns a hash code for this blank node.
    #
    # @return [Fixnum]
    def hash
      @id.hash
    end

    ##
    # Checks whether this blank node is equal to `other`.
    #
    # @param  [Node] other
    # @return [Boolean]
    def eql?(other)
      other.is_a?(Node) && self == other
    end

    ##
    # Checks whether this blank node is equal to `other`.
    #
    # @param  [Object] other
    # @return [Boolean]
    def ==(other)
      other.respond_to?(:node?) && other.node? &&
        other.respond_to?(:id) && @id == other.id
    end

    ##
    # Returns a string representation of this blank node.
    #
    # @return [String]
    def to_s
      "_:%s" % @id.to_s
    end

    ##
    # Returns a symbol representation of this blank node.
    #
    # @return [Symbol]
    # @since  0.2.0
    def to_sym
      @id.to_s.to_sym
    end
  end
end

{'fraction_non_alphanumeric': 0.12878242074927954, 'fraction_numerical': 0.012247838616714697, 'mean_word_length': 1.8982254697286012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6398717', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1934, 'n_words': 519}