lib/ld/patch/algebra/bind.rb
##
# Maps the value to a single output term by executing the path and updates `bindings` with `var` set to that output term
#
# @param  [RDF::Queryable] queryable
#   the graph or repository to write
# @param  [Hash{Symbol => Object}] options
#   any additional options
# @option options [RDF::Query::Solutions] :bindings
# @return [RDF::Query::Solutions] A single solution including passed bindings with `var` bound to the solution.
# @raise [Error]
#   If path does not evaluate to a single term or if unbound variables are used.
# @see    http://www.w3.org/TR/sparql11-update/
Maps the value to a single output term by executing the path and updates `bindings` with `var` set to that output term
Maps the value to a single output term by executing the path and updates ` bindings ` with ` var ` set to that output term
def execute(queryable, options = {})
      debug(options) {"Bind"}
      bindings = options.fetch(:bindings)
      solution = bindings.first
      var, value, path = operands
      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
def execute ( queryable , options = { } ) debug ( options ) { "Bind" } bindings = options . fetch ( :bindings ) solution = bindings . first var , value , path = operands 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
Maps the value to a single output term by executing the path and updates `bindings` with `var` set to that output term
Maps the value to a single output term by executing the path and updates ` bindings ` with ` var ` set to that output term
# Bind variables to path
A single solution including passed bindings with `var` bound to the solution.
A single solution including passed bindings with ` var ` bound to the solution .
RDF::Query::Solutions
[Error] If path does not evaluate to a single term or if unbound variables are used.
[ Error ] If path does not evaluate to a single term or if unbound variables are used .
queryable
<not_specific>
options
None
<not_specific>
options any additional options
options any additional options
see
None