<commit_before># encoding: utf-8

module Tripod

  # class that wraps a collection of resources, and allows them to be serialized
  class ResourceCollection

    include Enumerable

    attr_reader :resources

    def initialize(resources)
      @resources = resources
    end

    def each
      self.resources.each { |e| yield(e) }
    end

    # return the underlying array
    def to_a
      resources
    end

    # for n-triples we can just concatenate them
    def to_nt
      nt = ""
      resources.each do |resource|
        nt += resource.to_nt
      end
      nt
    end

    def to_json(opts={})
      get_graph.dump(:jsonld)
    end

    def to_rdf
      get_graph.dump(:rdf)<commit_msg>allow callers of resource_collection some access to underlying array<commit_after># encoding: utf-8

module Tripod

  # class that wraps a collection of resources, and allows them to be serialized
  class ResourceCollection

    include Enumerable

    attr_reader :resources

    def initialize(resources)
      @resources = resources
    end

    def length
      self.resources.length
    end

    def each
      self.resources.each { |e| yield(e) }
    end

    # return the underlying array
    def to_a
      resources
    end

    # allow index operator to act on underlying array of resources.
    def [](*args)
      resources[*args]
    end

    # for n-triples we can just concatenate them
    def to_nt
      nt = ""
      resources.each do |resource|
        nt += resource.to_nt
      end
      nt
    end

    def to_json(opts={})
      get_graph.dump(:jsonld)
    end

    def to_rdf
      get_graph.dump(:rdf)
{'fraction_non_alphanumeric': 0.06392132759680394, 'fraction_numerical': 0.001229256299938537, 'mean_word_length': 2.223762376237624, 'pattern_counts': {'":': 0, '<': 3, '<?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': '226273', 'n_tokens_mistral': 505, 'n_tokens_neox': 469, 'n_words': 161}