Serializing ARC Structures

semsol edited this page Mar 11, 2011 · 2 revisions

ARC supports 4 serialization formats:

The serializers can process both index and triple structures. Some examples:

/* ARC2 static class inclusion */ 
include_once('path/to/arc/ARC2.php');

/* Serializer instantiation */
$ser = ARC2::getTurtleSerializer();

/* Serialize a triples array */
$doc = $ser->getSerializedTriples($triples);

/* Serialize a resource index */
$doc = $ser->getSerializedIndex($index);

/* Serialize a resource index without 
   document head or footer (just the triples)  */
$doc = $ser->getSerializedIndex($index, 1);
/* custom namespace prefixes */
$ns = array(
  'foaf' => 'http://xmlns.com/foaf/0.1/',
  'dc' => 'http://purl.org/dc/elements/1.1/'
);
$conf = array('ns' => $ns);
$ser = ARC2::getRDFXMLSerializer($conf);

$doc = $ser->getSerializedIndex($index);

Each ARC component provides shortcuts to the serializers. These convenience methods auto-detect the passed structure (resource index or triple set):

$doc = $parser->toRDFJSON($index);
$doc = $store->toNTriples($triples);

Configuration Options

  • The RDF/XML Serializer accepts a "serializer_prettyprint_containers" config option which will lead to pretty-printed RDF Containers (rdf:Seq/Alt/Bag) if set to true.
  • The RDF/XML Serializer accepts a "serializer_default_ns" config option to set a default xmlns value
  • The RDF/XML Serializer accepts a "serializer_type_nodes" config option which will replace the generic rdf:Description with the node's first resource type (if available)