Class: SPARQL::Algebra::Operator::Union

Inherits:
Binary show all
Includes:
Query
Defined in:
lib/sparql/algebra/operator/union.rb

Overview

The SPARQL GraphPattern union operator.

Examples:

(prefix ((: <http://example/>))
  (union
    (bgp (triple ?s ?p ?o))
    (graph ?g
      (bgp (triple ?s ?p ?o)))))

See Also:

Constant Summary

NAME =
[:union]

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary collapse

Methods included from Query

#context=, #each_solution, #failed?, #matched?, #unshift, #variables

Methods inherited from Binary

#initialize

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

#apply, #evaluate, #memoize

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

#execute(queryable, options = {}) ⇒ RDF::Query::Solutions

Executes each operand with queryable and performs the union operation by creating a new solution set consiting of all solutions from both operands.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional keyword options

Returns:

See Also:



30
31
32
33
34
35
36
37
38
39
# File 'lib/sparql/algebra/operator/union.rb', line 30

def execute(queryable, options = {})
  debug("Union", options)
  solutions1 = operand(0).execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
  debug("=>(left) #{solutions1.inspect}", options)
  solutions2 = operand(1).execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
  debug("=>(right) #{solutions2.inspect}", options)
  @solutions = RDF::Query::Solutions.new(solutions1 + solutions2)
  debug("=> #{@solutions.inspect}", options)
  @solutions
end

#optimizeUnion, RDF::Query

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

Returns:



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