class Array

Extensions for Ruby's `Array` class.

Public Instance Methods

aggregate?() click to toggle source
# File lib/sparql/algebra/extensions.rb, line 133
def aggregate?; false; end
bind(solution) click to toggle source

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
constant?() click to toggle source
# File lib/sparql/algebra/extensions.rb, line 122
def constant?; !(variable?); end
deep_dup() click to toggle source

Deep duplicate

# File lib/sparql/algebra/extensions.rb, line 211
def deep_dup
  map(&:deep_dup)
end
evaluatable?() click to toggle source
# File lib/sparql/algebra/extensions.rb, line 131
def evaluatable?; true; end
evaluate(bindings, **options) click to toggle source

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
executable?() click to toggle source
# File lib/sparql/algebra/extensions.rb, line 132
def executable?; false; end
execute(queryable, **options) click to toggle source

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
ndvars() click to toggle source

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
node?() click to toggle source

Does this contain any nodes?

@return [Boolean]

# File lib/sparql/algebra/extensions.rb, line 128
def node?
  any?(&:node?)
end
optimize(**options) click to toggle source

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
replace_aggregate!() { |op| ... } click to toggle source

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_vars!() { |op| ... } click to toggle source

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
to_sxp_bin() click to toggle source

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
valid?() click to toggle source

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!() click to toggle source

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
variable?() click to toggle source

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
vars() click to toggle source

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