Class: LD::Patch::Algebra::Index

Inherits:
SPARQL::Algebra::Operator::Unary
  • Object
show all
Includes:
SPARQL::Algebra::Query
Defined in:
lib/ld/patch/algebra/index.rb

Overview

The LD Patch ‘index` operator.

Presuming that the input term identifies an rdf:List, returns the list element indexted by the single operand, or an empty solution set

Constant Summary collapse

NAME =
:index

Instance Method Summary collapse

Instance Method Details

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

Executes this upate on the given ‘writable` graph or repository.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional options

Options Hash (options):

  • starting (Array<RDF::Term>)

    terms

Returns:

  • (RDF::Query::Solutions)

    solutions with ‘:term` mapping



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ld/patch/algebra/index.rb', line 21

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

  results = terms.map do |term|
    list = RDF::List.new(subject: term, graph: queryable)
    list.at(index.to_i)
  end.flatten

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