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-796d3be4aa08/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
-
#aggregate(solutions = [], **options) ⇒ RDF::Term
abstract
Aggregates this operator accross its operands using a solutions enumerable.
- #apply(enum, **options) ⇒ RDF::Term abstract
-
#replace_aggregate! {|agg| ... } ⇒ RDF::Query::Variable
Replace ourselves with a variable returned from the block.
-
#replace_vars!(&block) ⇒ SPARQL::Algebra::Evaluatable
This is a no-op for Aggregates.
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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/aggregate.rb', line 27 def aggregate(solutions = [], **) operands.shift if distinct = (operands.first == :distinct) args_enum = solutions.map do |solution| operands.map do |operand| begin operand.evaluate(solution, **.merge(depth: [: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.
47 48 49 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/aggregate.rb', line 47 def apply(enum, **) 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
66 67 68 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/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.
55 56 57 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/aggregate.rb', line 55 def replace_vars!(&block) self end |