Class: LD::Patch::Algebra::Bind
- Inherits:
-
SPARQL::Algebra::Operator::Ternary
- Object
- SPARQL::Algebra::Operator::Ternary
- LD::Patch::Algebra::Bind
- Includes:
- SPARQL::Algebra::Evaluatable, SPARQL::Algebra::Query
- Defined in:
- lib/ld/patch/algebra/bind.rb
Overview
The LD Patch ‘bind` operator.
The Bind operation is used to bind a single term to a variable.
Constant Summary collapse
- NAME =
:bind
Instance Method Summary collapse
-
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Maps the value to a single output term by executing the path and updates ‘bindings` with `var` set to that output term.
Instance Method Details
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Maps the value to a single output term by executing the path and updates ‘bindings` with `var` set to that output term
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ld/patch/algebra/bind.rb', line 69 def execute(queryable, = {}) debug() {"Bind"} bindings = .fetch(:bindings) solution = bindings.first var, value, path = operands # Bind variables to path if value.variable? raise LD::Patch::Error.new("Operand uses unbound variable #{value.inspect}", code: 400) unless solution.bound?(value) value = solution[value] end path = path.dup.replace_vars! do |v| raise Error, "Operand uses unbound variable #{v.inspect}" unless solution.bound?(v) solution[v] end results = path.execute(queryable, terms: [value]) raise LD::Patch::Error, "Bind path bound to #{results.length} terms, expected just one" unless results.length == 1 RDF::Query::Solutions.new [solution.merge(var.to_sym => results.first.path)] end |