Class: SPARQL::Algebra::Operator::Add
- Includes:
- Update
- Defined in:
- lib/sparql/algebra/operator/add.rb
Overview
The SPARQL UPDATE add operator.
The ADD operation is a shortcut for inserting all data from an input graph into a destination graph. Data from the input graph is not affected, and initial data from the destination graph, if any, is kept intact.
[35] Add ::= "ADD" "SILENT"? GraphOrDefault "TO" GraphOrDefault
Constant Summary collapse
- NAME =
[:add]
Instance Method Summary collapse
-
#execute(queryable, **options) ⇒ RDF::Queryable
Executes this upate on the given
writablegraph or repository. -
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Update
#empty?, #graph_name=, #unshift, #variables
Instance Method Details
#execute(queryable, **options) ⇒ RDF::Queryable
Executes this upate on the given writable graph or repository.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sparql/algebra/operator/add.rb', line 39 def execute(queryable, **) debug() {"Add"} silent = operands.first == :silent operands.shift if silent src_name, dest_name = operands[-2..-1] raise ArgumentError, "add expected two operands, got #{operands.length}" unless operands.length == 2 raise ArgumentError, "add from must be IRI or :default" unless src_name == :default || src_name.is_a?(RDF::URI) raise ArgumentError, "add to must be IRI or :default" unless dest_name == :default || dest_name.is_a?(RDF::URI) src = queryable.enum_graph.detect {|g| g.to_s == src_name.to_s} if src.nil? raise IOError, "add operation source does not exist" unless silent else src.each do |statement| statement = statement.dup statement.graph_name = (dest_name unless dest_name == :default) queryable << statement end end queryable end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
67 68 69 70 71 72 |
# File 'lib/sparql/algebra/operator/add.rb', line 67 def to_sparql(**) *args, last = operands.dup args += [:TO, last] "ADD " + args.to_sparql(**) end |