Sha256: 4e64ae826698c7854af51ed5282d311b09090738e185e3920157e6d15169085c

Contents?: true

Size: 1.93 KB

Versions: 9

Compression:

Stored size: 1.93 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL GraphPattern `union` operator.
    #
    # @example
    #   (prefix ((: <http://example/>))
    #     (union
    #       (bgp (triple ?s ?p ?o))
    #       (graph ?g
    #         (bgp (triple ?s ?p ?o)))))
    #
    # @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
    class Union < Operator::Binary
      include Query
      
      NAME = [:union]

      ##
      # Executes each operand with `queryable` and performs the `union` operation
      # by creating a new solution set consiting of all solutions from both operands.
      #
      # @param  [RDF::Queryable] queryable
      #   the graph or repository to query
      # @param  [Hash{Symbol => Object}] options
      #   any additional keyword options
      # @return [RDF::Query::Solutions]
      #   the resulting solution sequence
      # @see    http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
      def execute(queryable, options = {})
        debug(options) {"Union"}
        solutions1 = operand(0).execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
        debug(options) {"=>(left) #{solutions1.inspect}"}
        solutions2 = operand(1).execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
        debug(options) {"=>(right) #{solutions2.inspect}"}
        @solutions = RDF::Query::Solutions.new(solutions1 + solutions2)
        debug(options) {"=> #{@solutions.inspect}"}
        @solutions
      end
      
      ##
      # 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
      #
      # @return [Union, RDF::Query] `self`
      def optimize
        ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?}
        @operands = ops
        self
      end
    end # Union
  end # Operator
end; end # SPARQL::Algebra

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sparql-1.0.1 lib/sparql/algebra/operator/union.rb
sparql-1.0.0 lib/sparql/algebra/operator/union.rb
sparql-0.3.3 lib/sparql/algebra/operator/union.rb
sparql-0.3.2 lib/sparql/algebra/operator/union.rb
sparql-0.3.1 lib/sparql/algebra/operator/union.rb
sparql-0.3.0 lib/sparql/algebra/operator/union.rb
sparql-0.1.1 lib/sparql/algebra/operator/union.rb
sparql-0.1.0 lib/sparql/algebra/operator/union.rb
sparql-0.0.2 lib/sparql/algebra/operator/union.rb