Class: SPARQL::Algebra::Operator::With
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::With
- Includes:
- Update
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/with.rb
Overview
The SPARQL UPDATE with
operator.
The WITH clause provides a convenience for when an operation primarily refers to a single graph.
[41] Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern
Constant Summary collapse
- NAME =
:with
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Constants included from RDF::Util::Logger
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#execute(queryable, **options) ⇒ RDF::Queryable
Executes this upate on the given
writable
graph or repository. -
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Update
#graph_name=, #unshift, #variables
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, #mergable?, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Methods included from RDF::Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator
Instance Method Details
#execute(queryable, **options) ⇒ RDF::Queryable
Executes this upate on the given writable
graph or repository.
Effectively filters results by setting a default __graph_name__
variable so that it is used when binding to perform update operations on the appropriate triples.
47 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 74 75 76 77 78 79 80 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/with.rb', line 47 def execute(queryable, **) debug() {"With: #{operand.to_sse}"} # Bound variable name = operands.shift unless queryable.has_graph?(name) debug() {"=> default data source #{name}"} load_opts = {logger: .fetch(:logger, false), base_uri: name} debug() {"=> load #{name}"} queryable.load(name.to_s, **load_opts) end # Set name for RDF::Graph descendants having no graph_name to the name variable each_descendant do |op| case op when RDF::Query, RDF::Query::Pattern unless op.graph_name debug() {"set graph_name on #{op.to_sse}"} op.graph_name = RDF::Query::Variable.new(:__graph_name__, name) end end end query = operands.shift # Restrict query portion to this graph queryable.query(query, **.merge(depth: [:depth].to_i + 1)) do |solution| debug() {"(solution)=>#{solution.inspect}"} # Execute each operand with queryable and solution operands.each do |op| op.execute(queryable, solutions: solution, **.merge(depth: [:depth].to_i + 1)) end end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/with.rb', line 87 def to_sparql(**) with, where, *ops = operands str = "WITH #{with.to_sparql(**)}\n" # The content of the WHERE clause, may be USING content = where.to_sparql(top_level: false, **) # DELETE | INSERT | DELETE INSERT str << ops.to_sparql(top_level: false, delimiter: "\n", **) + "\n" # Append the WHERE or USING clause str << if where.is_a?(Using) content else Operator.to_sparql(content, project: nil, **) end end |