Sha256: 66bae22cbc1ad14b297188df155241923830a4fa4f42b4d8f6bf74be95289e21

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 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(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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ld-patch-3.3.0 lib/ld/patch/algebra/index.rb
ld-patch-3.2.2 lib/ld/patch/algebra/index.rb
ld-patch-3.2.0 lib/ld/patch/algebra/index.rb
ld-patch-3.1.3 lib/ld/patch/algebra/index.rb
ld-patch-3.1.2 lib/ld/patch/algebra/index.rb
ld-patch-3.1.1 lib/ld/patch/algebra/index.rb
ld-patch-3.1.0 lib/ld/patch/algebra/index.rb
ld-patch-0.3.3 lib/ld/patch/algebra/index.rb
ld-patch-0.3.2 lib/ld/patch/algebra/index.rb
ld-patch-0.3.1 lib/ld/patch/algebra/index.rb
ld-patch-0.3.0 lib/ld/patch/algebra/index.rb
ld-patch-0.3.0.beta2 lib/ld/patch/algebra/index.rb
ld-patch-0.3.0.beta1 lib/ld/patch/algebra/index.rb