Sha256: 75cf8f07fa1cb865c6396872a13f46ab953af8aafe16f9a77b718b0b09b771fb
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
module LD::Patch::Algebra ## # 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 class Index < SPARQL::Algebra::Operator::Unary include SPARQL::Algebra::Query NAME = :index ## # Executes this upate on the given `writable` graph or repository. # # @param [RDF::Queryable] queryable # the graph or repository to write # @param [Hash{Symbol => Object}] options # any additional options # @option options [Array<RDF::Term>] starting terms # @return [RDF::Query::Solutions] solutions with `:term` mapping def execute(queryable, options = {}) debug(options) {"Index"} terms = Array(options.fetch(:terms)) index = operand(0) results = terms.map do |term| list = RDF::List.new(term, queryable) list.at(index.to_i) end.flatten RDF::Query::Solutions.new(results.map {|t| RDF::Query::Solution.new(path: t)}) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ld-patch-0.2.0 | lib/ld/patch/algebra/index.rb |
ld-patch-0.1.1 | lib/ld/patch/algebra/index.rb |
ld-patch-0.1.0 | lib/ld/patch/algebra/index.rb |