NAME

RDF::Simple::Serialiser

DESCRIPTION

a simple RDF serialiser. accepts an array of triples, returns a serialised RDF document.

SYNOPSIS

my $ser = RDF::Simple::Serialiser->new;

my @triples = (
               ['http://example.com/url#', 'dc:creator', 'zool@example.com'],
               ['http://example.com/url#', 'foaf:Topic', '_id:1234'],
               ['_id:1234','http://www.w3.org/2003/01/geo/wgs84_pos#lat','51.334422']
               );

my $rdf = $ser->serialise(@triples);

##
## supply own bNode id prefix, add namespaces

my $ser = RDF::Simple::Serialiser->new( nodeid_prefix => 'a:' );

$ser->addns( foaf => 'http://xmlns.com/foaf/0.1/' );

my $node1 = $ser->genid;
my $node2 = $ser->genid;

my @triples = (
               [$node1, 'foaf:name', 'Jo Walsh'],
               [$node1, 'foaf:knows', $node2],
               [$node2, 'foaf:name', 'Robin Berjon'],
               [$node1, 'rdf:type', 'foaf:Person'],
               [$node2, 'rdf:type','http://xmlns.com/foaf/0.1/Person']
               );

my $rdf = $ser->serialise(@triples);

##
## round-trip

my $parser = RDF::Simple::Parser->new();
my $rdf = LWP::Simple->get('http://www.zooleika.org.uk/foaf.rdf');

my @triples = $parser->parse_rdf($rdf);
my $new_rdf = $serialiser->serialise(@triples);

METHODS

new( [ nodeid_prefix => 'prefix' ])

serialise( @triples )

accepts a 'bucket of triples'
(an array of array references which are
'subject, predicate, object' statements)
and returns a serialised RDF document.

if 'rdf:type' is not provided for a subject,
the generic node type 'rdf:Description' is used.

genid( )

generates a random identifier for use as a bNode
(anonymous node) nodeID.
if nodeid_prefix is set, the generated id uses the prefix,
followed by 8 random numbers.

addns( qname => 'http://example.com/rdf/vocabulary#', qname2 => 'http://yetanother.org/vocabulary/' )

add new namespaces to the RDF document.
a namespace must exist for each predicate used in a triple.
the RDF::Simple::NS module which supports this one
provides the following vocabularies by default
(you can override them if wished)

    foaf => 'http://xmlns.com/foaf/0.1/',
    dc => 'http://purl.org/dc/elements/1.1/',
    rdfs => "http://www.w3.org/2000/01/rdf-schema#",
    daml => 'http://www.w3.org/2001/10/daml+oil#',
    space => 'http://frot.org/space/0.1/',
    geo => 'http://www.w3.org/2003/01/geo/wgs84_pos#',
    rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    owl => 'http://www.w3.org/2002/07/owl#',
    ical => 'http://www.w3.org/2002/12/cal/ical#',
    dcterms=>"http://purl.org/dc/terms/",
    wiki=>"http://purl.org/rss/1.0/modules/wiki/",
    chefmoz=>"http://chefmoz.org/rdf/elements/1.0/",

BUGS

probably loads, this is a very alpha release. feedback very welcome.

NOTES

i am english, so this is a Serialiser. for our divided friends across the water, RDF::Simple::Serializer will work as an alias to the module, and serialize() does the same as serialise().

THANKS

AUTHOR

jo walsh <jo@london.pm.org>

LICENSE

this module is available under the same terms as perl itself.