Class: LD::Patch::Algebra::Delete

Inherits:
SPARQL::Algebra::Operator::Unary
  • Object
show all
Includes:
SPARQL::Algebra::Evaluatable, SPARQL::Algebra::Update
Defined in:
lib/ld/patch/algebra/delete.rb

Overview

The LD Patch ‘delete` operator (incuding `deleteExisting`).

The Add operation is used to delete triples from the target graph with or without checking to see if the exist already.

Examples:

(add ((<a> <b> <c>)))

Constant Summary collapse

NAME =
:delete

Instance Method Summary collapse

Instance Method Details

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

Executes this upate on the given ‘writable` graph or repository.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

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

    any additional options

Options Hash (options):

  • :existing (Boolean)

    Specifies that triples must already exist in the target graph

Returns:

  • (RDF::Query::Solutions)

    A single solution including passed bindings with ‘var` bound to the solution.

Raises:

  • (Error)

    If ‘existing` is specified, and any triple is not found in the traget graph, or if unbound variables are used.

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ld/patch/algebra/delete.rb', line 30

def execute(queryable, options = {})
  debug(options) {"Delete"}
  bindings = options.fetch(:bindings)
  solution = bindings.first

  # Bind variables to triples
  triples = operand(0).dup.replace_vars! do |var|
    case var
    when RDF::Query::Pattern
      s = var.bind(solution)
      raise LD::Patch::Error.new("Operand uses unbound pattern #{var.inspect}", code: 400) if s.variable?
      s
    when RDF::Query::Variable
      raise LD::Patch::Error.new("Operand uses unbound variable #{var.inspect}", code: 400) unless solution.bound?(var)
      solution[var]
    end
  end

  # If `:new` is specified, verify that no triple in triples exists in queryable
  if @options[:existing]
    triples.each do |triple|
      raise LD::Patch::Error, "Target graph does not contain triple #{triple.to_ntriples}" unless queryable.has_statement?(triple)
    end
  end

  queryable.delete(*triples)
  bindings
end