Module: SPARQL::Algebra::Query Abstract
- Included in:
- Operator::Alt, Operator::Ask, Operator::Base, Operator::Construct, Operator::Dataset, Operator::Describe, Operator::Distinct, Operator::Extend, Operator::Filter, Operator::Graph, Operator::Group, Operator::Join, Operator::LeftJoin, Operator::Minus, Operator::NotOneOf, Operator::Order, Operator::Path, Operator::PathOpt, Operator::PathPlus, Operator::PathRange, Operator::PathStar, Operator::PathZero, Operator::Prefix, Operator::Project, Operator::Reduced, Operator::Reverse, Operator::Seq, Operator::Service, Operator::Slice, Operator::Table, Operator::Union, Operator::Using
- 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
-
#each_solution {|solution| ... } ⇒ Enumerator
Enumerates over each matching query solution.
-
#empty? ⇒ Boolean
Determine if this is an empty query, having no operands.
-
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Graph, ...
Executes this query on the given
queryable
graph or repository. -
#failed? ⇒ Boolean
Returns
true
if this query did not match when last executed. -
#graph_name=(value) ⇒ RDF::URI, RDF::Query::Variable
Add graph_name to sub-items, unless they already have a graph_name.
-
#matched? ⇒ Boolean
Returns
true
if this query matched when last executed. -
#query_yields_boolean? ⇒ Boolean
Query results in a boolean result (e.g., ASK).
-
#query_yields_solutions? ⇒ Boolean
Query results solutions (e.g., SELECT).
-
#query_yields_statements? ⇒ Boolean
Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE).
-
#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. This is only set
32 33 34 |
# File 'lib/sparql/algebra/query.rb', line 32 def solutions @solutions end |
Instance Method Details
#each_solution {|solution| ... } ⇒ Enumerator
Enumerates over each matching query solution.
122 123 124 |
# File 'lib/sparql/algebra/query.rb', line 122 def each_solution(&block) solutions.each(&block) end |
#empty? ⇒ Boolean
Determine if this is an empty query, having no operands
94 95 96 |
# File 'lib/sparql/algebra/query.rb', line 94 def empty? self.operands.empty? end |
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Graph, ...
Executes this query on the given queryable
graph or repository.
55 56 57 |
# File 'lib/sparql/algebra/query.rb', line 55 def execute(queryable, **, &block) 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.
77 78 79 |
# File 'lib/sparql/algebra/query.rb', line 77 def failed? solutions.empty? end |
#graph_name=(value) ⇒ RDF::URI, RDF::Query::Variable
Add graph_name to sub-items, unless they already have a graph_name
62 63 64 65 66 67 |
# File 'lib/sparql/algebra/query.rb', line 62 def graph_name=(value) operands.each do |operand| operand.graph_name = value if operand.respond_to?(:graph_name) && operand.graph_name != false end value 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.
89 90 91 |
# File 'lib/sparql/algebra/query.rb', line 89 def matched? !failed? end |
#query_yields_boolean? ⇒ Boolean
Query results in a boolean result (e.g., ASK)
100 101 102 |
# File 'lib/sparql/algebra/query.rb', line 100 def query_yields_boolean? false end |
#query_yields_solutions? ⇒ Boolean
Query results solutions (e.g., SELECT)
112 113 114 |
# File 'lib/sparql/algebra/query.rb', line 112 def query_yields_solutions? !(query_yields_boolean? || query_yields_statements?) end |
#query_yields_statements? ⇒ Boolean
Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE)
106 107 108 |
# File 'lib/sparql/algebra/query.rb', line 106 def query_yields_statements? false 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.respond_to?(:variables) ? hash.merge(o.variables) : hash} end |