Class: SPARQL::Algebra::Operator::Union
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Union
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/union.rb
Overview
The SPARQL GraphPattern union operator.
Constant Summary
- NAME =
[:union]
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary (collapse)
-
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes each operand with
queryableand performs theunionoperation by creating a new solution set consiting of all solutions from both operands. -
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Methods included from Query
#context=, #each_solution, #failed?, #matched?, #unshift, #variables
Methods inherited from Binary
Methods inherited from SPARQL::Algebra::Operator
arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?
Methods included from Evaluatable
Methods included from Expression
cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator::Binary
Instance Method Details
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes each operand with queryable and performs the union operation
by creating a new solution set consiting of all solutions from both operands.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sparql/algebra/operator/union.rb', line 30 def execute(queryable, = {}) debug("Union", ) solutions1 = operand(0).execute(queryable, .merge(:depth => [:depth].to_i + 1)) debug("=>(left) #{solutions1.inspect}", ) solutions2 = operand(1).execute(queryable, .merge(:depth => [:depth].to_i + 1)) debug("=>(right) #{solutions2.inspect}", ) @solutions = RDF::Query::Solutions.new(solutions1 + solutions2) debug("=> #{@solutions.inspect}", ) @solutions end |
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
If optimize operands, and if the first two operands are both Queries, replace with the unique sum of the query elements
48 49 50 51 52 |
# File 'lib/sparql/algebra/operator/union.rb', line 48 def optimize ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?} @operands = ops self end |