module RDF::N3::Algebra::Builtin
Behavior for N3
builtin operators
Public Instance Methods
By default, operators yield themselves and the operands, recursively.
Pass in solutions to have quantifiers resolved to those solutions.
# File lib/rdf/n3/algebra/builtin.rb, line 50 def each(solutions: RDF::Query::Solutions(), &block) log_debug("(#{self.class.const_get(:NAME)} each)") log_depth do subject, object = operands.map {|op| op.formula? ? op.graph_name : op} block.call(RDF::Statement(subject, self.to_uri, object)) operands.each do |op| next unless op.is_a?(Builtin) op.each(solutions: solutions) do |st| # Maintain formula graph name for formula operands st.graph_name ||= op.graph_name if op.formula? block.call(st) end end end end
Evaluates the builtin using the given variable ‘bindings` by cloning the builtin replacing variables with their bindings recursively.
@param [Hash{Symbol => RDF::Term
}] bindings
a query solution containing zero or more variable bindings
@param [Hash{Symbol => Object}] options ({})
options passed from query
@return [RDF::N3::Algebra::Builtin]
Returns a new builtin with bound values.
@see SPARQL::Algebra::Expression.evaluate
# File lib/rdf/n3/algebra/builtin.rb, line 40 def evaluate(bindings, formulae:, **options) args = operands.map { |operand| operand.evaluate(bindings, formulae: formulae, **options) } # Replace operands with bound operands self.class.new(*args, formulae: formulae, **options) end
The builtin hash is the hash of it’s operands and NAME.
@see RDF::Value#hash
# File lib/rdf/n3/algebra/builtin.rb, line 70 def hash ([self.class.const_get(:NAME)] + operands).hash end
Return subject or object operand, or both, depending on which is considered an input.
@return [RDF::Term]
# File lib/rdf/n3/algebra/builtin.rb, line 25 def input_operand # By default, return the merger of input and output operands RDF::N3::List.new(values: operands) end
Determine ordering for running built-in operator considering if subject or object is varaible and considered an input or an output. Accepts a solution set to determine if variable inputs are bound.
@param [RDF::Query::Solutions] solutions @return [Integer] rake for ordering, lower numbers have fewer unbound output variables.
# File lib/rdf/n3/algebra/builtin.rb, line 15 def rank(solutions) vars = input_operand.vars - solutions.variable_names # The rank is the remaining unbound variables vars.count end
The URI of this operator.
# File lib/rdf/n3/algebra/builtin.rb, line 75 def to_uri self.class.const_get(:URI) end