module SPARQL::Algebra::Aggregate

A SPARQL algebra aggregate.

Aggregates are for SPARQL set functions. Aggregates take one or more operands which are `Enumerable` lists of `RDF::Term` and return a single `RDF::Term` or `TypeError`.

@see www.w3.org/TR/sparql11-query/#setFunctions @see www.w3.org/TR/sparql11-query/#aggregates

@abstract

Public Instance Methods

aggregate(solutions = [], **options) click to toggle source

Aggregates this operator accross its operands using a solutions enumerable.

The first operand may be :distinct, in which case the result of applying the rest of the operands is uniqued before applying the expression.

@param [Enumerable<RDF::Query::Solution>] solutions ([])

an enumerable set of query solutions

@param [Hash{Symbol => Object}] options ({})

options passed from query

@return [RDF::Term] @raise [TypeError] @abstract

# File lib/sparql/algebra/aggregate.rb, line 27
def aggregate(solutions = [], **options)
  operands.shift if distinct = (operands.first == :distinct)
  args_enum = solutions.map do |solution|
    operands.map do |operand|
      begin
        operand.evaluate(solution, depth: options[:depth].to_i + 1, **options)
      rescue TypeError
        # Ignore errors
        nil
      end
    end.compact
  end
  apply(distinct ? args_enum.uniq : args_enum)
end
apply(enum, **options) click to toggle source

@param [Enumerable<Array<RDF::Term>>] enum

Enumerable yielding evaluated operands

@return [RDF::Term] @abstract

# File lib/sparql/algebra/aggregate.rb, line 47
def apply(enum, **options)
  raise NotImplementedError, "#{self.class}#apply(#{operands.map(&:class).join(', ')})"
end
replace_aggregate!() { |self| ... } click to toggle source

Replace ourselves with a variable returned from the block

@yield agg @yieldparam [SPARQL::Algebra::Aggregate] agg @yieldreturn [RDF::Query::Variable] @return [RDF::Query::Variable] the returned variable

# File lib/sparql/algebra/aggregate.rb, line 66
def replace_aggregate!(&block)
  yield self
end
replace_vars!(&block) click to toggle source

This is a no-op for Aggregates.

@return [SPARQL::Algebra::Evaluatable] self

# File lib/sparql/algebra/aggregate.rb, line 55
def replace_vars!(&block)
  self
end