Module: RDF::N3::Algebra::Builtin
- Includes:
- Enumerable, Util::Logger
- Included in:
- Formula, ListOperator, Log::Implies, Log::NotEqualTo, Math::Negation, NotImplemented, ResourceOperator, Str::Format, Str::Replace, Str::Scrape
- Defined in:
- lib/rdf/n3/algebra/builtin.rb
Overview
Behavior for N3 builtin operators
Instance Attribute Summary
Attributes included from Enumerable
Instance Method Summary collapse
-
#each(solutions: RDF::Query::Solutions(), &block) ⇒ Object
By default, operators yield themselves and the operands, recursively.
-
#evaluate(bindings, formulae:, **options) ⇒ RDF::N3::Algebra::Builtin
Evaluates the builtin using the given variable
bindings
by cloning the builtin replacing variables with their bindings recursively. -
#hash ⇒ Object
The builtin hash is the hash of it’s operands and NAME.
-
#input_operand ⇒ RDF::Term
Return subject or object operand, or both, depending on which is considered an input.
-
#rank(solutions) ⇒ Integer
Determine ordering for running built-in operator considering if subject or object is varaible and considered an input or an output.
-
#to_uri ⇒ Object
The URI of this operator.
Instance Method Details
#each(solutions: RDF::Query::Solutions(), &block) ⇒ Object
By default, operators yield themselves and the operands, recursively.
Pass in solutions to have quantifiers resolved to those solutions.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |
#evaluate(bindings, formulae:, **options) ⇒ RDF::N3::Algebra::Builtin
Evaluates the builtin using the given variable bindings
by cloning the builtin replacing variables with their bindings recursively.
40 41 42 43 44 |
# File 'lib/rdf/n3/algebra/builtin.rb', line 40 def evaluate(bindings, formulae:, **) args = operands.map { |operand| operand.evaluate(bindings, formulae: formulae, **) } # Replace operands with bound operands self.class.new(*args, formulae: formulae, **) end |
#hash ⇒ Object
The builtin hash is the hash of it’s operands and NAME.
70 71 72 |
# File 'lib/rdf/n3/algebra/builtin.rb', line 70 def hash ([self.class.const_get(:NAME)] + operands).hash end |
#input_operand ⇒ RDF::Term
Return subject or object operand, or both, depending on which is considered an input.
25 26 27 28 |
# 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 |
#rank(solutions) ⇒ Integer
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.
15 16 17 18 19 |
# 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 |
#to_uri ⇒ Object
The URI of this operator.
75 76 77 |
# File 'lib/rdf/n3/algebra/builtin.rb', line 75 def to_uri self.class.const_get(:URI) end |