Sha256: b32e5706093fdcc240ec15b689010c2c415b1c1f0643cb6da34a88066c2646a4

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL GraphPattern `exprlist` operator.
    #
    # Used for filters with more than one expression.
    #
    # @example
    #   (prefix ((: <http://example/>))
    #     (project (?v ?w)
    #       (filter (exprlist (= ?v 2) (= ?w 3))
    #         (bgp
    #           (triple ?s :p ?v)
    #           (triple ?s :q ?w)
    #         ))))
    #
    # @see http://www.w3.org/TR/sparql11-query/#evaluation
    class Exprlist < Operator
      include Evaluatable

      NAME = [:exprlist]

      ##
      # Returns `true` if all operands evaluate to `true`.
      #
      # Note that this operator operates on the effective boolean value
      # (EBV) of its operands.
      #
      # @example
      #
      #   (exprlist (= 1 1) (!= 1 0))
      #
      # @param  [RDF::Query::Solution] bindings
      #   a query solution containing zero or more variable bindings
      # @param [Hash{Symbol => Object}] options ({})
      #   options passed from query
      # @return [RDF::Literal::Boolean] `true` or `false`
      # @raise  [TypeError] if the operands could not be coerced to a boolean literal
      def evaluate(bindings, options = {})
        res = operands.all? {|op| boolean(op.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))).true? }
        RDF::Literal(res) # FIXME: error handling
      end

      ##
      # Returns an optimized version of this query.
      #
      # Return optimized query
      #
      # @return [Union, RDF::Query] `self`
      def optimize
        operands = operands.map(&:optimize)
      end
    end # Exprlist
  end # Operator
end; end # SPARQL::Algebra

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sparql-3.0.2 lib/sparql/algebra/operator/exprlist.rb
sparql-3.0.1 lib/sparql/algebra/operator/exprlist.rb
sparql-3.0.0 lib/sparql/algebra/operator/exprlist.rb
sparql-2.2.2 lib/sparql/algebra/operator/exprlist.rb
sparql-2.2.1 lib/sparql/algebra/operator/exprlist.rb
sparql-2.2.0 lib/sparql/algebra/operator/exprlist.rb
sparql-2.1.0 lib/sparql/algebra/operator/exprlist.rb
sparql-2.0.0 lib/sparql/algebra/operator/exprlist.rb
sparql-2.0.0.beta2 lib/sparql/algebra/operator/exprlist.rb
sparql-2.0.0.beta1 lib/sparql/algebra/operator/exprlist.rb