def SquishQuery.ask(query,db)
tables=[]
query.full_clauses.each do |clause|
vars={}
p,s,o=clause[0..2]
if p.gsub!(/^\?/,"")
vars['p']=p
p=nil
end
if s.gsub!(/^\?/,"")
vars['s']=s
s=nil
end
if o.gsub!(/^\?/,"")
vars['o']=o
o=nil
end
bindings = ResultSet.new
a = db.ask(Statement.new(s,p,o)).statements.each do |s|
vb={}
vb[vars['s']] = s.subject.to_s if (vars['s'] != nil)
vb[vars['p']] = s.predicate.to_s if (vars['p'] != nil)
vb[vars['o']] = s.object.to_s if (vars['o'] != nil)
bindings.push(ResultRow.new(vb))
end
tables.push bindings
end
htmllog = ""
current = tables.shift
begin
while (!tables.empty?)
nx = chooseTable(tables, current.vars)
joinvars = current.vars & nx.vars
htmllog += "<h2>Matching next constraint: vars: #{joinvars.inspect} </h2>"
htmllog += "<h3>Current matches:</h3>" + current.html_report
old=current
new = current.match nx, joinvars
current = new
htmllog += "<h3>New matches:</h3>"+current.html_report
end
rescue
if (!tables.empty?)
tables.each do |t|
end
current = ResultSet.new
else
end
end
current.debug_report += htmllog
answers=ResultSet.new
answers.debug_report=current.debug_report
dup={}
current.each do |row|
r=''
row.values.each_key do |col|
r += col.to_s + row.values[col]
end
if (!dup[r.hash])
dup[r.hash] =1
answers.push row
end
end
return answers
end