Class: Redlander::Query::Results Private
- Inherits:
-
Object
- Object
- Redlander::Query::Results
- Includes:
- Enumerable
- Defined in:
- lib/redlander/query/results.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #bindings? ⇒ Boolean private
- #boolean? ⇒ Boolean private
- #each ⇒ Object private
- #graph? ⇒ Boolean private
-
#initialize(q, options = {}) ⇒ void
constructor
private
Query the model RDF graph using a query language.
- #process(model) ⇒ Object private
- #syntax? ⇒ Boolean private
Constructor Details
#initialize(q, options = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The returned value is determined by the type of the query:
- Boolean
-
for SPARQL ASK queries (ignores block, if given)
- Redlander::Model
-
for SPARQL CONSTRUCT queries
if given a block, yields the constructed statements to it instead
- Array<Hash>
-
for SPARQL SELECT queries
where hash values are Redlander::Node instances; if given a block, yields each binding hash to it
-
nil, if query fails
Query the model RDF graph using a query language
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/redlander/query/results.rb', line 17 def initialize(q, = {}) language = [:language] || "sparql10" language_uri = [:language_uri] && [:language_uri].to_s base_uri = [:base_uri] && [:base_uri].to_s @rdf_query = Redland.librdf_new_query(Redlander.rdf_world, language, language_uri, q, base_uri) raise RedlandError, "Failed to create a #{language.upcase} query from '#{q}'" if @rdf_query.null? ObjectSpace.define_finalizer(self, self.class.send(:finalize_query, @rdf_query)) end |
Instance Method Details
#bindings? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/redlander/query/results.rb', line 72 def bindings? !Redland.librdf_query_results_is_bindings(@rdf_results).zero? end |
#boolean? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/redlander/query/results.rb', line 76 def boolean? !Redland.librdf_query_results_is_boolean(@rdf_results).zero? end |
#each ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/redlander/query/results.rb', line 61 def each if block_given? while Redland.librdf_query_results_finished(@rdf_results).zero? yield self Redland.librdf_query_results_next(@rdf_results) end else enum_for(:each) end end |
#graph? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'lib/redlander/query/results.rb', line 80 def graph? !Redland.librdf_query_results_is_graph(@rdf_results).zero? end |
#process(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 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 57 58 59 |
# File 'lib/redlander/query/results.rb', line 28 def process(model) @rdf_results = Redland.librdf_model_query_execute(model.rdf_model, @rdf_query) begin case when bindings? if block_given? return nil if @rdf_results.null? each { yield process_bindings } else return [] if @rdf_results.null? map { process_bindings } end when boolean? return nil if @rdf_results.null? process_boolean when graph? return nil if @rdf_results.null? if block_given? process_graph { |statement| yield statement } else process_graph end when syntax? process_syntax else raise RedlandError, "Cannot determine the type of query results" end ensure Redland.librdf_free_query_results(@rdf_results) end end |
#syntax? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 |
# File 'lib/redlander/query/results.rb', line 84 def syntax? !Redland.librdf_query_results_is_syntax(@rdf_results).zero? end |