Class: SPARQL::Algebra::Operator::In
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::In
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/in.rb
Overview
The SPARQL GraphPattern in
operator.
[114] RelationalExpression ::= NumericExpression (βINβ ExpressionList)?
Constant Summary collapse
- NAME =
:in
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::Literal::Boolean
The IN operator tests whether the RDF term on the left-hand side is found in the values of list of expressions on the right-hand side.
-
#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 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
Instance Method Details
#evaluate(bindings, **options) ⇒ RDF::Literal::Boolean
The IN operator tests whether the RDF term on the left-hand side is found in the values of list of expressions on the right-hand side. The test is done with β=β operator, which tests for the same value, as determined by the operator mapping.
A list of zero terms on the right-hand side is legal.
Errors in comparisons cause the IN expression to raise an error if the RDF term being tested is not found elsewhere in the list of terms.
The IN operator is equivalent to the SPARQL expression:
(lhs = expression1) || (lhs = expression2) || ...
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sparql/algebra/operator/in.rb', line 46 def evaluate(bindings, **) lhs = operands.first.evaluate(bindings, **) error_found = false found = operands[1..-1].any? do |op| begin lhs == op.evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) rescue TypeError error_found = true end end case when found then RDF::Literal::TRUE when error_found then raise TypeError else RDF::Literal::FALSE end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
68 69 70 71 72 73 |
# File 'lib/sparql/algebra/operator/in.rb', line 68 def to_sparql(**) "(" + operands.first.to_sparql(**) + " IN (" + operands[1..-1].map {|e| e.to_sparql(**)}.join(", ") + "))" end |