sweetrdf/quick-rdf-io

Collection of parser and serializers compatible with sweetrdf/rdfInterface

0.7.0 2021-03-29 17:07 UTC

README

Latest Stable Version Build status Coverage Status License

Collection of parsers and serializers implementing the https://github.com/sweetrdf/rdfInterface interface.

Originally developed for the quickRdf library.

Quite quick and dirty at the moment.

Installation

  • Obtain the Composer
  • Run composer require sweetrdf/quick-rdf-io

Automatically generated documentation

https://sweetrdf.github.io/quickRdfIo/namespaces/quickrdfio.html

It's very incomplete but better than nothing.
RdfInterface documentation is included.

Usage

include 'vendor/autoload.php';

// parse turle/ntriples/nquad/ntriples* file
$dataFactory = new DataFactory();
$parser = new quickRdfIo\TriGParser($dataFactory);
$stream = fopen('pathToTurtleFile', 'r');
foreach($parser->parseStream($stream) as $quad) {
   echo "$quad\n";
}
fclose($stream);

// convert to nquads/ntriples/ntriples*
$instream = fopen('pathToTurtleFile', 'r');
$iterator = $parser->parseStream($instream);
$serializer = new quickRdfIo\NQuadsSerializer();
$outstream = fopen('pathToOutputTurtleFile', 'w');
$serializer->serializeStream($stream, $iterator);
fclose($outstream);
fclose($instream);