Parse RDF/PHP 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) {
$this
->checkParseParams($graph, $data, $format, $baseUri);
if ($format != 'php') {
throw new EasyRdf_Exception("EasyRdf_Parser_RdfPhp does not support: {$format}");
}
foreach ($data as $subject => $properties) {
if (substr($subject, 0, 2) === '_:') {
$subject = $this
->remapBnode($subject);
}
elseif (preg_match('/^\\w+$/', $subject)) {
# Cope with invalid RDF/JSON serialisations that
# put the node name in, without the _: prefix
# (such as net.fortytwo.sesametools.rdfjson)
$subject = $this
->remapBnode($subject);
}
foreach ($properties as $property => $objects) {
foreach ($objects as $object) {
if ($object['type'] === 'bnode') {
$object['value'] = $this
->remapBnode($object['value']);
}
$this
->addTriple($subject, $property, $object);
}
}
}
return $this->tripleCount;
}