Class: SPARQL::Algebra::Operator::With

Inherits:
SPARQL::Algebra::Operator show all
Includes:
Update
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/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.

Examples:

(with :g1
  (bgp (triple ?s ?p ?o))
  (insert ((triple ?s ?p "z"))))

See Also:

Constant Summary

NAME =
:with

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Update

#graph_name=, #unshift, #variables

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, #optimize, #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, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

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.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

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

    any additional keyword options

Options Hash (options):

  • debug (Boolean)

    Query execution debugging

Returns:

Raises:

  • (IOError)

    If from does not exist, unless the silent operator is present

See Also:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/operator/with.rb', line 36

def execute(queryable, options = {})
  debug(options) {"With: #{operand.to_sse}"}
  # Bound variable
  name = operands.shift

  unless queryable.has_graph?(name)
    debug(options) {"=> default data source #{name}"}
    load_opts = {debug: options.fetch(:debug, nil), base_uri: name}
    debug(options) {"=> 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(options) {"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, options.merge(depth: options[:depth].to_i + 1)) do |solution|
    debug(options) {"(solution)=>#{solution.inspect}"}

    # Execute each operand with queryable and solution
    operands.each do |op|
      op.execute(queryable, solution, options.merge(depth: options[:depth].to_i + 1))
    end
  end
end