Class: RDF::N3::Algebra::Log::Includes

Inherits:
SPARQL::Algebra::Operator::Binary show all
Includes:
Builtin, SPARQL::Algebra::Query, SPARQL::Algebra::Update
Defined in:
vendor/bundler/ruby/2.7.0/bundler/gems/rdf-n3-edf63ce7750f/lib/rdf/n3/algebra/log/includes.rb

Overview

The subject formula includes the object formula.

Formula A includes formula B if there exists some substitution which when applied to B creates a formula B' such that for every statement in B' is also in A, every variable universally (or existentially) quantified in B' is quantified in the same way in A.

Variable substitution is applied recursively to nested compound terms such as formulae, lists and sets.

(Understood natively by cwm when in in the antecedent of a rule. You can use this to peer inside nested formulae.)

Direct Known Subclasses

NotIncludes

Constant Summary collapse

NAME =
:logIncludes
URI =
RDF::N3::Log.includes

Constants included from Util::Logger

Util::Logger::IOWrapper

Constants inherited from SPARQL::Algebra::Operator::Binary

SPARQL::Algebra::Operator::Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

SPARQL::Algebra::Operator::ARITY, SPARQL::Algebra::Operator::IsURI

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Attributes included from SPARQL::Algebra::Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Builtin

#each, #evaluate, #hash, #input_operand, #rank, #to_uri

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, #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_names, #has_graph?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_term?, #has_triple?, #invalid?, #method_missing, #objects, #predicates, #project_graph, #quads, #respond_to_missing?, #statements, #subjects, #supports?, #terms, #to_a, #to_h, #to_set, #triples, #valid?, #validate!

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Countable

#count, #empty?

Methods included from Isomorphic

#bijection_to, #isomorphic_with?

Methods included from SPARQL::Algebra::Update

#graph_name=, #unshift, #variables

Methods included from SPARQL::Algebra::Query

#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_boolean?, #query_yields_solutions?, #query_yields_statements?, #unshift, #variables

Methods inherited from SPARQL::Algebra::Operator::Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, base_uri, #base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #formulae, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Dynamic Method Handling

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

Instance Method Details

#execute(queryable, solutions:, **options) ⇒ RDF::Solutions

Creates a repository constructed by evaluating the subject against queryable and queries object against that repository. Either retuns a single solution, or no solutions

Parameters:

Options Hash (**options):

Returns:

  • (RDF::Solutions)

    distinct solutions



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-n3-edf63ce7750f/lib/rdf/n3/algebra/log/includes.rb', line 28

def execute(queryable, solutions:, **options)
  @queryable = queryable
  RDF::Query::Solutions(solutions.map do |solution|
    subject = operand(0).evaluate(solution.bindings, formulae: formulae)
    object = operand(1).evaluate(solution.bindings, formulae: formulae)
    log_debug(NAME) {"subject: #{SXP::Generator.string subject.to_sxp_bin}"}
    log_debug(NAME) {"object: #{SXP::Generator.string operand(1).to_sxp_bin}"}

    # Nothing to do if variables aren't resolved.
    next unless subject && object

    solns = log_depth {subject.execute(queryable, solutions: RDF::Query::Solutions(solution), **options)}
    log_debug("(logIncludes solutions pre-filter)") {SXP::Generator.string solns.to_sxp_bin}

    # filter solutions where not all variables in antecedant are bound.
    vars = subject.universal_vars
    solns = solns.filter do |solution|
      vars.all? {|v| solution.bound?(v)}
    end
    log_debug("(logIncludes subject)") {SXP::Generator.string solns.to_sxp_bin}
    next if solns.empty?

    repo = RDF::N3::Repository.new << subject

    # Query object against repo
    solns = log_depth {object.execute(repo, solutions: solns, **options)}

    # filter solutions where not all variables in antecedant are bound.
    vars = object.universal_vars
    solns = solns.filter do |soln|
      vars.all? {|v| soln.bound?(v)}
    end
    log_debug("(logIncludes object)") {SXP::Generator.string solns.to_sxp_bin}
    solns
  end.flatten.compact)
end