Class: SPARQL::Algebra::Operator::Drop

Inherits:
Operator
  • Object
show all
Includes:
Update
Defined in:
lib/sparql/algebra/operator/drop.rb

Overview

The SPARQL UPDATE drop operator.

The DROP operation removes the specified graph(s) from the Graph Store

Equivalent to clear in this implementation

[33] Drop ::= 'DROP' 'SILENT'? GraphRefAll

Examples:

SPARQL Grammar (SILENT DEFAULT)

DROP SILENT DEFAULT

SSE (SILENT DEFAULT)

(update
 (drop silent default))

SPARQL Grammar (IRI)

DROP GRAPH <http://example.com/>

SSE (IRI)

(update (drop <http://example.com/>))

See Also:

Constant Summary collapse

NAME =
[:drop]

Instance Method Summary collapse

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.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

  • options (Hash{Symbol => Object})

    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:



46
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
# File 'lib/sparql/algebra/operator/drop.rb', line 46

def execute(queryable, **options)
  debug(options) {"Drop"}
  silent = operands.first == :silent
  operands.shift if silent

  raise ArgumentError, "drop expected operand to be 'default', 'named', 'all', or an IRI" unless operands.length == 1
  case operands.last
  when :default
    queryable.each_graph do |g|
      g.clear! unless g.graph_name
    end
  when :named
    queryable.each_graph do |g|
      g.clear! if g.graph_name
    end
  when :all
    queryable.clear!
  when RDF::URI
    if g = queryable.each_graph.detect {|c| c.graph_name == operands.last}
      g.clear!
    else
      raise IOError, "drop operation graph does not exist" unless silent
    end
  else
    raise ArgumentError, "drop expected operand to be 'default', 'named', 'all', or an IRI" 
  end

  queryable
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:

  • (String)


81
82
83
84
85
86
87
# File 'lib/sparql/algebra/operator/drop.rb', line 81

def to_sparql(**options)
  silent = operands.first == :silent
  str = "DROP "
  str << "SILENT " if operands.first == :silent
  str << "GRAPH " if operands.last.is_a?(RDF::URI)
  str << operands.last.to_sparql(**options)
end