Class: LD::Patch::Algebra::Reverse

Inherits:
SPARQL::Algebra::Operator::Unary show all
Includes:
SPARQL::Algebra::Evaluatable, SPARQL::Algebra::Query
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/algebra/reverse.rb

Overview

The LD Patch reverse operator

Finds all the terms which are the subject of triples where the operand is the predicate and input terms are objects.

Queries queryable for subjects where input terms are objects and the predicate is :p, by executing the reverse operand using input terms to get a set of output terms.

Examples:

(reverse :p)

Constant Summary collapse

NAME =
:reverse

Constants inherited from SPARQL::Algebra::Operator::Unary

SPARQL::Algebra::Operator::Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

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

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

Instance Attribute Summary

Attributes included from SPARQL::Algebra::Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from SPARQL::Algebra::Evaluatable

#apply, #evaluate, #memoize, #replace_aggregate!, #replace_vars!

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::Unary

#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, #mergable?, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sparql, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from SPARQL::Algebra::Expression

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

Methods included from RDF::Util::Logger

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

Constructor Details

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

Instance Method Details

#execute(queryable, options = {}) ⇒ RDF::Query::Solutions

Executes this upate on the given writable graph or repository.

Parameters:

Options Hash (options):

Returns:



27
28
29
30
31
32
33
34
35
36
37
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/algebra/reverse.rb', line 27

def execute(queryable, options = {})
  debug(options) {"Reverse"}
  op = operand(0)
  terms = Array(options.fetch(:terms))

  results = terms.map do |object|
    queryable.query({object: object, predicate: op}).map(&:subject)
  end.flatten

  RDF::Query::Solutions.new(results.map {|t| RDF::Query::Solution.new(path: t)})
end