You are here

protected function EasyRdf_Serialiser_Turtle::serialiseSubjects in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php \EasyRdf_Serialiser_Turtle::serialiseSubjects()

@ignore

1 call to EasyRdf_Serialiser_Turtle::serialiseSubjects()
EasyRdf_Serialiser_Turtle::serialise in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php
Serialise an EasyRdf_Graph to Turtle.

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php, line 288

Class

EasyRdf_Serialiser_Turtle
Class to serialise an EasyRdf_Graph to Turtle with no external dependancies.

Code

protected function serialiseSubjects(EasyRdf_Graph $graph, $filterType) {
  $turtle = '';
  foreach ($graph
    ->resources() as $resource) {

    /** @var $resource EasyRdf_Resource */

    // If the resource has no properties - don't serialise it
    $properties = $resource
      ->propertyUris();
    if (count($properties) == 0) {
      continue;
    }

    // Is this node of the right type?
    $thisType = $resource
      ->isBNode() ? 'bnode' : 'uri';
    if ($thisType != $filterType) {
      continue;
    }
    if ($thisType == 'bnode') {
      $id = $resource
        ->getBNodeId();
      if (isset($this->outputtedBnodes[$id])) {

        // Already been serialised
        continue;
      }
      $this->outputtedBnodes[$id] = true;
      $rpcount = $this
        ->reversePropertyCount($resource);
      if ($rpcount == 0) {
        $turtle .= '[]';
      }
      else {
        $turtle .= $this
          ->serialiseResource($resource);
      }
    }
    else {
      $turtle .= $this
        ->serialiseResource($resource);
    }
    $turtle .= $this
      ->serialiseProperties($resource);
    $turtle .= "\n";
  }
  return $turtle;
}