Class: SPARQL::Algebra::Operator::Min

Inherits:
Unary show all
Includes:
Aggregate
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/min.rb

Overview

The SPARQL min set function.

Examples:

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

See Also:

Constant Summary

NAME =
:min

Constants inherited from Unary

Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Aggregate

#aggregate, #replace_aggregate!, #replace_vars!

Methods inherited from Unary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Unary

Instance Method Details

#apply(enum) ⇒ RDF::Literal

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.

Parameters:

Returns:



27
28
29
30
31
32
33
34
35
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/min.rb', line 27

def apply(enum)
  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