[Activerdf] query results metadata
Eric Hanson
elh at cs.pdx.edu
Thu Oct 5 17:36:23 IST 2006
Eyal Oren wrote:
> On 10/04/06/10/06 13:33 -0700, Eric Hanson wrote:
>> Well, I want the user to be able to enter a SPARQL query cause letting
>> them write Ruby code would be dubious. And in general, the app I'm
>> working on is really general so it doesn't know in advance what schemas
>> will be present, so don't think I can use most of the really cool OO
>> stuff you're working on as far as I can tell. I'm going to be doing
>> client-side SPARQL query manipulation.
> ok, if you think that is the best solution in your case, I have extended
> the SPARQL adapter to not only take in an abstract Query object but also
> a complete SPARQL query string: see sparql.rb execute_sparql_query. You
> also need to supply a header that specifies the required result format.
> Now, what do you want to do with the query results? You just want me to
> give you your JSON results back?
>
> I can do that easily, but your usage of ActiveRDF is quite minimal then ;-)
Yeah exactly. Here's my "dream code", a simple minimal read/write REST
interface to a triple store, easily accessible via XMLHttpRequest.
(This is funny, posting code and requesting to make it work... I love
open source. :-)
rdfrest.cgi
---
#!/usr/bin/ruby
require 'active_rdf3'
require 'cgi'
cgi = CGI.new
action = cgi['action']
print "Content-type: text/html\r\n\r\n"
db = NodeFactory.connection( :adapter => :redland, :location =>
'/usr/local/redland-data/test' )
if action == 'query'
query = cgi['query']
# results = db.query(query)
# this line grabs json results
jsonResults = db.query(query, 'someJsonResultsIndicator')
print jsonResults
elsif action == 'create'
s = IdentifiedResource.create(cgi['s'])
p = IdentifiedResource.create(cgi['p'])
# is object a URI or a literal?
if /^[^ ]+:\/\//.match (cgi['o'])
o = IdentifiedResource.create(cgi['o'])
else
o = Literal.create(cgi['o'])
end
db.add(s,p,o)
print 'success'
elsif action == 'delete'
db.delete (cgi['s'], cgi['p'], cgi['o'])
print 'success'
else
print 'request param <em>action</em> not set or unrecognized'
end
>> Also, is there Redland JSON support? Dave added JSON serialization to
>> 1.0.4 though the results format URI is not documented and to get the
>> ruby bindings to work you need a patch from the source repo :-) [1] But
>> I did get it to work eventually.
> Well, if Redland comes with a stable version that does JSON I can hand
> it to you (same as above with generic SPARQL adapter).
It worked for me, just the Ruby bindings were borked. The patch is in
the Redland svn repo at:
http://svn.librdf.org/repository/bindings/trunk/ruby/
http://svn.librdf.org/view/bindings/trunk/ruby/
The call looks like:
results.to_string
(Redland::Uri.new("http://www.w3.org/2001/sw/DataAccess/json-sparql/"))
> In the meantime
> you can just patch activerdf to use sparql+json on redland, just look at
> sparql.rb and compare it to redland.rb. it should be straightforward to
> port json-results into the redland adapter.
My ruby skillz are pretty minimal but I'll take a look.
Thanks,
Eric
More information about the Activerdf
mailing list