Class: SPARQL::Algebra::Operator::Join

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

Overview

The SPARQL GraphPattern join operator.

Examples:

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

See Also:

Constant Summary collapse

NAME =
[:join]

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 join operation by creating a new solution set containing the merge of all solutions from each set that are compatible with each other.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

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

    any additional keyword options

Returns:

See Also:


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sparql/algebra/operator/join.rb', line 33

def execute(queryable, options = {})
  # Join(Ω1, Ω2) = { merge(μ1, μ2) | μ1 in Ω1 and μ2 in Ω2, and μ1 and μ2 are compatible }
  # eval(D(G), Join(P1, P2)) = Join(eval(D(G), P1), eval(D(G), P2))
  #
  # Generate solutions independently, merge based on solution compatibility
  debug("Join", 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 = solutions1.map do |s1|
    solutions2.map { |s2| s2.merge(s1) if s2.compatible?(s1) }
  end.flatten.compact
  @solutions = RDF::Query::Solutions.new(@solutions)
  debug("=> #{@solutions.inspect}", options)
  @solutions
end

#optimizeJoin, RDF::Query

Returns an optimized version of this query.

Groups of one graph pattern (not a filter) become join(Z, A) and can be replaced by A. The empty graph pattern Z is the identity for join: Replace join(Z, A) by A Replace join(A, Z) by A

Returns:


60
61
62
63
64
# File 'lib/sparql/algebra/operator/join.rb', line 60

def optimize
  ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?}
  @operands = ops
  self
end