You are here

protected function EasyRdf_Serialiser_Turtle::serialiseProperties in Zircon Profile 8.0

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

Protected method to serialise the properties of a resource @ignore

1 call to EasyRdf_Serialiser_Turtle::serialiseProperties()
EasyRdf_Serialiser_Turtle::serialiseSubjects in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php
@ignore

File

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

Class

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

Code

protected function serialiseProperties($res, $depth = 1) {
  $properties = $res
    ->propertyUris();
  $indent = str_repeat(' ', $depth * 2 - 1);
  $turtle = '';
  if (count($properties) > 1) {
    $turtle .= "\n{$indent}";
  }
  $pCount = 0;
  foreach ($properties as $property) {
    if ($property === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') {
      $pStr = 'a';
    }
    else {
      $pStr = $this
        ->serialiseResource($property, true);
    }
    if ($pCount) {
      $turtle .= " ;\n{$indent}";
    }
    $turtle .= ' ' . $pStr;
    $oCount = 0;
    foreach ($res
      ->all("<{$property}>") as $object) {
      if ($oCount) {
        $turtle .= ',';
      }
      if ($object instanceof EasyRdf_Collection) {
        $turtle .= ' ' . $this
          ->serialiseCollection($object, $indent);
      }
      elseif ($object instanceof EasyRdf_Resource and $object
        ->isBNode()) {
        $id = $object
          ->getBNodeId();
        $rpcount = $this
          ->reversePropertyCount($object);
        if ($rpcount <= 1 and !isset($this->outputtedBnodes[$id])) {

          // Nested unlabelled Blank Node
          $this->outputtedBnodes[$id] = true;
          $turtle .= ' [';
          $turtle .= $this
            ->serialiseProperties($object, $depth + 1);
          $turtle .= ' ]';
        }
        else {

          // Multiple properties pointing to this blank node
          $turtle .= ' ' . $this
            ->serialiseObject($object);
        }
      }
      else {
        $turtle .= ' ' . $this
          ->serialiseObject($object);
      }
      $oCount++;
    }
    $pCount++;
  }
  if ($depth == 1) {
    $turtle .= " .";
    if ($pCount > 1) {
      $turtle .= "\n";
    }
  }
  elseif ($pCount > 1) {
    $turtle .= "\n" . str_repeat(' ', ($depth - 1) * 2 - 1);
  }
  return $turtle;
}