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

Inherits:
Ternary show all
Includes:
Query
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/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 collapse

NAME =
[:slice]

Constants inherited from Ternary

Ternary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands

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

Methods inherited from Ternary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

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

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}) (defaults to: {})

    any additional keyword options

Yields:

  • (solution)

    each matching solution

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

See Also:



46
47
48
49
50
51
52
53
54
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/slice.rb', line 46

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

#optimizeUnion, RDF::Query

Returns an optimized version of this query.

Return optimized query

Returns:



62
63
64
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/slice.rb', line 62

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