Module: SPARQL::Algebra::Evaluatable Abstract

Overview

This module is abstract.

Mixin for Algebra::Operator sub-classes that evaluate bindings to return a result

Instance Method Summary collapse

Instance Method Details

#apply(*operands) ⇒ RDF::Term

This method is abstract.

Parameters:

Returns:

Raises:

  • (NotImplementedError)


35
36
37
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/evaluatable.rb', line 35

def apply(*operands)
  raise NotImplementedError, "#{self.class}#apply(#{operands.map(&:class).join(', ')})"
end

#evaluate(bindings, options = {}) ⇒ RDF::Term

This method is abstract.

Evaluates this operator using the given variable bindings.

Parameters:

  • bindings (RDF::Query::Solution)

    a query solution containing zero or more variable bindings

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

    ({}) options passed from query

Returns:



16
17
18
19
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/evaluatable.rb', line 16

def evaluate(bindings, options = {})
  args = operands.map { |operand| operand.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1)) }
  options[:memoize] ? memoize(*args) : apply(*args)
end

#memoize(*operands) ⇒ RDF::Term

Returns the memoized result

Parameters:

Returns:



25
26
27
28
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/evaluatable.rb', line 25

def memoize(*operands)
  @cache ||= RDF::Util::Cache.new(options[:memoize].is_a?(Integer) ? options[:memoize] : -1)
  @cache[operands] ||= apply(*operands)
end

#replace_aggregate! {|agg| ... } ⇒ SPARQL::Algebra::Evaluatable, RDF::Query::Variable

Recursively re-map operators to replace aggregates with temporary variables returned from the block

Yields:

  • agg

Yield Parameters:

Yield Returns:

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/evaluatable.rb', line 68

def replace_aggregate!(&block)
  @operands.map! do |op|
    case
    when op.aggregate?
      yield op
    when op.respond_to?(:replace_aggregate!)
      op.replace_aggregate!(&block) 
    else
      op
    end
  end
  self
end

#replace_vars! {|var| ... } ⇒ SPARQL::Algebra::Evaluatable

Replace operators which are variables with the result of the block descending into operators which are also evaluatable

Yields:

  • var

Yield Parameters:

Yield Returns:

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/evaluatable.rb', line 47

def replace_vars!(&block)
  @operands.map! do |op|
    case
    when op.is_a?(RDF::Query::Variable)
      yield op
    when op.respond_to?(:replace_vars!)
      op.replace_vars!(&block) 
    else
      op
    end
  end
  self
end