Sha256: 98052203baf6b5f143d22c5686f0906ecb37ec993b89d2b39b5e54518aac7992

Contents?: true

Size: 1.65 KB

Versions: 15

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/rdf-sparql-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 the operand is a variable that is bound to a
      # value in the given `bindings`, `false` otherwise.
      #
      # @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

15 entries across 15 versions & 1 rubygems

Version Path
sparql-1.99.1 lib/sparql/algebra/operator/bound.rb
sparql-1.1.9.1 lib/sparql/algebra/operator/bound.rb
sparql-1.99.0 lib/sparql/algebra/operator/bound.rb
sparql-1.1.9 lib/sparql/algebra/operator/bound.rb
sparql-1.1.8 lib/sparql/algebra/operator/bound.rb
sparql-1.1.7 lib/sparql/algebra/operator/bound.rb
sparql-1.1.6 lib/sparql/algebra/operator/bound.rb
sparql-1.1.5 lib/sparql/algebra/operator/bound.rb
sparql-1.1.4 lib/sparql/algebra/operator/bound.rb
sparql-1.1.3 lib/sparql/algebra/operator/bound.rb
sparql-1.1.2.1 lib/sparql/algebra/operator/bound.rb
sparql-1.1.2 lib/sparql/algebra/operator/bound.rb
sparql-1.1.1 lib/sparql/algebra/operator/bound.rb
sparql-1.1.0 lib/sparql/algebra/operator/bound.rb
sparql-1.1.0p0 lib/sparql/algebra/operator/bound.rb