Class: SPARQL::Algebra::Operator::Bound

Inherits:
Unary show all
Includes:
Evaluatable
Defined in:
lib/sparql/algebra/operator/bound.rb

Overview

The SPARQL bound operator.

Examples:

(prefix ((: <http://example.org/ns#>))
  (project (?a ?c)
    (filter (! (bound ?e))
      (leftjoin
        (bgp (triple ?a :b ?c))
        (bgp (triple ?c :d ?e))))))

See Also:

Constant Summary

NAME =
:bound

Constants inherited from Unary

Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary collapse

Methods included from Evaluatable

#apply, #memoize

Methods inherited from SPARQL::Algebra::Operator

arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #inspect, #operand, #optimize, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?

Methods included from Expression

cast, #constant?, for, new, open, #optimize, parse, #to_sse, #variable?

Constructor Details

#initialize(var, options = {}) ⇒ Bound

Initializes a new operator instance.

Parameters:

Raises:

  • (TypeError)

    if any operand is invalid



28
29
30
# File 'lib/sparql/algebra/operator/bound.rb', line 28

def initialize(var, options = {})
  super
end

Instance Method Details

#evaluate(bindings = {}) ⇒ RDF::Literal::Boolean

Returns true if the operand is a variable that is bound to a value in the given bindings, false otherwise.

Parameters:

  • bindings (RDF::Query::Solution, #[]) (defaults to: {})

Returns:

  • (RDF::Literal::Boolean)

    true or false

Raises:

  • (TypeError)

    if the operand is not a variable



39
40
41
42
43
44
45
# File 'lib/sparql/algebra/operator/bound.rb', line 39

def evaluate(bindings = {})
  case var = operand
    when Variable
      operand.evaluate(bindings) ? RDF::Literal::TRUE : RDF::Literal::FALSE
    else raise TypeError, "expected an RDF::Query::Variable, but got #{var.inspect}"
  end
end