Sha256: e340711847e992f0408b0428cef64e0f5931e5f0d66d25d99405104bd3ae521e

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL `bound` operator.
    #
    # @example
    #   (prefix ((: <http://example.org/ns#>))
    #     (project (?a ?c)
    #       (filter (! (bound ?e))
    #         (leftjoin
    #           (bgp (triple ?a :b ?c))
    #           (bgp (triple ?c :d ?e))))))
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-bound
    class Bound < Operator::Unary
      include Evaluatable

      NAME = :bound

      ##
      # Initializes a new operator instance.
      #
      # @param  [RDF::Query::Variable] var
      #   a variable
      # @param  [Hash{Symbol => Object}] options
      #   any additional options (see {Operator#initialize})
      # @raise  [TypeError] if any operand is invalid
      def initialize(var, **options)
        super
      end

      ##
      # Returns `true` if `var` is bound to a value. Returns false otherwise. Variables with the value NaN or INF are considered bound.
      #
      # @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 operand is not a variable
      def evaluate(bindings, **options)
        case var = operand
          when Variable
            bindings.respond_to?(:bound?) && bindings.bound?(var) ?
              RDF::Literal::TRUE : RDF::Literal::FALSE
          else raise TypeError, "expected an RDF::Query::Variable, but got #{var.inspect}"
        end
      end
    end # Bound
  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/bound.rb