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:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/algebra/builtin.rb

Overview

Behavior for N3 builtin operators

Constant Summary

Constants included from Util::Logger

Util::Logger::IOWrapper

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods included from Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Methods included from Enumerable

add_entailment, #canonicalize, #canonicalize!, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #method_missing, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #respond_to_missing?, #statement?, #statements, #subject?, #subjects, #supports?, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Isomorphic

#bijection_to, #isomorphic_with?

Methods included from Countable

#count, #empty?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Enumerable

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 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/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.

Parameters:

Returns:

See Also:

  • SPARQL::Algebra::Expression.evaluate


40
41
42
43
44
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/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

#hashObject

The builtin hash is the hash of it's operands and NAME.

See Also:

  • Value#hash


70
71
72
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/algebra/builtin.rb', line 70

def hash
  ([self.class.const_get(:NAME)] + operands).hash
end

#input_operandRDF::Term

Return subject or object operand, or both, depending on which is considered an input.

Returns:



25
26
27
28
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/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.

Parameters:

Returns:

  • (Integer)

    rake for ordering, lower numbers have fewer unbound output variables.



15
16
17
18
19
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/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_uriObject

The URI of this operator.



75
76
77
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/algebra/builtin.rb', line 75

def to_uri
  self.class.const_get(:URI)
end