[redland-dev] json serialization

Eric Hanson elh at cs.pdx.edu
Tue Jul 11 23:20:13 BST 2006


Dave Beckett wrote:
> Eric Hanson wrote:
>> I noticed Rasql can output in JSON which is really cool!
>>
>> Any plans to add JSON as an serialization format from
>> librdf_serializer_serialize_model_to_string?  Anybody written their own?
> 
> There's no plans, mostly because of the usual reasons (time) but also that I
> haven't seen a decent rdf-triples-in-JSON syntax design yet.  The SPARQL
> results in JSON was an easy translation in comparison.

Ok, my primary concern at this point is just getting SPARQL results in
JSON anyway.

Though I'm having some troubles with that as well.

Here's the Ruby code I'm trying:

require 'rdf/redland.rb'
queryStr = 'select ?s ?p ?o where {?s ?p ?o}'
store = Redland::HashStore.read_store('wine', '/usr/local/redland-data')
model = Redland::Model.new(store)
query = Redland::Query.new(queryStr, 'sparql')
results = query.execute(model)
# bad line
print results.to_string(Redland::Uri.new("json"), nil)

Produces:
hash-type='bdb',new='no', dir='/usr/local/redland-data',
write='yes',contexts='yes'
/usr/local/lib/ruby/1.8/rdf/redland/queryresults.rb:103:in
`librdf_query_results_to_string': in method
'librdf_query_results_to_string', argument 2 of type 'librdf_uri *'
(TypeError)
        from /usr/local/lib/ruby/1.8/rdf/redland/queryresults.rb:103:in
`to_string'
        from redland.rhtml:10


The Ruby API function is:

# File rdf/redland/queryresults.rb, line 91
    def to_string(format_uri = nil, base_uri = nil)
      if self.is_graph?()
        tmpmodel=Model.new()
        tmpmodel.add_statements(self.as_stream())
        serializer=Serializer.new()
        return serializer.model_to_string(base_uri, tmpmodel)
      end

      if not self.is_boolean?() and not self.is_bindings?()
        raise RedlandError.new("Unknown query result format cannot be
written as a string")
      end

      return Redland.librdf_query_results_to_string(@results,
format_uri, base_uri)
    end

It says the second argument has a type error, though really the second
argument on the C API side is the first argument on the Ruby side (cause
world is wrapped up in the API).  So what's going on here?  I've tried
various combinations without much luck.

Thanks,
Eric



More information about the redland-dev mailing list