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.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/sparql/algebra/evaluatable.rb', line 33

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

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

This method is abstract.

Evaluates this operator using the given variable bindings.



14
15
16
17
# File 'lib/sparql/algebra/evaluatable.rb', line 14

def evaluate(bindings = {})
  args = operands.map { |operand| operand.evaluate(bindings) }
  options[:memoize] ? memoize(*args) : apply(*args)
end

#memoize(*operands) ⇒ RDF::Term



23
24
25
26
# File 'lib/sparql/algebra/evaluatable.rb', line 23

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