Module: SPARQL::Algebra::Aggregate Abstract

Included in:
Operator::Avg, Operator::Count, Operator::GroupConcat, Operator::Max, Operator::Min, Operator::Sample, Operator::Sum
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/aggregate.rb

Overview

This module is abstract.

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.

Instance Method Summary collapse

Instance Method Details

#aggregate(solutions = [], **options) ⇒ RDF::Term

This method is abstract.

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.

Parameters:

Returns:

Raises:

  • (TypeError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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, **options.merge(depth: options[:depth].to_i + 1))
      rescue TypeError
        # Ignore errors
        nil
      end
    end.compact
  end
  apply(distinct ? args_enum.uniq : args_enum)
end

#apply(enum, **options) ⇒ RDF::Term

This method is abstract.

Parameters:

Returns:

Raises:

  • (NotImplementedError)


47
48
49
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/aggregate.rb', line 47

def apply(enum, **options)
  raise NotImplementedError, "#{self.class}#apply(#{operands.map(&:class).join(', ')})"
end

#replace_aggregate! {|agg| ... } ⇒ RDF::Query::Variable

Replace ourselves with a variable returned from the block

Yields:

  • agg

Yield Parameters:

Yield Returns:

Returns:



66
67
68
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/aggregate.rb', line 66

def replace_aggregate!(&block)
  yield self
end

#replace_vars!(&block) ⇒ SPARQL::Algebra::Evaluatable

This is a no-op for Aggregates.

Returns:



55
56
57
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/aggregate.rb', line 55

def replace_vars!(&block)
  self
end