public function EasyRdf_Serialiser_Ntriples::serialise

Serialise an EasyRdf_Graph into N-Triples

Parameters

object EasyRdf_Graph $graph An EasyRdf_Graph object.:

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

Return value

string The RDF in the new desired format.

Overrides EasyRdf_Serialiser::serialise

1 call to EasyRdf_Serialiser_Ntriples::serialise()
EasyRdf_Serialiser_Rapper::serialise in drupal/core/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 drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php
Serialise an EasyRdf_Graph to the RDF format of choice.

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php, line 187

Class

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

Code

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}");
  }
}