Class: SPARQL::Algebra::Operator::And
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::And
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/and.rb
Overview
The SPARQL logical and operator.
Constant Summary
- NAME =
[:and, :&&']
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
ANDof the left operand and the right operand. -
- (And) 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
- (And) initialize(left, right, options = {})
Initializes a new operator instance.
27 28 29 |
# File 'lib/sparql/algebra/operator/and.rb', line 27 def initialize(left, right, = {}) super end |
Instance Method Details
- (RDF::Literal::Boolean) evaluate(bindings = {})
Returns the logical AND 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/and.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-and that encounters an error on only one branch will return an error if the other branch is # TRUE and FALSE if the other branch is FALSE. case when left.nil? && right.nil? then raise(TypeError) when left.nil? then right ? raise(TypeError) : RDF::Literal::FALSE when right.nil? then left ? raise(TypeError) : RDF::Literal::FALSE else RDF::Literal(left && right) end end |