1. Go to this page and download the library: Download sweetrdf/quick-rdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sweetrdf / quick-rdf example snippets
usequickRdf\DataFactoryasDF;
$graph = new quickRdf\Dataset();
$parser = new quickRdfIo\TriGParser();
$stream = fopen('pathToTurtleFile', 'r');
$graph->add($parser->parseStream($stream));
fclose($stream);
// count edges in the graphecho count($graph);
// go trough all edges in the graphforeach ($graph as $i) {
echo"$i\n";
}
// find all graph edges with a given subjectecho $graph->copy(DF::quadTemplate(DF::namedNode('http://mySubject')));
// find all graph edges with a given predicateecho $graph->copy(DF::quadTemplate(null, DF::namedNode('http://myPredicate')));
// find all graph edges with a given objectecho $graph->copy(DF::quadTemplate(null, null, DF::literal('value', 'en')));
// replace an edge in the graph
$edge = DF::quad(DF::namedNode('http://edgeSubject'), DF::namedNode('http://edgePredicate'), DF::namedNode('http://edgeObject'));
$graph[$edge] = $edge->withObject(DF::namedNode('http://anotherObject'));
// find intersection with other graph
$graph->copy($otherGraph); // immutable
$graph->delete($otherGraph); // in-place// compute union with other graph
$graph->union($otherGraph); // immutable
$graph->add($otherGraph); // in-place// compute set difference with other graph
$graph->copyExcept($otherGraph); // immutable
$graph->delete($otherGraph); // in-place
$serializer = new quickRdfIo\TurtleSerializer();
$stream = fopen('pathToOutputTurtleFile', 'w');
$serializer->serializeStream($stream, $graph);
fclose($stream);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.