[redland-dev] Serializing models

Dave Beckett Dave.Beckett at bristol.ac.uk
Mon Aug 15 23:13:59 BST 2005


Chris answered all the questions, yay, so I'll just chip in

On Mon, 2005-08-15 at 17:57 -0400, Christopher Schmidt wrote:
> 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?

Sounds good, if that's the standard ruby metaphor (it is for python).

> > 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.

That's the general idea.  If I could make SWIG use the counted string
interfaces it would probably remove some more strlen() calls in the
somebodies code, but since the librdf_THING_to_counted_string use an
int*, that's not so easy to translate across languages.

> > 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.

Yeah, most of the time you don't care about the Serializer class extra
functionality, you just want the string or the file to contain the
serialization of the model, but it allows extra features to be enabled.

Dave




More information about the redland-dev mailing list