<commit_before>class ResourceNetwork < ActiveRecord::Base
  self.inheritance_column = "inheritance_type"

  TYPE_GIFTER_AND_POSSESSOR = 10.freeze
  TYPE_GIFTER = 20.freeze
  TYPE_POSSESSOR = 30.freeze
  TYPES = {
    TYPE_GIFTER_AND_POSSESSOR => "Gifter and Possessor",
    TYPE_GIFTER => "Gifter",
    TYPE_POSSESSOR => "Possessor"
  }

  validates_presence_of :type

   scope :item, lambda { |entity| where("resource_type_id =? AND resource_id = ?", 2, entity.id) }
   scope :entity, lambda { |entity| where("entity_id =? AND entity_type_id = ?", entity.id, 1) }

   def set_possessor!(entity, entity_type_id)
     self.entity_id = entity.id
     self.entity_type_id = entity_type_id
     self.type = TYPE_GIFTER
     save!
   end

   def remove_possessor!
     self.entity_id = nil
     self.type = TYPE_GIFTER_AND_POSSESSOR
     save!
   end<commit_msg>Added gifter and requester related methods, and scopes<commit_after>class ResourceNetwork < ActiveRecord::Base
  self.inheritance_column = "inheritance_type"

  TYPE_GIFTER_AND_POSSESSOR = 10.freeze
  TYPE_GIFTER = 20.freeze
  TYPE_POSSESSOR = 30.freeze
  TYPES = {
    TYPE_GIFTER_AND_POSSESSOR => "Gifter and Possessor",
    TYPE_GIFTER => "Gifter",
    TYPE_POSSESSOR => "Possessor"
  }

  validates_presence_of :type

   scope :item, lambda { |entity| where("resource_type_id =? AND resource_id = ?", 2, entity.id) }
   scope :entity, lambda { |entity| where("entity_id =? AND entity_type_id = ?", entity.id, 1) }
   scope :gifter, :conditions => { :type => TYPE_GIFTER }
   scope :possessor, :conditions => { :type => TYPE_POSSESSOR }
   scope :gifter_possessor, :conditions => { :type => TYPE_GIFTER_AND_POSSESSOR }

   def set_possessor!(entity, entity_type_id)
     self.entity_id = entity.id
     self.entity_type_id = entity_type_id
     self.type = TYPE_GIFTER
     save!
   end

   def remove_possessor!
     self.entity_id = nil
     self.type = TYPE_GIFTER_AND_POSSESSOR
     save!
   end

   def to_gifter!
     self.type = TYPE_GIFTER
     save!
   end

   def to_possessor!
     self.type = TYPE_POSSESSOR
     save!
   end

   def to_gifter_and_possessor!
     self.type = TYPE_GIFTER_AND_POSSESSOR
     save!
   end
{'fraction_non_alphanumeric': 0.09812870835235052, 'fraction_numerical': 0.00730260155180283, 'mean_word_length': 3.5762004175365343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '641870', 'n_tokens_mistral': 846, 'n_tokens_neox': 811, 'n_words': 157}