Module: RDF::Query::Executer
- Included in:
- Graph::Memory
- Defined in:
- lib/rdf/query/executer.rb
Overview
A mix-in module for graph implementations. If a Graph implementation cannot delegate the execute
method to the underlying triplestore, then this module can be mixed in to provide Query execution. The graph must only implement the match
method.
Instance Method Summary collapse
-
#execute(query) ⇒ Object
Returns the result of executing
query
on this graph. -
#match(s, p, o, result = nil) ⇒ Object
Performs a match of
s
,p
, ando
and returns a set of bindings.
Instance Method Details
#execute(query) ⇒ Object
Returns the result of executing query
on this graph.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rdf/query/executer.rb', line 9 def execute(query) result = nil where_clause = query.where_clause begin s, p, o = where_clause.shift result = match(s, p, o, result) end while where_clause.any? && result.success? result end |
#match(s, p, o, result = nil) ⇒ Object
Performs a match of s
, p
, and o
and returns a set of bindings.
If s
, p
, or o
are Ruby symbols, then they will be considered variables, and they will be bound to all possible nodes in the result.
If s
, p
, or o
are BlankNodes that are unassociated with this graph, then they will be bound to all possible nodes in the result.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rdf/query/executer.rb', line 28 def match(s, p, o, result = nil) if result.nil? result = match_binding(s, p, o, RDF::Query::Binding.new) result else result = result.bindings.inject(RDF::Query::Result.new) do |r, b| r << match_binding(s, p, o, b) r end result end end |