Parse an N-Triples document into an EasyRdf_Graph
object EasyRdf_Graph $graph the graph to load the data into:
string $data the RDF document data:
string $format the format of the input data:
string $baseUri the base URI of the data being parsed:
integer The number of triples added to the graph
Overrides EasyRdf_Parser::parse
public function parse($graph, $data, $format, $baseUri) {
parent::checkParseParams($graph, $data, $format, $baseUri);
if ($format != 'ntriples') {
throw new EasyRdf_Exception("EasyRdf_Parser_Ntriples does not support: {$format}");
}
$lines = preg_split("/[\r\n]+/", strval($data));
foreach ($lines as $line) {
if (preg_match("/^\\s*#/", $line)) {
continue;
}
elseif (preg_match("/(.+)\\s+<([^<>]+)>\\s+(.+)\\s*\\./", $line, $matches)) {
$this
->addTriple($this
->parseNtriplesSubject($matches[1]), $this
->unescapeString($matches[2]), $this
->parseNtriplesObject($matches[3]));
}
}
return $this->tripleCount;
}