[redland-dev] setting parser feature through ruby api

Dave Beckett dave at dajobe.org
Fri Dec 8 08:10:25 UTC 2006


Eyal Oren wrote:
> Hi,
> 
> I'm trying to use rapper through the ruby API. I've got it to work
> successfully (and great, thanks!) over command-line, but I have the
> feeling that the API documentation is not completely up-to-date?

All the docs are generated from the sources in subversion so
occasionally things are fixed that are mentioned in the docs
but since there was a recent release, it should be close now.

> The following works:
> 
> model = Redland::Model.new
> parser = Redland::Parser.new('rdfxml')
> parser.parse_into_model(model, url)
> triples = Redland.librdf_model_to_string(model.model, nil, 'ntriples',
> '', nil)
> 
> Calling model.to_string('ntriples'), which should have worked according
> to the docs [1] didn't actually work.

The example.rb example script for ruby contains:

size=model.to_string(name="ntriples",
base_uri=Redland::Uri.new("http://example.org/base#")).length()

so you should be able to use

str = model.to_string(name="ntriples",
base_uri=Redland::Uri.new("http://example.org/base#"))

although strictly a base uri isn't needed and should be optional

> Now I'm trying to set the parser to scan for rdf:RDF fragments (rapper
> --scan) but can't figure out how to use parser.feature. I've tried
> Redland::librdf_parser_set_feature(@parser,uri.uri,value.node) but
> didn't know which uri and value to use exactly. I found
> http://lists.usefulinc.com/pipermail/redland-dev/2005-July/001037.html
> but couldn't make it work.
> 
> Does anybody know how to enable this parsing feature in the Ruby API?

It's the method feature on the parser class.  It is documented.

What isn't documented is well is the URIs to use(*), the email above
gives the answer.  You want
URI: http://feature.librdf.org/raptor-scanForRDF
value: rdf literal node with string "1"
(or any datatyped literal with string "1")

and you want to try it, because I haven't.

> And a bonus question: does rapper do content-negotiation (e.g. asking
> for application/rdf+xml for sites that serve both html and rdf on the
> same URI) or is there a way to enable it?

You want '-g' for guess or '-i guess' which uses it as a parser.
The latter can be used in anything that uses raptor.


(*) The problem is, where does the documentation go?  It's
about parsers, which are provided by raptor, but the API
is in redland, and you may be accessing it by any of the N
language bindings.  That makes ~10 places.  Plus the tutorial
documentation, manual pages for raptor, ... so more like 12.

Nightmare!  And as they say: Don't Repeat Yourself.

Dave

> 
> -eyal
> 
> [1] http://librdf.org/docs/rdoc/classes/Redland/Parser.html
> _______________________________________________
> redland-dev mailing list
> redland-dev at lists.librdf.org
> http://lists.gnomehack.com/mailman/listinfo/redland-dev
> 
> !DSPAM:45743535238701804284693!
> 
> 
> 



More information about the redland-dev mailing list