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

Inherits:
SPARQL::Algebra::Operator::Unary show all
Includes:
SPARQL::Algebra::Query
Defined in:
vendor/bundler/ruby/3.0.0/bundler/gems/ld-patch-1e120ae2cd50/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

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

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::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, #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::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:



21
22
23
24
25
26
27
28
29
30
31
32
# File 'vendor/bundler/ruby/3.0.0/bundler/gems/ld-patch-1e120ae2cd50/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