Class: SPARQL::Algebra::Operator::Slice
- Inherits:
-
Ternary
- Object
- SPARQL::Algebra::Operator
- Ternary
- SPARQL::Algebra::Operator::Slice
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/slice.rb
Overview
The SPARQL GraphPattern slice
operator.
[25] LimitOffsetClauses ::= LimitClause OffsetClause? | OffsetClause LimitClause?
Constant Summary collapse
- NAME =
[:slice]
Constants inherited from Ternary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions
Executes this query on the given
queryable
graph or repository. -
#to_sparql(**options) ⇒ String
Extracts OFFSET and LIMIT.
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
Methods inherited from SPARQL::Algebra::Operator
#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, 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.
57 58 59 60 61 62 63 64 65 |
# File 'lib/sparql/algebra/operator/slice.rb', line 57 def execute(queryable, **, &block) offset = operands[0] == :_ ? 0 : operands[0].to_i limit = operands[1] == :_ ? -1 : operands[1].to_i @solutions = operands.last. execute(queryable, **.merge(depth: [: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.
72 73 74 75 76 |
# File 'lib/sparql/algebra/operator/slice.rb', line 72 def to_sparql(**) offset = operands[0].to_i unless operands[0] == :_ limit = operands[1].to_i unless operands[1] == :_ operands.last.to_sparql(offset: offset, limit: limit, **) end |