[redland-dev] Serializing models

Christopher Schmidt crschmidt at crschmidt.net
Mon Aug 15 22:57:49 BST 2005


On Mon, Aug 15, 2005 at 04:15:54PM -0500, Jorge Santos wrote:
> Hello, I'm looking into returning a string representing a rdf/xml
> representation of a model using the Ruby bindings and I have found a
> couple odd thins:
> 
> 1.  There is no wrapper for the librdf_model_to_string () function.  I
> wrote a simple wrapper for this:

In Python, the string representation of a model is also the to_string
method (so "print model" actually prints the RDF/XML version of the
model): -- is there anything in Ruby like this? Maybe it would be a good
idea to add that as well as the to_s method?
> 
> 2.  What's with librdf_model_to_counted_string () anyway?  What's the
> use of knowing the length of the string?

It's not useful in any of the scripting languages, so far as I am aware,
but is useful in C-type languages, where you need to work at a lower
level. So, I think in Ruby that shouldn't matter.

> 3.  The initialize function for Redland::Serializer starts like so:
> 
>     # Constructor - create a new Serializer object
>     # name -  the serializer factory name
>     # mime_type -  the MIME type of the syntax
>     # uri -  URI of syntax
>     def initialize(name="",mime_type="application/rdf+xml",uri=nil)
> 
> But  in model.rb you can read:
> 
>     # saves this model to the specified filename
>     def save(filename)
>       serializer = Serializer.new(filename)
> 
> So what's the deal with passing the serializer the filename?

Not sure I understand this without reading the code, and Ruby in general
scares me, so I think I'll take a pass on this one.

> 4.  So what's the deal with having the Serializer, why aren't all its
> functions in Model (as many of them seem to be)?

Most of the serializer functions actually aren't available on the Model.
The point of the Model is to be able to store data and retrieve it: the
Serializer is designed to simply turn the data into a file that can be
saved. On the Serializer, you can set the namespace, syntax, save it to
a file, etc. On the Model, you can find statements, add statements, etc.

The Serialization has nothing to do with the model other than
convenience. The fact that it has a to_string method is simply designed
to allow finding out what's in the model quickly: the serializer is
needed for the full featureset.

-- 
Christopher Schmidt
Freelance Web Developer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.gnomehack.com/pipermail/redland-dev/attachments/20050815/454ba5ca/attachment.pgp


More information about the redland-dev mailing list