Class: SPARQL::Algebra::Operator::Extend
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Extend
- Includes:
- Query
- Defined in:
- vendor/bundler/ruby/2.7.0/bundler/gems/sparql-881ac01048a7/lib/sparql/algebra/operator/extend.rb
Overview
The SPARQL Extend
operator.
Extends a solution
Constant Summary collapse
- NAME =
[:extend]
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#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:.
-
#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.
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
Methods inherited from SPARQL::Algebra::Operator
#aggregate?, arity, base_uri, #base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #formulae, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #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, #optimize, #optimize!, 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 Ω }
For SPARQL*, expr may be an embedded tiple pattern
(extend ((?t (triple ?bob foaf:age ?age))) (bgp (triple ?t dct:source ?src)))
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-881ac01048a7/lib/sparql/algebra/operator/extend.rb', line 48 def execute(queryable, **, &block) debug() {"Extend"} @solutions = operand(1).execute(queryable, depth: [:depth].to_i + 1, **) @solutions.each do |solution| debug() {"===> soln #{solution.to_h.inspect}"} operand(0).each do |(var, expr)| begin val = expr.evaluate(solution, queryable: queryable, depth: [:depth].to_i + 1, **) debug() {"===> + #{var} => #{val.inspect}"} solution.bindings[var.to_sym] = if val.is_a?(RDF::Query::Pattern) # Variable is bound to the solution val.bind(solution) else val end rescue TypeError => e # Evaluates to error, ignore debug() {"===> #{var} error: #{e.}"} end end end @solutions.each(&block) if block_given? @solutions 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
76 77 78 79 80 81 82 83 84 85 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-881ac01048a7/lib/sparql/algebra/operator/extend.rb', line 76 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 |