Class: LD::Patch::Algebra::Add

Inherits:
SPARQL::Algebra::Operator::Unary show all
Includes:
SPARQL::Algebra::Evaluatable, SPARQL::Algebra::Update
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/algebra/add.rb

Overview

The LD Patch add operator.

The Add operation is used to add triples to the target graph with or without allowing duplicates.

Examples:

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

Constant Summary collapse

NAME =
:add

Constants inherited from SPARQL::Algebra::Operator::Unary

SPARQL::Algebra::Operator::Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

SPARQL::Algebra::Operator::ARITY, SPARQL::Algebra::Operator::IsURI, SPARQL::Algebra::Operator::URI

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from SPARQL::Algebra::Evaluatable

#apply, #evaluate, #memoize, #replace_aggregate!, #replace_vars!

Methods included from SPARQL::Algebra::Update

#graph_name=, #unshift, #variables

Methods inherited from SPARQL::Algebra::Operator::Unary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, base_uri, #base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #formulae, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sparql, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Unary

Instance Method Details

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

Executes this upate on the given writable graph or repository.

Parameters:

Options Hash (options):

  • :new (Boolean)

    Specifies that triples may not 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 the :new option is specified and any triples already exist in queryable 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 'vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/algebra/add.rb', line 30

def execute(queryable, options = {})
  debug(options) {"Add"}
  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[:new]
    triples.each do |triple|
      raise LD::Patch::Error, "Target graph contains added triple #{triple.to_ntriples}" if queryable.has_statement?(triple)
    end
  end

  queryable.insert(*triples)
  bindings
end