Example #1
0
 /**
  * Parse an RDF document into an EasyRdf_Graph
  *
  * @param object EasyRdf_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 = EasyRdf_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);
 }
Example #2
0
 /**
  * Parse an RDF document into an EasyRdf_Graph
  *
  * @param string $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 boolean         true if parsing was successful
  */
 public function parse($graph, $data, $format, $baseUri)
 {
     parent::checkParseParams($graph, $data, $format, $baseUri);
     // Open a pipe to the rapper command
     $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
     $process = proc_open(escapeshellcmd($this->_rapperCmd) . " --quiet " . " --input " . escapeshellarg($format) . " --output json " . " --ignore-errors " . " --input-uri " . escapeshellarg($baseUri) . " --output-uri -" . " - ", $descriptorspec, $pipes, '/tmp', null);
     if (is_resource($process)) {
         // $pipes now looks like this:
         // 0 => writeable handle connected to child stdin
         // 1 => readable handle connected to child stdout
         // 2 => readable handle connected to child stderr
         fwrite($pipes[0], $data);
         fclose($pipes[0]);
         $data = stream_get_contents($pipes[1]);
         fclose($pipes[1]);
         $error = stream_get_contents($pipes[2]);
         fclose($pipes[2]);
         // It is important that you close any pipes before calling
         // proc_close in order to avoid a deadlock
         $returnValue = proc_close($process);
         if ($returnValue) {
             throw new EasyRdf_Exception("Failed to parse RDF ({$returnValue}): " . $error);
         }
     } else {
         throw new EasyRdf_Exception("Failed to execute rapper command.");
     }
     // Parse in the JSON
     return parent::parse($graph, $data, 'json', $baseUri);
 }