/** * Internal function to serialise an EasyRdf\Graph into a DOT formatted string * * @ignore */ protected function serialiseDot(Graph $graph) { $result = "digraph {\n"; // Write the graph attributes foreach ($this->attributes as $k => $v) { $result .= ' ' . $this->escape($k) . '=' . $this->escape($v) . ";\n"; } // Go through each of the properties and write the edges $nodes = array(); $result .= "\n // Edges\n"; foreach ($graph->resources() as $resource) { $name1 = $this->nodeName($resource); foreach ($resource->propertyUris() as $property) { $label = null; if ($this->useLabels) { $label = $graph->resource($property)->label(); } if ($label === null) { if ($this->onlyLabelled == true) { continue; } else { $label = RdfNamespace::shorten($property); } } foreach ($resource->all("<{$property}>") as $value) { $name2 = $this->nodeName($value); $nodes[$name1] = $resource; $nodes[$name2] = $value; $result .= $this->serialiseRow($name1, $name2, array('label' => $label)); } } } ksort($nodes); $result .= "\n // Nodes\n"; foreach ($nodes as $name => $node) { $type = substr($name, 0, 1); $label = ''; if ($type == 'R') { if ($this->useLabels) { $label = $node->label(); } if (!$label) { $label = $node->shorten(); } if (!$label) { $label = $node->getURI(); } $result .= $this->serialiseRow($name, null, array('URL' => $node->getURI(), 'label' => $label, 'shape' => 'ellipse', 'color' => 'blue')); } elseif ($type == 'B') { if ($this->useLabels) { $label = $node->label(); } $result .= $this->serialiseRow($name, null, array('label' => $label, 'shape' => 'circle', 'color' => 'green')); } else { $result .= $this->serialiseRow($name, null, array('label' => strval($node), 'shape' => 'record')); } } $result .= "}\n"; return $result; }