Module: SPARQL::Algebra::Evaluatable Abstract

Included in:
LD::Patch::Algebra::Add, LD::Patch::Algebra::Bind, LD::Patch::Algebra::Constraint, LD::Patch::Algebra::Cut, LD::Patch::Algebra::Delete, LD::Patch::Algebra::Path, LD::Patch::Algebra::Reverse, LD::Patch::Algebra::UpdateList, Operator::Abs, Operator::And, Operator::Asc, Operator::BNode, Operator::Bound, Operator::Ceil, Operator::Coalesce, Operator::Compare, Operator::Concat, Operator::Contains, Operator::Datatype, Operator::Day, Operator::Divide, Operator::EncodeForURI, Operator::Exists, Operator::Exprlist, Operator::Floor, Operator::Hours, Operator::IRI, Operator::If, Operator::In, Operator::IsBlank, Operator::IsIRI, Operator::IsLiteral, Operator::IsNumeric, Operator::IsTriple, Operator::LCase, Operator::Lang, Operator::LangMatches, Operator::MD5, Operator::Minutes, Operator::Month, Operator::Multiply, Operator::Negate, Operator::Not, Operator::NotExists, Operator::NotIn, Operator::Now, Operator::Object, Operator::Or, Operator::Plus, Operator::Predicate, Operator::Rand, Operator::Regex, Operator::Replace, Operator::Round, Operator::SHA1, Operator::SHA256, Operator::SHA384, Operator::SHA512, Operator::SameTerm, Operator::Seconds, Operator::Str, Operator::StrAfter, Operator::StrBefore, Operator::StrDT, Operator::StrEnds, Operator::StrLang, Operator::StrLen, Operator::StrStarts, Operator::StrUUID, Operator::SubStr, Operator::Subject, Operator::Subtract, Operator::TZ, Operator::Timezone, Operator::Triple, Operator::UCase, Operator::UUID, Operator::Year
Defined in:
vendor/bundler/ruby/3.0.0/bundler/gems/sparql-ffa592c8f275/lib/sparql/algebra/evaluatable.rb

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/3.0.0/bundler/gems/sparql-ffa592c8f275/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:

Returns:



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

def evaluate(bindings, **options)
  args = operands.map { |operand| operand.evaluate(bindings, depth: options[:depth].to_i + 1, **options) }
  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/3.0.0/bundler/gems/sparql-ffa592c8f275/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/3.0.0/bundler/gems/sparql-ffa592c8f275/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/3.0.0/bundler/gems/sparql-ffa592c8f275/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