Class: SPARQL::Algebra::Operator::Sequence

Inherits:
SPARQL::Algebra::Operator show all
Includes:
Update
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/sequence.rb

Overview

The SPARQL UPDATE sequence operator.

Sequences through each operand

Examples:

(sequence
  (bgp
    (triple ?s ?p ??0)
    (triple ??0 rdf:first ??1)
    (triple ??0 rdf:rest ??2)
    (triple ??2 rdf:first ??3)
    (triple ??2 rdf:rest rdf:nil))
  (path ??1 (seq (path* :p) :q) 123)
  (path ??3 (reverse :r) "hello"))

Constant Summary

NAME =
:sequence

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Update

#graph_name=, #unshift, #variables

Methods inherited from SPARQL::Algebra::Operator

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

Methods included from Expression

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

Constructor Details

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

Instance Method Details

#execute(queryable, options = {}) {|solution| ... } ⇒ Object

Basically a JOIN across multiple operands

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional keyword options

Options Hash (options):

  • debug (Boolean)

    Query execution debugging

Yields:

  • (solution)

    each matching solution

Yield Parameters:

Yield Returns:

  • (void)

    ignored

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/sequence.rb', line 38

def execute(queryable, options = {})
  debug(options) {"Sequence #{operands.to_sse}"}

  last = queryable.query(operands.shift, options.merge(depth: options[:depth].to_i + 1))
  debug(options) {"(sequence)=>(last) #{last.map(&:to_h).to_sse}"}

  operands.each do |op|
    this = queryable.query(op, options.merge(depth: options[:depth].to_i + 1))
    debug(options) {"(sequence)=>(this) #{this.map(&:to_h).to_sse}"}

    last = last.map do |s1|
      this.map do |s2|
        s2.merge(s1) if s2.compatible?(s1)
      end
    end.flatten.compact
    debug(options) {"(sequence)=>(next) #{last.map(&:to_h).to_sse}"}
  end

  @solutions = RDF::Query::Solutions.new(last)
  debug(options) {"(sequence)=> #{@solutions.map(&:to_h).to_sse}"}
  @solutions.each(&block) if block_given?
  @solutions
end