Sha256: f371e355277dd9eddb0ccbaaf3fd1e2414dc7ca17b09b7ebce761a2db942c29d

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

module SPARQL; module Algebra
  ##
  # Mixin for Algebra::Operator sub-classes that evaluate bindings to return a result
  #
  # @abstract
  module Evaluatable
    ##
    # Evaluates this operator using the given variable `bindings`.
    #
    # @param  [RDF::Query::Solution, #[]] bindings
    #   a query solution containing zero or more variable bindings
    # @return [RDF::Term]
    # @abstract
    def evaluate(bindings = {})
      args = operands.map { |operand| operand.evaluate(bindings) }
      options[:memoize] ? memoize(*args) : apply(*args)
    end

    ##
    # @param  [Array<RDF::Term>] operands
    #   evaluated operands
    # @return [RDF::Term] the memoized result
    def memoize(*operands)
      @cache ||= RDF::Util::Cache.new(options[:memoize].is_a?(Integer) ? options[:memoize] : -1)
      @cache[operands] ||= apply(*operands)
    end

    ##
    # @param  [Array<RDF::Term>] operands
    #   evaluated operands
    # @return [RDF::Term]
    # @abstract
    def apply(*operands)
      raise NotImplementedError, "#{self.class}#apply(#{operands.map(&:class).join(', ')})"
    end
  end # Query
end; end # SPARQL::Algebra

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sparql-1.0.8 lib/sparql/algebra/evaluatable.rb
sparql-1.0.7 lib/sparql/algebra/evaluatable.rb
sparql-1.0.6 lib/sparql/algebra/evaluatable.rb
sparql-1.0.5 lib/sparql/algebra/evaluatable.rb
sparql-1.0.4 lib/sparql/algebra/evaluatable.rb
sparql-1.0.3 lib/sparql/algebra/evaluatable.rb
sparql-1.0.2 lib/sparql/algebra/evaluatable.rb
sparql-1.0.1 lib/sparql/algebra/evaluatable.rb
sparql-1.0.0 lib/sparql/algebra/evaluatable.rb
sparql-0.3.3 lib/sparql/algebra/evaluatable.rb
sparql-0.3.2 lib/sparql/algebra/evaluatable.rb
sparql-0.3.1 lib/sparql/algebra/evaluatable.rb
sparql-0.3.0 lib/sparql/algebra/evaluatable.rb
sparql-0.1.1 lib/sparql/algebra/evaluatable.rb
sparql-0.1.0 lib/sparql/algebra/evaluatable.rb
sparql-0.0.2 lib/sparql/algebra/evaluatable.rb