class SPARQL::Algebra::Operator::Min

The SPARQL `min` set function.

@example

(prefix ((: <http://www.example.org/>))
  (project (?max)
    (extend ((?min ??.0))
      (group () ((??.0 (min ?o)))
        (bgp (triple ?s ?p ?o))))))

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

Constants

NAME

Public Class Methods

new(*operands, **options) click to toggle source
Calls superclass method SPARQL::Algebra::Operator::new
# File lib/sparql/algebra/operator/min.rb, line 19
def initialize(*operands, **options)
  raise ArgumentError,
    "min operator accepts at most one argument with an optional :distinct" if
    (operands - %i{distinct}).length != 1
  super
end

Public Instance Methods

apply(enum, **options) click to toggle source

Min is a SPARQL set function that return the minimum value from a group respectively.

It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.

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

enum of evaluated operand

@return [RDF::Literal] The maximum value of the terms

# File lib/sparql/algebra/operator/min.rb, line 34
def apply(enum, **options)
  # FIXME: we don't actually do anything with distinct
  operands.shift if distinct = (operands.first == :distinct)
  if enum.empty?
    raise TypeError, "Minumuim of an empty multiset"
  elsif enum.flatten.all? {|n| n.literal?}
    RDF::Literal(enum.flatten.min)
  else
    raise TypeError, "Minumuim of non-literals: #{enum.flatten}"
  end
end