Module: SPARQL::Algebra::Query Abstract
- Included in:
- Operator::Ask, Operator::Base, Operator::Construct, Operator::Dataset, Operator::Describe, Operator::Distinct, Operator::Filter, Operator::Join, Operator::LeftJoin, Operator::Order, Operator::Prefix, Operator::Project, Operator::Reduced, Operator::Slice, Operator::Union
- Defined in:
- lib/sparql/algebra/query.rb
Overview
A SPARQL algebra query, may be duck-typed as RDF::Query.
Mixin with SPARQL::Algebra::Operator to provide query-like operations on graphs and filters
Instance Attribute Summary collapse
-
#solutions ⇒ RDF::Query::Solutions
readonly
The solution sequence for this query.
Instance Method Summary collapse
-
#context=(value) ⇒ RDF::URI, RDF::Query::Variable
Add context to sub-items, unless they already have a context.
-
#each_solution {|solution| ... } ⇒ Enumerator
(also: #each)
Enumerates over each matching query solution.
-
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Executes this query on the given
queryable
graph or repository. -
#failed? ⇒ Boolean
Returns
true
if this query did not match when last executed. -
#matched? ⇒ Boolean
Returns
true
if this query matched when last executed. -
#unshift(query)
Prepends an operator.
-
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
The variables used in this query.
Instance Attribute Details
#solutions ⇒ RDF::Query::Solutions (readonly)
The solution sequence for this query.
32 33 34 |
# File 'lib/sparql/algebra/query.rb', line 32 def solutions @solutions end |
Instance Method Details
#context=(value) ⇒ RDF::URI, RDF::Query::Variable
Add context to sub-items, unless they already have a context
57 58 59 60 61 62 |
# File 'lib/sparql/algebra/query.rb', line 57 def context=(value) operands.each do |operand| operand.context = value if operand.respond_to?(:context) && operand.context != false end value end |
#each_solution {|solution| ... } ⇒ Enumerator Also known as: each
Enumerates over each matching query solution.
94 95 96 |
# File 'lib/sparql/algebra/query.rb', line 94 def each_solution(&block) solutions.each(&block) end |
#execute(queryable, options = {}) ⇒ RDF::Query::Solutions
Executes this query on the given queryable
graph or repository.
50 51 52 |
# File 'lib/sparql/algebra/query.rb', line 50 def execute(queryable, = {}) raise NotImplementedError, "#{self.class}#execute(#{queryable})" end |
#failed? ⇒ Boolean
Returns true
if this query did not match when last executed.
When the solution sequence is empty, this method can be used to determine whether the query failed to match or not.
72 73 74 |
# File 'lib/sparql/algebra/query.rb', line 72 def failed? solutions.empty? end |
#matched? ⇒ Boolean
Returns true
if this query matched when last executed.
When the solution sequence is empty, this method can be used to determine whether the query matched successfully or not.
84 85 86 |
# File 'lib/sparql/algebra/query.rb', line 84 def matched? !failed? end |
#unshift(query)
This method returns an undefined value.
Prepends an operator.
15 16 17 18 |
# File 'lib/sparql/algebra/query.rb', line 15 def unshift(query) @operands.unshift(query) self end |
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
The variables used in this query.
24 25 26 |
# File 'lib/sparql/algebra/query.rb', line 24 def variables operands.inject({}) {|hash, o| o.executable? ? hash.merge!(o.variables) : hash} end |