Class: SPARQL::Algebra::Operator::Order
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Order
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/order.rb
Overview
The SPARQL GraphPattern order operator.
Constant Summary
- NAME =
[:order]
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary (collapse)
-
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes this query on the given
queryablegraph or repository. -
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Methods included from Query
#context=, #each_solution, #failed?, #matched?, #unshift, #variables
Methods inherited from Binary
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
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::Binary
Instance Method Details
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes this query on the given queryable graph or repository.
Orders a solution set returned by executing operand(1) using
an array of expressions and/or variables specified in operand(0)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sparql/algebra/operator/order.rb', line 30 def execute(queryable, = {}) debug("Order", ) @solutions = operands.last.execute(queryable, .merge(:depth => [:depth].to_i + 1)).order do |a, b| operand(0).inject(false) do |memo, op| debug("=> #{op.inspect}", ) memo ||= begin comp = case op when RDF::Query::Variable a[op.to_sym] <=> b[op.to_sym] when Operator, Array a_eval, b_eval = op.evaluate(a), op.evaluate(b) if a_eval.nil? RDF::Literal(-1) elsif b_eval.nil? RDF::Literal(1) else Operator::Compare.evaluate(a_eval, b_eval) end else raise TypeError, "Unexpected order expression #{op.inspect}" end comp = -comp if op.is_a?(Operator::Desc) comp == 0 ? false : comp end end || 0 # They compare equivalently if there are no matches end end |
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Return optimized query
64 65 66 |
# File 'lib/sparql/algebra/operator/order.rb', line 64 def optimize operands = operands.map(&:optimize) end |