Class: LD::Patch::Algebra::Add
- Inherits:
-
SPARQL::Algebra::Operator::Unary
- Object
- SPARQL::Algebra::Operator::Unary
- LD::Patch::Algebra::Add
- Includes:
- SPARQL::Algebra::Evaluatable, SPARQL::Algebra::Update
- Defined in:
- 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.
Constant Summary collapse
- NAME =
:add
Instance Method Summary collapse
-
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Executes this upate on the given ‘writable` graph or repository.
Instance Method Details
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Executes this upate on the given ‘writable` graph or repository.
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/add.rb', line 30 def execute(queryable, = {}) debug() {"Add"} bindings = .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 |