Serialise an EasyRdf_Graph into N-Triples
object EasyRdf_Graph $graph An EasyRdf_Graph object.:
string $format The name of the format to convert to.:
string The RDF in the new desired format.
Overrides EasyRdf_Serialiser::serialise
public function serialise($graph, $format) {
parent::checkSerialiseParams($graph, $format);
if ($format == 'ntriples') {
$nt = '';
foreach ($graph
->toArray() as $resource => $properties) {
foreach ($properties as $property => $values) {
foreach ($values as $value) {
$nt .= $this
->ntriplesResource($resource) . " ";
$nt .= "<" . $this
->escapeString($property) . "> ";
$nt .= $this
->ntriplesValue($value) . " .\n";
}
}
}
return $nt;
}
else {
throw new EasyRdf_Exception("EasyRdf_Serialiser_Ntriples does not support: {$format}");
}
}