Class: SPARQL::Algebra::Operator::Extend

Inherits:
Binary show all
Includes:
Query
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/extend.rb

Overview

The SPARQL Extend operator.

Extends a solution

Examples:

(select (?z)
  (project (?z)
    (extend ((?z (+ ?o 10)))
      (bgp (triple ?s <http://example/p> ?o)))))

See Also:

Constant Summary collapse

NAME =
[:extend]

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, #variable?, #vars

Methods included from Expression

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

Constructor Details

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

Instance Method Details

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

Let μ be a solution mapping, Ω a multiset of solution mappings, var a variable and expr be an expression, then we define:

Extend(μ, var, expr) = μ ∪ { (var,value) | var not in dom(μ) and value = expr(μ) }

Extend(μ, var, expr) = μ if var not in dom(μ) and expr(μ) is an error

Extend is undefined when var in dom(μ).

Extend(Ω, var, expr) = { Extend(μ, var, expr) | μ in Ω }

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:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/extend.rb', line 42

def execute(queryable, options = {}, &block)
  debug(options) {"Extend"}
  @solutions = operand(1).execute(queryable, options.merge(depth: options[:depth].to_i + 1))
  @solutions.each do |solution|
    debug(options) {"===> soln #{solution.to_h.inspect}"}
    operand(0).each do |(var, expr)|
      begin
        val = expr.evaluate(solution, options.merge(
                                        queryable: queryable,
                                        depth: options[:depth].to_i + 1))
        debug(options) {"===> + #{var} => #{val.inspect}"}
        solution.bindings[var.to_sym] = val
      rescue TypeError => e
        # Evaluates to error, ignore
        debug(options) {"===> #{var} error: #{e.message}"}
      end
    end
  end
  @solutions.each(&block) if block_given?
  @solutions
end

#optimizeObject

Returns an optimized version of this query.

Return optimized query

Returns:

  • FIXME



82
83
84
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/extend.rb', line 82

def optimize
  operands = operands.map(&:optimize)
end

#validate!Object

The variable introduced by the BIND clause must not have been used in the group graph pattern up to the point of use in BIND



65
66
67
68
69
70
71
72
73
74
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/extend.rb', line 65

def validate!
  bind_vars = operand(0).map(&:first).map(&:name)
  query_vars = operand(1).vars.map(&:name)
  
  unless (bind_vars.compact & query_vars.compact).empty?
    raise ArgumentError,
         "bound variable used in query: #{(bind_vars.compact & query_vars.compact).to_sse}"
  end
  super
end