Sha256: 669c13947cf8502009614e4365d07c1bc7286ac3d1bfa4bee0db860af44d29ca

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # 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 http://www.w3.org/TR/sparql11-query/#defn_aggMin
    class Min < Operator
      include Aggregate

      NAME = :min

      ##
      # 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
      def apply(enum)
        # 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
    end # Min
  end # Operator
end; end # SPARQL::Algebra

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sparql-3.1.0 lib/sparql/algebra/operator/min.rb