Class: LD::Patch::Algebra::Reverse
- Inherits:
-
SPARQL::Algebra::Operator::Unary
- Object
- SPARQL::Algebra::Operator::Unary
- LD::Patch::Algebra::Reverse
- Includes:
- SPARQL::Algebra::Evaluatable, SPARQL::Algebra::Query
- Defined in:
- 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.
Constant Summary collapse
- NAME =
:reverse
Instance Method Summary collapse
-
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Executes this upate on the given
writablegraph or repository.
Instance Method Details
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Executes this upate on the given writable graph or repository.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ld/patch/algebra/reverse.rb', line 27 def execute(queryable, = {}) debug() {"Reverse"} op = operand(0) terms = Array(.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 |