<commit_before>require 'dbd/helpers/ordered_set_collection'

module Dbd
  class Fact
    module Collection

      include Helpers::OrderedSetCollection

      def initialize
        super
        @hash_by_subject = Hash.new { |h, k| h[k] = [] }
        @used_provenance_subjects = {}
      end

      def newest_time_stamp
        newest_entry = @internal_collection.last
        newest_entry && newest_entry.time_stamp
      end

      def oldest_time_stamp
        oldest_entry = @internal_collection.first
        oldest_entry && oldest_entry.time_stamp
      end

      ##
      # This is the central method of Fact::Collection module
      #
      # @param [Fact] Fact the fact that is added to the collection
      #
      # @return [self] for chaining
      #
      # Validates that added fact is valid.
      #
      # Validates that added fact is newer.
      #
      # Validates that subject was never used as provenance_subject [A].
      #
      # Adds the fact and return the index in the collection.
      #
      # Store this index in the hash_by_subject.
      #
      # Mark the fact in the list of used provenance_subjects (for [A]).
      def <<(fact)
        raise FactError unless fact.valid?
        raise OutOfOrderError if (self.newest_time_stamp && fact.time_stamp <= self.newest_time_stamp)
        raise OutOfOrderError if (@used_provenance_subjects[fact.subject])
        index = Helpers::OrderedSetCollection.add_and_return_index(fact, @internal_collection)
        @hash_by_subject[fact.subject] << index
        fact.update_used_provenance_subjects(@used_provenance_subjects)
        self
      end

      def by_subject(fact_subject)
        @hash_by_subject[fact_subject].map{ |index| @internal_collection[index]}
      end

    end
  end
end
<commit_msg>Fix an @arg name in the documentation<commit_after>require 'dbd/helpers/ordered_set_collection'

module Dbd
  class Fact
    module Collection

      include Helpers::OrderedSetCollection

      def initialize
        super
        @hash_by_subject = Hash.new { |h, k| h[k] = [] }
        @used_provenance_subjects = {}
      end

      def newest_time_stamp
        newest_entry = @internal_collection.last
        newest_entry && newest_entry.time_stamp
      end

      def oldest_time_stamp
        oldest_entry = @internal_collection.first
        oldest_entry && oldest_entry.time_stamp
      end

      ##
      # This is the central method of Fact::Collection module
      #
      # @param [Fact] fact the fact that is added to the collection
      #
      # @return [self] for chaining
      #
      # Validates that added fact is valid.
      #
      # Validates that added fact is newer.
      #
      # Validates that subject was never used as provenance_subject [A].
      #
      # Adds the fact and return the index in the collection.
      #
      # Store this index in the hash_by_subject.
      #
      # Mark the fact in the list of used provenance_subjects (for [A]).
      def <<(fact)
        raise FactError unless fact.valid?
        raise OutOfOrderError if (self.newest_time_stamp && fact.time_stamp <= self.newest_time_stamp)
        raise OutOfOrderError if (@used_provenance_subjects[fact.subject])
        index = Helpers::OrderedSetCollection.add_and_return_index(fact, @internal_collection)
        @hash_by_subject[fact.subject] << index
        fact.update_used_provenance_subjects(@used_provenance_subjects)
        self
      end

      def by_subject(fact_subject)
        @hash_by_subject[fact_subject].map{ |index| @internal_collection[index]}
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.07194444444444445, 'fraction_numerical': 0.0, 'mean_word_length': 2.5269343780607247, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6856658', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1059, 'n_words': 282}