- From: Peter Ansell <ansell.peter@gmail.com>
- Date: Sun, 1 Jun 2008 12:17:02 +1000
- To: cdr <_@whats-your.name>
- Cc: "Semantic Web" <semantic-web@w3.org>
2008/6/1 cdr <_@whats-your.name>: > On Sun Jun 01, 2008 at 08:13:04AM +1000, Peter Ansell wrote: >> >> Hi all, >> >> I am not an expert in perl, but I have hacked together a script that >> requires me to convert an rdf/xml document into an N3/NTriples >> document. My current ideas are as follows, but I can't make them work >> properly. >> >> $rdfXmlParser = new RDF::Notation3::XML(); >> $model = $rdfXmlParser->parse_string($rdf_data); >> >> $rdfN3RDFCore = new RDF::Notation3::RDFCore(); >> $n3 = $rdfN3RDFCore->get_n3($model); >> >> print($n3); > > you have the right idea.. > > heres a great introduction to Redland & Perl: > > http://kill.devc.at/internet/semantic-web/rdf/redland/tutorial > > > also if you dig, you can probably find 'triplr' source in redland's SVN (maybe not) or even use the test suites as some example code if the doc examples are lacking. > > also the W3C site is mostly written in Perl and RDF, and its source code is available fpr perusal as well.. > > > you'll probbaly find more ready-made examples on blogs and wikis for Python and Ruby.. I found what I needed after a bit of searching: $storage= new RDF::Redland::Storage("hashes", "test", "new='yes',hash-type='memory'"); $model= new RDF::Redland::Model($storage, ""); $parser = new RDF::Redland::Parser (undef, "application/rdf+xml") or die "Failed to find parser\n"; $uri = new RDF::Redland::URI ("file:".$directory."/".$file); $parser->parse_into_model ($uri, $base_uri, $model); $serializer = new RDF::Redland::Serializer("ntriples") or die "Failed to find serializer"; $n3 = $serializer->serialize_model_to_string ($base_uri, $model); $serializer = undef; Still not quite happy with having the entire C-based Redland program as a dependency but it is working and it looks quite clean. Cheers, Peter
Received on Sunday, 1 June 2008 02:17:39 UTC