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

Inherits:
Unary show all
Includes:
Evaluatable
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bound.rb

Overview

The SPARQL bound operator.

[121] BuiltInCall ::= ... | 'BOUND' '(' Var ')'

Examples:

SPARQL Grammar

PREFIX  : <http://example.org/ns#>
SELECT  ?a ?c
WHERE
    { ?a :b ?c . 
      OPTIONAL
        { ?c :d ?e } . 
      FILTER (! bound(?e)) 
    }

SSE

(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 collapse

NAME =
:bound

Constants inherited from Unary

Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Constants included from Expression

Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

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=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #formulae, #inspect, #mergable?, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from Expression

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

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Constructor Details

#initialize(var, **options) ⇒ Bound

Initializes a new operator instance.

Parameters:

Raises:

  • (TypeError)

    if any operand is invalid



40
41
42
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bound.rb', line 40

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:

Returns:

Raises:

  • (TypeError)

    if the operand is not a variable



53
54
55
56
57
58
59
60
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bound.rb', line 53

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

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:



67
68
69
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bound.rb', line 67

def to_sparql(**options)
  "bound(" + operands.first.to_sparql(**options) + ")"
end