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

Inherits:
Unary show all
Includes:
Evaluatable
Defined in:
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

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, #inspect, #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?

Constructor Details

#initialize(var, **options) ⇒ Bound

Initializes a new operator instance.

Parameters:

Raises:

  • (TypeError)

    if any operand is invalid



40
41
42
# File '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:

  • bindings (RDF::Query::Solution)

    a query solution containing zero or more variable bindings

  • options (Hash{Symbol => Object})

    ({}) options passed from query

Returns:

  • (RDF::Literal::Boolean)

    true or false

Raises:

  • (TypeError)

    if the operand is not a variable



53
54
55
56
57
58
59
60
# File '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:

  • (String)


67
68
69
# File 'lib/sparql/algebra/operator/bound.rb', line 67

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