<commit_before>module RDF
  ##
  # An RDF basic graph pattern query.
  #
  # @example Filtering solutions using a hash
  #   query.filter(:author  => RDF::URI.new("http://ar.to/#self"))
  #   query.filter(:author  => "<NAME>")
  #   query.filter(:author  => [RDF::URI.new("http://ar.to/#self"), "<NAME>"])
  #   query.filter(:updated => RDF::Literal.new(Date.today))
  #
  # @example Filtering solutions using a block
  #   query.filter { |solution| solution.author.literal? }
  #   query.filter { |solution| solution.title =~ /^SPARQL/ }
  #   query.filter { |solution| solution.price < 30.5 }
  #   query.filter { |solution| solution.bound?(:date) }
  #   query.filter { |solution| solution.age.datatype == RDF::XSD.integer }
  #   query.filter { |solution| solution.name.language == :es }
  #
  # @example Reordering solutions based on a variable
  #   query.order_by(:updated)
  #   query.order_by(:updated, :created)
  #
  # @example Selecting particular variables only
  #   query.select(:title)
  #   query.select(:title, :description)
  #
  # @example Eliminating duplicate solutions
  #   query.distinct!
  #
  # @example Limiting the number of solutions
  #   query.offset(25).limit(10)
  #
  # @example Counting the number of solutions
  #   query.count
  #
  # @example Iterating over all found solutions
  #   query.each_solution { |solution| puts solution.inspect }
  #
  class Query
    autoload :Pattern,  'rdf/query/pattern'
    autoload :Solution, 'rdf/query/solution'
    autoload :Variable, 'rdf/query/variable'

    include ::Enumerable

    # @return [Hash{Symbol => RDF::Query::Variable}]
    attr_reader :variables

    # @return [Array<RDF::Query::Pattern>]
    attr_reader :patterns

    # @return [Array<Hash{Symbol => RDF::Value}>] An unordered sequence of query solutions.
    attr_accessor :solutions

    # @return [Hash]
    attr_reader :options

    ##
    # @param  [Hash{Symbol => Object}] options
    # @yield  [query]
    # @yieldparam [Query]
    def initialize(options = {}, &block)
      @options   = options.dup
      @variables = @options.delete(:variables) || {}
      @patterns  = @options.delete(:patterns)  || []
      @solutions = @options.delete(:solutions) || []

      if block_given?
        case block.arity
          when 1 then block.call(self)
          else instance_eval(&block)
        end
      end
    end

    ##
    # Enumerates over each query solution.
    #
    # @yield  [solution]
    # @yieldparam [Solution] solution
    # @return [Enumerator]
    def each_solution(&block)
      unless block_given?
        enum_for(:each_solution)
      else
        solutions.each do |solution|
          block.call(solution.is_a?(Solution) ? solution : Solution.new(solution))
        end
      end
    end<commit_msg>Implemented an RDF::Query#<< convenience method.<commit_after>module RDF
  ##
  # An RDF basic graph pattern query.
  #
  # @example Filtering solutions using a hash
  #   query.filter(:author  => RDF::URI.new("http://ar.to/#self"))
  #   query.filter(:author  => "<NAME>")
  #   query.filter(:author  => [RDF::URI.new("http://ar.to/#self"), "<NAME>"])
  #   query.filter(:updated => RDF::Literal.new(Date.today))
  #
  # @example Filtering solutions using a block
  #   query.filter { |solution| solution.author.literal? }
  #   query.filter { |solution| solution.title =~ /^SPARQL/ }
  #   query.filter { |solution| solution.price < 30.5 }
  #   query.filter { |solution| solution.bound?(:date) }
  #   query.filter { |solution| solution.age.datatype == RDF::XSD.integer }
  #   query.filter { |solution| solution.name.language == :es }
  #
  # @example Reordering solutions based on a variable
  #   query.order_by(:updated)
  #   query.order_by(:updated, :created)
  #
  # @example Selecting particular variables only
  #   query.select(:title)
  #   query.select(:title, :description)
  #
  # @example Eliminating duplicate solutions
  #   query.distinct!
  #
  # @example Limiting the number of solutions
  #   query.offset(25).limit(10)
  #
  # @example Counting the number of solutions
  #   query.count
  #
  # @example Iterating over all found solutions
  #   query.each_solution { |solution| puts solution.inspect }
  #
  class Query
    autoload :Pattern,  'rdf/query/pattern'
    autoload :Solution, 'rdf/query/solution'
    autoload :Variable, 'rdf/query/variable'

    include ::Enumerable

    # @return [Hash{Symbol => RDF::Query::Variable}]
    attr_reader :variables

    # @return [Array<RDF::Query::Pattern>]
    attr_reader :patterns

    # @return [Array<Hash{Symbol => RDF::Value}>] An unordered sequence of query solutions.
    attr_accessor :solutions

    # @return [Hash]
    attr_reader :options

    ##
    # @param  [Hash{Symbol => Object}] options
    # @yield  [query]
    # @yieldparam [Query]
    def initialize(options = {}, &block)
      @options   = options.dup
      @variables = @options.delete(:variables) || {}
      @patterns  = @options.delete(:patterns)  || []
      @solutions = @options.delete(:solutions) || []

      if block_given?
        case block.arity
          when 1 then block.call(self)
          else instance_eval(&block)
        end
      end
    end

    ##
    # Inserts a new query `pattern` into this query.
    #
    # @param  [RDF::Query::Pattern] pattern
    # @return [void] self
    def <<(pattern)
      self.patterns << Pattern.from(pattern)
      self
    end

    ##
    # Enumerates over each query solution.
    #
    # @yield  [solution]
    # @yieldparam [Solution] solution
    # @return [Enumerator]
    def each_solution(&block)
      unless block_given?
        enum_for(:each_solution)
      else
        solutions.each do |solution|
          block.call(solution.is_a?(Solution) ? solution : Solution.new(solution))
        end
      end
    end
{'fraction_non_alphanumeric': 0.13766368022053757, 'fraction_numerical': 0.0027567195037904893, 'mean_word_length': 2.8985896574882473, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '5676254', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1829, 'n_words': 411}