Class: RDF::Query
- Inherits:
-
Object
- Object
- RDF::Query
- Defined in:
- lib/rdf/query.rb,
lib/rdf/query/result.rb,
lib/rdf/query/binding.rb,
lib/rdf/query/executer.rb
Overview
An RDF graph query. This represents a complex query that joins several triples. To query for a simple triple, see the match
method on RDF::Graph::Memory.
A Query is created then passed to the execute
method on a graph. In some graph implementations the execute method may delegate to the underlying triple store, but in other cases the execute
method may be mixed in from RDF::Query::Executer.
At some point I’d like to steal the query DSL from Semitar.
Example:
q = RDF::Query.new.select(:a, :c).
where(:a, RDF::type, :b).
and(:b, RDFS::subClassOf, RDF::Property).
and(:b, RDFS::comment, :c)
result = some_graph.execute(q)
Defined Under Namespace
Modules: Executer Classes: Binding, Result
Instance Method Summary collapse
-
#initialize ⇒ Query
constructor
Creates a new Query.
-
#select(*a) ⇒ Object
Adds items to the select clause of this query.
-
#select_clause ⇒ Object
Returns the select clause for this query.
-
#where(s, p, o) ⇒ Object
(also: #and)
Adds the triple s p o to the where clause of this query.
-
#where_clause ⇒ Object
Returns the where clause for this query.
Constructor Details
#initialize ⇒ Query
Creates a new Query.
23 24 25 26 |
# File 'lib/rdf/query.rb', line 23 def initialize @select_clause = [] @where_clause = [] end |
Instance Method Details
#select(*a) ⇒ Object
Adds items to the select clause of this query. When this query is executed, the results will include bindings for these variables.
30 31 32 33 |
# File 'lib/rdf/query.rb', line 30 def select(*a) @select_clause = a self end |
#select_clause ⇒ Object
Returns the select clause for this query.
36 37 38 |
# File 'lib/rdf/query.rb', line 36 def select_clause @select_clause.clone end |
#where(s, p, o) ⇒ Object Also known as: and
Adds the triple s p o to the where clause of this query. When the query is executed, the where clause will constrain the results.
42 43 44 45 |
# File 'lib/rdf/query.rb', line 42 def where(s, p, o) @where_clause << [s, p, o] self end |
#where_clause ⇒ Object
Returns the where clause for this query.
48 49 50 |
# File 'lib/rdf/query.rb', line 48 def where_clause @where_clause.clone end |