Class: SPARQL::Algebra::Operator::Or
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Or
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/or.rb
Overview
The SPARQL logical or operator.
Constant Summary
- NAME =
[:or, :||']
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary (collapse)
-
- (RDF::Literal::Boolean) evaluate(bindings = {})
Returns the logical
ORof the left operand and the right operand. -
- (Or) initialize(left, right, options = {})
constructor
Initializes a new operator instance.
Methods included from Evaluatable
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
- (Or) initialize(left, right, options = {})
Initializes a new operator instance.
27 28 29 |
# File 'lib/sparql/algebra/operator/or.rb', line 27 def initialize(left, right, = {}) super end |
Instance Method Details
- (RDF::Literal::Boolean) evaluate(bindings = {})
Returns the logical OR of the left operand and the right operand.
Note that this operator operates on the effective boolean value (EBV) of its operands.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sparql/algebra/operator/or.rb', line 40 def evaluate(bindings = {}) begin left = boolean(operand(0).evaluate(bindings)).true? rescue TypeError left = nil end begin right = boolean(operand(1).evaluate(bindings)).true? rescue TypeError right = nil end # From http://www.w3.org/TR/rdf-sparql-query/#evaluation # A logical-or that encounters an error on only one branch will return TRUE if the other branch is TRUE # and an error if the other branch is FALSE. case when left.nil? && right.nil? then raise(TypeError) when left.nil? then right ? RDF::Literal::TRUE : raise(TypeError) when right.nil? then left ? RDF::Literal::TRUE : raise(TypeError) else RDF::Literal(left || right) end end |