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

Inherits:
Unary show all
Includes:
Evaluatable
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/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, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Evaluatable

#apply, #memoize, #replace_aggregate!, #replace_vars!

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #inspect, #ndvars, #node?, #operand, #optimize, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

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

Initializes a new operator instance.

Parameters:

Raises:

  • (TypeError)

    if any operand is invalid



28
29
30
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/bound.rb', line 28

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

Instance Method Details

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

Returns true if var is bound to a value. Returns false otherwise. Variables with the value NaN or INF are considered bound.

Parameters:

  • bindings (RDF::Query::Solution)

    a query solution containing zero or more variable bindings

  • options (Hash{Symbol => Object}) (defaults to: {})

    ({}) options passed from query

Returns:

Raises:

  • (TypeError)

    if the operand is not a variable



41
42
43
44
45
46
47
48
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/bound.rb', line 41

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