Class: SPARQL::Algebra::Operator::If
- Inherits:
-
Ternary
- Object
- SPARQL::Algebra::Operator
- Ternary
- SPARQL::Algebra::Operator::If
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/if.rb
Overview
The SPARQL if
function.
[121] BuiltInCall ::= … | ‘IF’ ‘(’ Expression ‘,’ Expression ‘,’ Expression ‘)’
Constant Summary collapse
- NAME =
:if
Constants inherited from Ternary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#evaluate(bindings, **options) ⇒ RDF::Term
The IF function form evaluates the first argument, interprets it as a effective boolean value, then returns the value of
expression2
if the EBV is true, otherwise it returns the value ofexpression3
. -
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Evaluatable
#apply, #memoize, #replace_aggregate!, #replace_vars!
Methods inherited from Ternary
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, #initialize, #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
This class inherits a constructor from SPARQL::Algebra::Operator::Ternary
Instance Method Details
#evaluate(bindings, **options) ⇒ RDF::Term
The IF function form evaluates the first argument, interprets it as a effective boolean value, then returns the value of expression2
if the EBV is true, otherwise it returns the value of expression3
. Only one of expression2
and expression3
is evaluated. If evaluating the first argument raises an error, then an error is raised for the evaluation of the IF expression.
Evaluates the first operand and returns the evaluation of either the second or third operands
44 45 46 47 48 49 50 |
# File 'lib/sparql/algebra/operator/if.rb', line 44 def evaluate(bindings, **) operand(0).evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) == RDF::Literal::TRUE ? operand(1).evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) : operand(2).evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) rescue raise TypeError end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
57 58 59 |
# File 'lib/sparql/algebra/operator/if.rb', line 57 def to_sparql(**) "IF(" + operands.to_sparql(delimiter: ', ', **) + ")" end |