Module: SPARQL::Algebra::Evaluatable Abstract
- Included in:
- Operator::Abs, Operator::Adjust, 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::FunctionCall, 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:
- 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
- #apply(*operands, **options) ⇒ RDF::Term abstract
-
#evaluate(bindings, **options) ⇒ RDF::Term
abstract
Evaluates this operator using the given variable
bindings
. -
#memoize(*operands, **options) ⇒ RDF::Term
The memoized result.
-
#replace_aggregate! {|agg| ... } ⇒ SPARQL::Algebra::Evaluatable, RDF::Query::Variable
Recursively re-map operators to replace aggregates with temporary variables returned from the block.
-
#replace_vars! {|var| ... } ⇒ SPARQL::Algebra::Evaluatable
Replace operators which are variables with the result of the block descending into operators which are also evaluatable.
Instance Method Details
#apply(*operands, **options) ⇒ RDF::Term
This method is abstract.
35 36 37 |
# File '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
.
16 17 18 19 |
# File 'lib/sparql/algebra/evaluatable.rb', line 16 def evaluate(bindings, **) args = operands.map { |operand| operand.evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) } [:memoize] ? memoize(*args, **) : apply(*args, **) end |
#memoize(*operands, **options) ⇒ RDF::Term
Returns the memoized result.
25 26 27 28 |
# File 'lib/sparql/algebra/evaluatable.rb', line 25 def memoize(*operands, **) @cache ||= RDF::Util::Cache.new([:memoize].is_a?(Integer) ? [: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
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File '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
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File '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 |