class Array
Extensions for Ruby's `Array` class.
Public Instance Methods
# File lib/sparql/algebra/extensions.rb, line 133 def aggregate?; false; end
Binds the pattern to a solution, making it no longer variable if all variables are resolved to bound variables
@param [RDF::Query::Solution] solution @return [self]
# File lib/sparql/algebra/extensions.rb, line 106 def bind(solution) map! do |op| op.respond_to?(:bind) ? op.bind(solution) : op end self end
# File lib/sparql/algebra/extensions.rb, line 122 def constant?; !(variable?); end
Deep duplicate
# File lib/sparql/algebra/extensions.rb, line 211 def deep_dup map(&:deep_dup) end
# File lib/sparql/algebra/extensions.rb, line 131 def evaluatable?; true; end
Evaluates the array using the given variable `bindings`.
In this case, the Array
has two elements, the first of which is an XSD datatype, and the second is the expression to be evaluated. The result is cast as a literal of the appropriate type
@param [RDF::Query::Solution] bindings
a query solution containing zero or more variable bindings
@param [Hash{Symbol => Object}] options ({})
options passed from query
@return [RDF::Term] @see SPARQL::Algebra::Expression.evaluate
# File lib/sparql/algebra/extensions.rb, line 72 def evaluate(bindings, **options) SPARQL::Algebra::Expression.extension(*self.map {|o| o.evaluate(bindings, **options)}) end
# File lib/sparql/algebra/extensions.rb, line 132 def executable?; false; end
If `#execute` is invoked, it implies that a non-implemented Algebra operator is being invoked
@param [RDF::Queryable] queryable
the graph or repository to query
@param [Hash{Symbol => Object}] options @raise [NotImplementedError]
If an attempt is made to perform an unsupported operation
@see www.w3.org/TR/sparql11-query/#sparqlAlgebra
# File lib/sparql/algebra/extensions.rb, line 86 def execute(queryable, **options) raise NotImplementedError, "SPARQL::Algebra '#{first}' operator not implemented" end
Return the non-destinguished variables contained within this Array
@return [Array<RDF::Query::Variable>]
# File lib/sparql/algebra/extensions.rb, line 181 def ndvars vars.reject(&:distinguished?) end
Does this contain any nodes?
@return [Boolean]
# File lib/sparql/algebra/extensions.rb, line 128 def node? any?(&:node?) end
Return an optimized version of this array.
@return [Array] a copy of `self` @see SPARQL::Algebra::Expression#optimize
# File lib/sparql/algebra/extensions.rb, line 95 def optimize(**options) self.map do |op| op.optimize(**options) if op.respond_to?(:optimize) end end
Recursively re-map operators to replace aggregates with temporary variables returned from the block
@yield agg @yieldparam [SPARQL::Algebra::Aggregate] agg @yieldreturn [RDF::Query::Variable] @return [SPARQL::Algebra::Evaluatable, RDF::Query::Variable] self
# File lib/sparql/algebra/extensions.rb, line 164 def replace_aggregate!(&block) map! do |op| case when op.respond_to?(:aggregate?) && op.aggregate? yield op when op.respond_to?(:replace_aggregate!) op.replace_aggregate!(&block) else op end end self end
Replace operators which are variables with the result of the block descending into operators which are also evaluatable
@yield var @yieldparam [RDF::Query::Variable] var @yieldreturn [RDF::Query::Variable, SPARQL::Algebra::Evaluatable] @return [SPARQL::Algebra::Evaluatable] self
# File lib/sparql/algebra/extensions.rb, line 143 def replace_vars!(&block) map! do |op| case when op.respond_to?(:variable?) && op.variable? yield op when op.respond_to?(:replace_vars!) op.replace_vars!(&block) else op end end self end
Returns the SXP representation of this object, defaults to `self`.
@return [String]
# File lib/sparql/algebra/extensions.rb, line 55 def to_sxp_bin map {|x| x.to_sxp_bin} end
Is this value composed only of valid components?
@return [Boolean] `true` or `false`
# File lib/sparql/algebra/extensions.rb, line 196 def valid? all? {|e| e.respond_to?(:valid?) ? e.valid? : true} end
Validate all components. @return [Array] `self` @raise [ArgumentError] if the value is invalid
# File lib/sparql/algebra/extensions.rb, line 204 def validate! each {|e| e.validate! if e.respond_to?(:validate!)} self end
Returns `true` if any of the operands are variables, `false` otherwise.
@return [Boolean] `true` or `false` @see constant?
# File lib/sparql/algebra/extensions.rb, line 119 def variable? any? {|op| op.respond_to?(:variable?) && op.variable?} end
Return the variables contained within this Array
@return [Array<RDF::Query::Variable>]
# File lib/sparql/algebra/extensions.rb, line 188 def vars select {|o| o.respond_to?(:vars)}.map(&:vars).flatten.compact end