Sha256: 25610cf8e8ef2c0522043353104e867599ed8d2eff3eee716739857da00f1ffe

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module SPARQL; module Algebra
  class Operator

    ##
    # The SPARQL UPDATE `delete` operator.
    #
    # The DELETE operation is a form of the DELETE/INSERT operation having no INSERT section
    #
    # @example
    #   (delete ((triple ?s ?p ?o))))
    #
    # @see https://www.w3.org/TR/sparql11-update/#delete
    class Delete < Operator::Unary
      include SPARQL::Algebra::Update

      NAME = [:delete]

      ##
      # Executes this upate on the given `writable` graph or repository.
      #
      # @param  [RDF::Queryable] queryable
      #   the graph or repository to write
      # @param  [RDF::Query::Solutions] solutions
      #   Solutions to map to patterns for this operation
      # @param  [Hash{Symbol => Object}] options
      #   any additional keyword options
      # @option options [Boolean] debug
      #   Query execution debugging
      # @return [RDF::Queryable]
      #   Returns queryable.
      # @raise [IOError]
      #   If `from` does not exist, unless the `silent` operator is present
      # @see    https://www.w3.org/TR/sparql11-update/
      def execute(queryable, solutions: nil, **options)
        debug(options) {"Delete: #{solution} against #{operands.to_sse}"}
        # Only binds the first solution
        solution = solutions.is_a?(RDF::Query::Solutions) ? solutions.first : solutions
        # Operands are an array of patterns and Queries (when named).
        # Create a new query made up all patterns
        patterns = operand.inject([]) do |memo, op|
          if op.respond_to?(:statements)
            memo += op.statements.to_a
          else
            memo << op
          end
          memo
        end
        patterns.each do |pattern|
          pattern = pattern.dup.bind(solution)
          debug(options) {"Delete statement #{statement.to_sse}"}
          queryable.delete(RDF::Statement.from(pattern)) if pattern.bound? || pattern.constant?
        end
        queryable
      end
    end # Delete
  end # Operator
end; end # SPARQL::Algebra

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sparql-3.1.3 lib/sparql/algebra/operator/delete.rb
sparql-3.1.2 lib/sparql/algebra/operator/delete.rb