You are here

public function EasyRdf_Serialiser_Ntriples::serialise in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php \EasyRdf_Serialiser_Ntriples::serialise()

Serialise an EasyRdf_Graph into N-Triples

Parameters

EasyRdf_Graph $graph An EasyRdf_Graph object.:

string $format The name of the format to convert to.:

array $options:

Return value

string The RDF in the new desired format.

Throws

EasyRdf_Exception

Overrides EasyRdf_Serialiser::serialise

1 call to EasyRdf_Serialiser_Ntriples::serialise()
EasyRdf_Serialiser_Rapper::serialise in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php
Serialise an EasyRdf_Graph to the RDF format of choice.
1 method overrides EasyRdf_Serialiser_Ntriples::serialise()
EasyRdf_Serialiser_Rapper::serialise in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php
Serialise an EasyRdf_Graph to the RDF format of choice.

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php, line 199

Class

EasyRdf_Serialiser_Ntriples
Class to serialise an EasyRdf_Graph to N-Triples with no external dependancies.

Code

public function serialise($graph, $format, array $options = array()) {
  parent::checkSerialiseParams($graph, $format);
  if ($format == 'ntriples') {
    $nt = '';
    foreach ($graph
      ->toRdfPhp() as $resource => $properties) {
      foreach ($properties as $property => $values) {
        foreach ($values as $value) {
          $nt .= $this
            ->serialiseResource($resource) . " ";
          $nt .= "<" . $this
            ->escapeString($property) . "> ";
          $nt .= $this
            ->serialiseValue($value) . " .\n";
        }
      }
    }
    return $nt;
  }
  else {
    throw new EasyRdf_Exception("EasyRdf_Serialiser_Ntriples does not support: {$format}");
  }
}