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

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

Overview

The SPARQL GraphPattern slice operator.

[25] LimitOffsetClauses ::= LimitClause OffsetClause? | OffsetClause LimitClause?

Examples:

SPARQL Grammar

PREFIX : <http://example.org/ns#>

SELECT ?v
WHERE { :a ?p ?v }
ORDER BY ?v
OFFSET 100
LIMIT 1

SSE

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

See Also:

Constant Summary collapse

NAME =
[:slice]

Instance Attribute Summary

Attributes included from Query

#solutions

Instance Method Summary collapse

Methods included from Query

#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_boolean?, #query_yields_solutions?, #query_yields_statements?, #unshift, #variables

Instance Method Details

#execute(queryable, **options) {|solution| ... } ⇒ 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.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object})

    any additional keyword options

Yields:

  • (solution)

    each matching solution

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

See Also:



57
58
59
60
61
62
63
64
65
# File 'lib/sparql/algebra/operator/slice.rb', line 57

def execute(queryable, **options, &block)
  offset = operands[0] == :_ ? 0 : operands[0].to_i
  limit = operands[1] == :_ ? -1 : operands[1].to_i
  @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.each(&block) if block_given?
  @solutions
end

#to_sparql(**options) ⇒ String

Extracts OFFSET and LIMIT.

Returns:

  • (String)


72
73
74
75
76
# File 'lib/sparql/algebra/operator/slice.rb', line 72

def to_sparql(**options)
  offset = operands[0].to_i unless operands[0] == :_
  limit = operands[1].to_i unless operands[1] == :_
  operands.last.to_sparql(offset: offset, limit: limit, **options)
end