Class: SPARQL::Algebra::Operator::Filter
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Filter
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/filter.rb
Overview
The SPARQL GraphPattern filter operator.
Constant Summary
- NAME =
[:filter]
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.
Then it passes each solution through one or more filters and removes
those that evaluate to false or generate a TypeError.
Note that the last operand returns a solution set, while the first is an expression. This may be a variable, simple expression, or exprlist.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sparql/algebra/operator/filter.rb', line 35 def execute(queryable, = {}) debug("Filter #{operands.first}", ) @solutions = operands.last.execute(queryable, .merge(:depth => [:depth].to_i + 1)) debug("=>(before) #{@solutions.map(&:to_hash).inspect}", ) @solutions = @solutions.filter do |solution| # Evaluate the solution, which will return true or false #debug("===>(evaluate) #{operands.first.inspect} against #{solution.to_hash.inspect}", options) # From http://www.w3.org/TR/rdf-sparql-query/#tests # FILTERs eliminate any solutions that, when substituted into the expression, either # result in an effective boolean value of false or produce an error. begin res = boolean(operands.first.evaluate(solution)).true? debug("===>#{res} #{solution.to_hash.inspect}", ) res rescue debug("rescue(#{$!}): #{solution.to_hash.inspect}", ) false end end @solutions = RDF::Query::Solutions.new(@solutions) debug("=>(after) #{@solutions.map(&:to_hash).inspect}", ) @solutions end |
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Return optimized query
66 67 68 |
# File 'lib/sparql/algebra/operator/filter.rb', line 66 def optimize operands = operands.map(&:optimize) end |