/** * Parse an RDF document into an EasyRdf\Graph * * @param Graph $graph the graph to load the data into * @param string $data the RDF document data * @param string $format the format of the input data * @param string $baseUri the base URI of the data being parsed * * @return integer The number of triples added to the graph */ public function parse($graph, $data, $format, $baseUri) { parent::checkParseParams($graph, $data, $format, $baseUri); $json = Utils::execCommandPipe($this->rapperCmd, array('--quiet', '--input', $format, '--output', 'json', '--ignore-errors', '--input-uri', $baseUri, '--output-uri', '-', '-'), $data); // Parse in the JSON return parent::parse($graph, $json, 'json', $baseUri); }
/** * Serialise an EasyRdf\Graph to the RDF format of choice. * * @param \EasyRdf\Graph $graph An EasyRdf\Graph object. * @param string $format The name of the format to convert to. * @param array $options * * @return string The RDF in the new desired format. * @throws Exception */ public function serialise(Graph $graph, $format, array $options = array()) { parent::checkSerialiseParams($format); $ntriples = parent::serialise($graph, 'ntriples'); // Hack to produce more concise RDF/XML if ($format == 'rdfxml') { $format = 'rdfxml-abbrev'; } return Utils::execCommandPipe($this->rapperCmd, array('--quiet', '--input', 'ntriples', '--output', $format, '-', 'unknown://'), $ntriples); }
/** * Parse HTTP-response object into a meaningful result-object. * * Can be overridden to do custom processing * * @param Http\Response|\Zend\Http\Response $response * @return Graph|Result */ protected function parseResponseToQuery($response) { list($content_type, ) = Utils::parseMimeType($response->getHeader('Content-Type')); if (strpos($content_type, 'application/sparql-results') === 0) { $result = new Result($response->getBody(), $content_type); return $result; } else { $result = new Graph($this->queryUri, $response->getBody(), $content_type); return $result; } }
/** * Internal function to render a graph into an image * * @ignore */ public function renderImage(Graph $graph, $format = 'png') { $dot = $this->serialiseDot($graph); return Utils::execCommandPipe($this->dotCommand, array("-T{$format}"), $dot); }