[Activerdf] query results metadata
Eric Hanson
elh at cs.pdx.edu
Thu Oct 5 21:31:50 IST 2006
Eyal Oren wrote:
> On 10/05/06/10/06 09:36 -0700, Eric Hanson wrote:
>
>> Yeah exactly. Here's my "dream code", a simple minimal read/write REST
>> interface to a triple store, easily accessible via XMLHttpRequest.
> Hmm. I'm not sure about the usage scenario, but I'll go along for now.
>
> Maybe you're looking for something like ActiveResource (work-in-progress
> in Rails AFAIK), we could do that on top of ActiveRDF, as you outlined
> below. Some suggestions:
>
>> rdfrest.cgi
>> ---
>> #!/usr/bin/ruby
>>
>> require 'active_rdf3'
Upon further inspection, I was using the 0.2 libraries still. I thought
that transition was a little too smooth... :-)
>> 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' )
> (using new activerdf ConnectionPool.add_data_source :type => :redland etc.)
Found a bugish-type-thing where you have to explicitly require
"activerdf/adapter/redland" to get it to work. Submitted a bug report.
> case action
> when 'query' etc.
> instead of if
Sweet action.
>> if action == 'query'
>> query = cgi['query']
>> # results = db.query(query)
>> # this line grabs json results
>> jsonResults = db.query(query, 'someJsonResultsIndicator')
> sure, but use db.execute_sparql_query (see sparql.rb in trunk)
>> print jsonResults
>> elsif action == 'create'
>> s = IdentifiedResource.create(cgi['s'])
>> p = IdentifiedResource.create(cgi['p'])
> in activerdf3 this is now:
> RDFS::Resource.new cgi['s']
>> # is object a URI or a literal?
>> if /^[^ ]+:\/\//.match (cgi['o'])
>> o = IdentifiedResource.create(cgi['o'])
>> else
>> o = Literal.create(cgi['o'])
> literals are not wrapped anymore (for now)
>> 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
> with that it should all work.
>
>>> 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.
I'm in over my head on this one. Maybe I'll just wait for you to do it?
Thanks,
Eric
More information about the Activerdf
mailing list