Method: Query#where

Defined in:
lib/active_rdf/queryengine/query.rb

#where(s, p, o, c = nil) ⇒ Object

Adds where clauses (s,p,o) where each constituent is either variable (:s) or an RDFS::Resource. Keyword queries are specified with the special :keyword symbol: Query.new.select(:s).where(:s, :keyword, ‘eyal’)



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/active_rdf/queryengine/query.rb', line 137

def where s,p,o,c=nil
case p
when :keyword
	# treat keywords in where-clauses specially
	keyword_where(s,o)
else
	# remove duplicate variable bindings, e.g.
	# where(:s,type,:o).where(:s,type,:oo) we should remove the second clause, 
	# since it doesn't add anything to the query and confuses the query 
	# generator. 
	# if you construct this query manually, you shouldn't! if your select 
	# variable happens to be in one of the removed clauses: tough luck.

	unless s.respond_to?(:uri) or s.is_a?(Symbol)
		raise(ActiveRdfError, "cannot add a where clause with s #{s}: s must be a resource or a variable")
	end
	unless p.respond_to?(:uri) or p.is_a?(Symbol)
		raise(ActiveRdfError, "cannot add a where clause with p #{p}: p must be a resource or a variable")
	end

	@where_clauses << [s,p,o,c].collect{|arg| parametrise(arg)}
end
  self
end