<commit_before>require 'rdf/isomorphic'
require 'set'

module Spira
  module Resource

    ##
    # This module contains instance methods for Spira resources.  See
    # {Spira::Resource} for more information.
    #
    # @see Spira::Resource
    # @see Spira::Resource::ClassMethods
    # @see Spira::Resource::DSL
    # @see Spira::Resource::Validations
    module InstanceMethods

      # Marker for whether or not a field has been set or not; distinguishes
      # nil and unset.
      # @private
      NOT_SET = ::Object.new.freeze

      ##
      # This instance's URI.
      #
      # @return [RDF::URI]
      attr_reader :subject

      ## 
      # Initialize a new Spira::Resource instance of this resource class using
      # a new blank node subject.  Accepts a hash of arguments for initial
      # attributes.  To use a URI or existing blank node as a subject, use
      # {Spira::Resource::ClassMethods#for} instead.
      #
      # @param [Hash{Symbol => Any}] opts Default attributes for this instance
      # @yield [self] Executes a given block and calls `#save!`
      # @yieldparam [self] self The newly created instance
      # @see Spira::Resource::ClassMethods#for
      # @see RDF::URI#as
      # @see RDF::Node#as
      def initialize(opts = {})
        @subject = opts[:_subject] || RDF::Node.new
        reload(opts)
        if block_given?
          yield(self)
          save!
        end
        self
      end
  
      ##
      # Reload all attributes for this instance, overwriting or setting
      # defaults with the given opts.  This resource will block if the
      # underlying repository blocks the next time it accesses attributes.
      #
      # @param   [Hash{Symbol => Any}] opts
      # @option opts [Symbol] :any A property name.  Sets the given property to the given value.
      def reload(opts = {})
        @cache = opts[:_cache] || RDF::Util::Cache.new
        @cache[subject] = self
        @dirty = {}
        @attributes = {}
        @attributes[:current] = {}
        @attributes[:copied] = {}
        self.class.properties.each do |name, predicate|
          case opts[name].nil?
            when false
              attribute_set(name, opts[name])
            when true
              @attributes[:copied][name] = NOT_SET
          end
        end
        @attributes[:original] = promise { reload_attributes }<commit_msg>no need to return self from "initialize"<commit_after>require 'rdf/isomorphic'
require 'set'

module Spira
  module Resource

    ##
    # This module contains instance methods for Spira resources.  See
    # {Spira::Resource} for more information.
    #
    # @see Spira::Resource
    # @see Spira::Resource::ClassMethods
    # @see Spira::Resource::DSL
    # @see Spira::Resource::Validations
    module InstanceMethods

      # Marker for whether or not a field has been set or not; distinguishes
      # nil and unset.
      # @private
      NOT_SET = ::Object.new.freeze

      ##
      # This instance's URI.
      #
      # @return [RDF::URI]
      attr_reader :subject

      ## 
      # Initialize a new Spira::Resource instance of this resource class using
      # a new blank node subject.  Accepts a hash of arguments for initial
      # attributes.  To use a URI or existing blank node as a subject, use
      # {Spira::Resource::ClassMethods#for} instead.
      #
      # @param [Hash{Symbol => Any}] opts Default attributes for this instance
      # @yield [self] Executes a given block and calls `#save!`
      # @yieldparam [self] self The newly created instance
      # @see Spira::Resource::ClassMethods#for
      # @see RDF::URI#as
      # @see RDF::Node#as
      def initialize(opts = {})
        @subject = opts[:_subject] || RDF::Node.new
        reload(opts)
        if block_given?
          yield(self)
          save!
        end
      end
  
      ##
      # Reload all attributes for this instance, overwriting or setting
      # defaults with the given opts.  This resource will block if the
      # underlying repository blocks the next time it accesses attributes.
      #
      # @param   [Hash{Symbol => Any}] opts
      # @option opts [Symbol] :any A property name.  Sets the given property to the given value.
      def reload(opts = {})
        @cache = opts[:_cache] || RDF::Util::Cache.new
        @cache[subject] = self
        @dirty = {}
        @attributes = {}
        @attributes[:current] = {}
        @attributes[:copied] = {}
        self.class.properties.each do |name, predicate|
          case opts[name].nil?
            when false
              attribute_set(name, opts[name])
            when true
              @attributes[:copied][name] = NOT_SET
          end
        end
        @attributes[:original] = promise { reload_attributes }
{'fraction_non_alphanumeric': 0.10067114093959731, 'fraction_numerical': 0.0, 'mean_word_length': 2.239809782608696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6945170', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1309, 'n_words': 437}