NAME

RDF::Core::Serializer - produce XML code for RDF model

SYNOPSIS

use RDF::Core::Serializer;

my %options = (getSubjects => \&getSubjectsHandler,
               getNamespaces => \&getNamespacesHandler,
               getStatements => \&getStatementsHandler,
               existsStatement => \&existsStatementHandler,
               BaseURI => 'http://www.foo.com/',
              );
my $serializer = new RDF::Core::Serializer(%options);
$serializer->serialize;

DESCRIPTION

Serializer takes RDF data provided by handlers and generates a XML document. Besides the trivial job of generating one description for one statement the serializer attempts to group statements with common subject into one description and makes referenced descriptions nested into referencing ones. Using baseURI and InlineURI options helps to keep relative and anonymous resources instead of making them absolute and persistent.

Interface

  • new(%options)

    Available options are:

    • getSubjects

      A reference to a subroutine that provides all distinct subjects in serialized model.

    • getNamespaces

      A reference to a subroutine that provides all predicates' namespaces.

    • getStatements($subject, $predicate, $object)

      A reference to a subroutine that provides all statements conforming given mask.

    • existsStatement($subject, $predicate, $object)

      A reference to a subroutine that returns true if a statement exists conforming the mask.

    • Output

      Output can be assigned a filehandle reference (a reference to a typeglob or FileHandle object), or a reference to a scalar variable. If a filehendle is set, serializer assumes it's open and valid, just prints there and doesn't close it. If a variable is set, XML is appended to it. Serializer writes to STDOUT with default settings.

    • BaseURI

      A base URI of a document that is created. If a subject of a statement matches the URI, about attribute with relative URI is generated. No ID attributes are produced until corresponding RDF issue is closed. (See rdfms-difference-between-ID-and-about at http://www.w3.org/2000/03/rdf-tracking/)

    • InlineURI

      If a subject matches an InlineURI option, serializer attempts to generate an anonymous description. (The description has not about neither ID attribute.) If it's not possible (imagine an anonymous resource which points to itself, or some circularly dependent anonymous resources etc.), an ID attribute is generated using InlinePrefix and a counter. The default value is '_:'.

    • InlinePrefix

      If an anonymous description is to be generated and need is to give it ID attribute (see InlineURI), the attribute will be InlinePrefix concatenated with unique number. Unique is ment in the scope of the document. Default prefix is '_:a'.

  • serialize

    Does the job.

Handlers

getSubjects should return an array of references, each reference pointing to an array of one item ($subject), where $subject is a reference to RDF::Core::Resource. (I.e. $subject = $returnValue->[$someElementOfArray]->[0])

getNamespaces should return a hash reference where keys are namespaces and values are namespace prefixes. There must be a rdf namespace present with value 'rdf'

getStatements($subject, $predicate, $object) should return all statements that match given mask. That is the statements' subject is equal to $subject or $subject is not defined and the same for predicate and subject. Return value is a reference to RDF::Core::Enumerator object.

existsStatement($subject, $predicate, $object) should return true if exists statement that matches given mask and false otherwise.

LICENSE

This package is subject to the MPL (or the GPL alternatively).

AUTHOR

Ginger Alliance, rdf@gingerall.cz

SEE ALSO

FileHandle, RDF::Core::Model::Serializer, RDF::Core::Enumerator