Class: LD::Patch::Algebra::Cut

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

Overview

The LD Patch cut operator.

The Cut operation is recursively remove triples from some starting node.

Examples:

(cut ?a)

Constant Summary collapse

NAME =
:cut

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

Returns:

  • (RDF::Query::Solutions)

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

Raises:

  • (IOError)

    If no triples are identified, or the operand is an unbound variable or the operand is an unbound variable.

See Also:



28
29
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
# File 'lib/ld/patch/algebra/cut.rb', line 28

def execute(queryable, options = {})
  debug(options) {"Cut"}
  bindings = options.fetch(:bindings)
  solution = bindings.first
  var = operand(0)

  # Bind variable
  raise LD::Patch::Error.new("Operand uses unbound variable #{var.inspect}", code: 400) unless solution.bound?(var)
  var = solution[var]

  cut_count = 0
  # Get triples to delete using consice bounded description
  queryable.concise_bounded_description(var) do |statement|
    queryable.delete(statement)
    cut_count += 1
  end

  # Also delete triples having var in the object position
  queryable.query({object: var}).each do |statement|
    queryable.delete(statement)
    cut_count += 1
  end

  raise LD::Patch::Error, "Cut removed no triples" unless cut_count > 0

  bindings
end