Example #1
0
 /**
  * Parse Turtle 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);
     if ($format != 'turtle') {
         throw new EasyRdf_Exception("EasyRdf_Parser_Turtle does not support: {$format}");
     }
     $this->data = $data;
     $this->namespaces = array();
     $this->subject = null;
     $this->predicate = null;
     $this->object = null;
     $this->line = 1;
     $this->column = 1;
     $this->resetBnodeMap();
     $c = $this->skipWSC();
     while ($c != -1) {
         $this->parseStatement();
         $c = $this->skipWSC();
     }
     return $this->tripleCount;
 }
Example #2
0
 /**
  * Parse Turtle 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);
     if ($format != 'turtle') {
         throw new EasyRdf_Exception("EasyRdf_Parser_Turtle does not support: {$format}");
     }
     $this->_data = $data;
     $this->_len = strlen($data);
     $this->_pos = 0;
     $this->_namespaces = array();
     $this->_subject = NULL;
     $this->_predicate = NULL;
     $this->_object = NULL;
     $this->resetBnodeMap();
     $c = $this->skipWSC();
     while ($c != -1) {
         $this->parseStatement();
         $c = $this->skipWSC();
     }
     return $this->_tripleCount;
 }
 protected function parseNtriples($filename)
 {
     $graph = new EasyRdf_Graph();
     $this->ntriplesParser->parse($graph, readFixture($filename), 'ntriples', $this->baseUri . basename($filename));
     return $graph->serialise('ntriples-array');
 }