static function deleteTriples($iri, $graph, $endpoint) { /* Serializer instantiation */ $ser = new FourStore_NTriplesSerializer(); $sp_readonly = @new FourStore_StorePlus($endpoint); //DELETE OLD TRIPLES WITH THE SUBJECT $uri $q = "select * where {GRAPH <" . $graph . "> {<" . $iri . "> ?p ?o.}} "; $oldTriples = @$sp_readonly->query($q, 'rows'); $err = $sp_readonly->getErrors(); if ($err) { throw new Exception(self::buildMessage($err)); } if (count($oldTriples) > 0) { for ($i = 0, $i_max = count($oldTriples); $i < $i_max; $i++) { $t =& $oldTriples[$i]; $t['s'] = $iri; $t['s type'] = "uri"; } /* Serialize a triples array */ $docd = $ser->getSerializedTriples($oldTriples, 1); $sp = new FourStore_StorePlus($endpoint, false); $q = "DELETE DATA { \n\t\t\t\t\t\t\tGRAPH <" . $graph . "> { \n\t\t\t\t\t\t\t{$docd} \n\t\t\t \t\t}}"; $res = @$sp->query($q, 'raw'); $err = $sp->getErrors(); if ($err) { throw new Exception(self::buildMessage($err)); } if (!$res) { $msg = "Query delete old triples return: False without errors"; throw new Exception($msg); } } }
static function insertRDF($uri, $graph, $endpoint) { self::deleteTriples($uri, $graph, $endpoint); //READ NEW TRIPLES WITH THE SUBJECT $uri $parser = ARC2::getRDFXMLParser(); @$parser->parse($uri); $err = $parser->getErrors(); if ($err) { throw new Exception(self::buildMessage($err)); } $newTriples = $parser->getTriples(); for ($i = 0, $i_max = count($newTriples); $i < $i_max; $i++) { if ($uri != $newTriples[$i]['s']) { unset($newTriples[$i]); } } /* Serializer instantiation */ $ser = new FourStore_NTriplesSerializer(); /* Serialize a triples array */ $doc = $ser->getSerializedTriples($newTriples, 1); self::insert($doc, $graph, $endpoint); }