Class: SPARQL::Algebra::Operator::Minus

Inherits:
Binary show all
Includes:
Query
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/minus.rb

Overview

The SPARQL GraphPattern minus operator.

Examples:

(prefix ((ex: <http://www.w3.org/2009/sparql/docs/tests/data-sparql11/negation#>))
  (project (?animal)
    (minus
      (bgp (triple ?animal <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ex:Animal))
      (filter (|| (= ?type ex:Reptile) (= ?type ex:Insect))
        (bgp (triple ?animal <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type))))))

See Also:

Constant Summary

NAME =
:minus

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Query

#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_boolean?, #query_yields_solutions?, #query_yields_statements?, #unshift, #variables

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Instance Method Details

#execute(queryable, options = {}) {|solution| ... } ⇒ 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

Yields:

  • (solution)

    each matching solution

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/minus.rb', line 38

def execute(queryable, options = {}, &block)
  # Let Ω1 and Ω2 be multisets of solution mappings. We define:
  # 
  # Minus(Ω1, Ω2) = { μ | μ in Ω1 . ∀ μ' in Ω2, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint }
  # 
  # card[Minus(Ω1, Ω2)](μ) = card[Ω1](μ)
  debug(options) {"Minus"}
  left = queryable.query(operand(0), options.merge(depth: options[:depth].to_i + 1))
  debug(options) {"(minus left) #{left.inspect}"}
  right = queryable.query(operand(1), options.merge(depth: options[:depth].to_i + 1))
  debug(options) {"(minus right) #{right.inspect}"}
  @solutions = left.minus(right)
  @solutions.each(&block) if block_given?
  @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:



63
64
65
66
67
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/minus.rb', line 63

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