Sha256: 21db9a8dfbb1bd953f21a0ad3a05f479c9b49d9fc9f714db9dd1cac103a64575

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 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"}
        @solutions = RDF::Query::Solutions.new(operands.inject([]) do |memo, op|
          solns = op.execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
          debug(options) {"=> (op) #{solns.inspect}"}
          memo + solns
        end)
        debug(options) {"=> #{@solutions.inspect}"}
        @solutions
      end
      
      ##
      # Returns an optimized version of this query.
      #
      # Optimize operands and remove any which are empty.
      #
      # @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

10 entries across 10 versions & 1 rubygems

Version Path
sparql-1.1.1 lib/sparql/algebra/operator/union.rb
sparql-1.1.0 lib/sparql/algebra/operator/union.rb
sparql-1.1.0p0 lib/sparql/algebra/operator/union.rb
sparql-1.0.8 lib/sparql/algebra/operator/union.rb
sparql-1.0.7 lib/sparql/algebra/operator/union.rb
sparql-1.0.6 lib/sparql/algebra/operator/union.rb
sparql-1.0.5 lib/sparql/algebra/operator/union.rb
sparql-1.0.4 lib/sparql/algebra/operator/union.rb
sparql-1.0.3 lib/sparql/algebra/operator/union.rb
sparql-1.0.2 lib/sparql/algebra/operator/union.rb