/** * Parses a given stream and returns an iterator containing Statement instances representing the * previously read data. The stream parses the data not as a whole but in chunks. * * @param string $inputStream Filename of the stream to parse which contains RDF * serialized data. * @param string $baseUri The base URI of the parsed content. If this URI is null * the inputStreams URL is taken as base URI. * @param string $serialization The serialization of the inputStream. If null is given * the parser will either apply some standard serialization, * or the only one it is supporting, or will try to guess * the correct serialization, or will throw an Exception. * Supported formats are a subset of the following: * json, rdfxml, sparql-xml, rdfa, turtle, ntriples, n3 * @return StatementIterator A StatementIterator containing all the Statements parsed by the parser to * far. * @throws \Exception If the base URI $baseUri is no valid URI. */ public function parseStreamToIterator($inputStream, $baseUri = null, $serialization = null) { $graph = new Graph(); // let EasyRdf guess the format if ($serialization === null) { // use PHP's file:// stream, if its a local file if (false === strpos($inputStream, '://')) { $inputStream = 'file://' . $inputStream; } $serialization = Format::guessFormat(file_get_contents($inputStream)); } else { $serialization = Format::getFormat($serialization); } // if format is still null, throw exception, because we dont know what format the given stream is if (null === $serialization) { throw new \Exception('Either given $format is unknown or i could not guess format.'); } $graph->parseFile($inputStream, $serialization->getName()); // transform parsed data to PHP array return $this->rdfPhpToStatementIterator($graph->toRdfPhp()); }
<?php use EasyRdf\Graph; use EasyRdf\Format; use EasyRdf\Serialiser\GraphViz; $app->get('/image', function () { $graph = Graph::newAndLoad(site_base_uri() . '/asset/dataset/countries.rdf'); $format = Format::getFormat('png'); $viz = new GraphViz(); header("Content-Type: " . $format->getDefaultMimeType()); echo $viz->renderImage($graph, $format); die; })->name('home');