Class: SPARQL::Algebra::Operator::Slice

Inherits:
Ternary show all
Includes:
Query
Defined in:
lib/sparql/algebra/operator/slice.rb

Overview

The SPARQL GraphPattern slice operator.

Examples:

(prefix ((: <http://example.org/ns#>))
  (slice 1 1
    (project (?v)
      (order (?v)
        (bgp (triple ??0 :num ?v))))))

See Also:

Constant Summary

NAME =
[:slice]

Constants inherited from Ternary

Ternary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary collapse

Methods included from Query

#context=, #each_solution, #failed?, #matched?, #unshift, #variables

Methods inherited from Ternary

#initialize

Methods inherited from SPARQL::Algebra::Operator

arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, #prefixes, prefixes, prefixes=, #to_sse, #to_sxp, #variable?

Methods included from Evaluatable

#apply, #evaluate, #memoize

Methods included from Expression

cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Ternary

Instance Method Details

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

Executes this query on the given queryable graph or repository. Returns a subset of the solutions resulting from executing the third operand, an RDF::Queryable object by indexing in to the result set by the amount specified in the first operand and limiting the total number of solutions returned by the amount specified in the second operand.

If either the first or second operands are :_, they are not considered.

Examples:


(slice 1 2 (bgp (triple ?s ?p ?o)))   # Returns at most two solutions starting with the second solution.
(slice _ 2 (bgp (triple ?s ?p ?o)))   # Returns at most two solutions starting with the first solution.
(slice 1 _ (bgp (triple ?s ?p ?o)))   # Returns all solution after the first.

See Also:



42
43
44
45
46
47
# File 'lib/sparql/algebra/operator/slice.rb', line 42

def execute(queryable, options = {})
  @solutions = operands.last. execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
  @solutions.offset(operands[0]) unless operands[0] == :_
  @solutions.limit(operands[1]) unless operands[1] == :_
  @solutions
end

#optimizeUnion, RDF::Query

Returns an optimized version of this query.

Return optimized query



55
56
57
# File 'lib/sparql/algebra/operator/slice.rb', line 55

def optimize
  operands = operands.map(&:optimize)
end