Download the PHP package sweetrdf/rdfinterface2easyrdf without Composer
On this page you can find all versions of the php package sweetrdf/rdfinterface2easyrdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sweetrdf/rdfinterface2easyrdf
More information about sweetrdf/rdfinterface2easyrdf
Files in sweetrdf/rdfinterface2easyrdf
Package rdfinterface2easyrdf
Short Description Provides methods to convert between EasyRdf and rdfInterface objects.
License MIT
Homepage https://github.com/sweetrdf/rdfInterface2easyRdf
Informations about the package rdfinterface2easyrdf
rdfInterface2easyRdf
A library providing methods for converting between EasyRdf (original library, still maintained fork) and rdfInterface objects (in both directions).
Helpful especially when you have too much EasyRdf code to port it but you would like to develop new code using the rdfInterface ecosystem.
Installation
- Obtain the Composer
- Run
composer require sweetrdf/rdfInterface2easyRdf
- Install EasyRdf implementation of your choice, e.g.
composer require sweetrdf/easyrdf
. - Install rdfInterface implementation of your choice, e.g.
composer require sweetrdf/quick-rdf
.
Usage
rdfInterface to EasyRdf
Conversion in this direction is straightforward:
-
If you don't care about strong result type checks, just use the
rdfInterface2easyRdf\AsEasyRdf::asEasyRdf()
method, e.g.:- If you want converted data to be appended to an already existing graph, pass it as a second parameter, e.g. (continuing the code from the previous example):
- If you care about stictly defined return data types, use
rdfInterface2easyRdf\AsEasyRdf::asLiteral()
,rdfInterface2easyRdf\AsEasyRdf::asResource()
andrdfInterface2easyRdf\AsEasyRdf::asGraph()
.- Each of them accepts only compatible input types, e.g.
rdfInterface2easyRdf\AsEasyRdf::asLiteral()
accepts onlyrdfInterface\LiteralInterface
rdfInterface\NodeInterface
is accepted both byrdfInterface2easyRdf\AsEasyRdf::asResource()
andrdfInterface2easyRdf\AsEasyRdf::asGraph()
- An
EasyRdf\Graph
can be passed as an optional second parameter just as withrdfInterface2easyRdf\AsEasyRdf::AsEasyRdf()
(see the example above)
- Each of them accepts only compatible input types, e.g.
EasyRdf to rdfInterface
Conversion in this direction might get tricky. Important remarks:
- As the rdfInterface defines only an interface but no actual implementation,
you must always pass an RDF terms factory object (the
$dataFactory
parameter). - As the rdfInterface doesn't define a standardized way to create datasets
(
rdfInterface\DatasetInterface
) and dataset nodes (rdfInterface\DatasetNodeInterface
) theasRdfInterface()
method returns anrdfInterface\QuadIteratorInterface
which is a triples iterator. The only way to convert anEasyRdf\Resource
orEasyRdf\Graph
to a dataset or dataset node is to add triples from the EasyRdf object to an existingrdfInterface\DatasetInterface
orrdfInterface\DatasetNodeInterface
. Theadd()
,addDataset()
andaddDatasetNode()
methods can be used for that (see examples below). - There's an ambiguity around the
EasyRdf\Resource
conversion. You may want convert it to an RDF term (rdfInterface\BlankNode
orrdfInterface\NamedNode
) or you may want to convert it to a set of triples (quad iterator, dataset or dataset node).- The
asRdfInterface()
method converts to an RDF term if theEasyRdf\Resource
object has no properties (no triples) and to ardfInterface\QuadIteratorInterface
otherwise. - Use
asTerm()
,asQuadIterator()
,add()
,addDataset()
oraddDatasetNode()
to enforce a more specific behavior.
- The
A sample EasyRdf graph and terms factory used in examples below:
-
Use
asRdfInterface()
to guess the output type based on the input. -
Use
asTerm()
to enforce conversion of anEasyRdf\Resource
to a term: -
There are two ways of converting an
EasyRdf\Graph
andEasyRdf\Resource
to a dataset: -
Conversion of an
EasyRdf\Resource
to a dataset node is relatively most complex: - In case of
add()
,addDataset()
andaddDatasetNode()
the parameter used to pass a dataset/dataset node accepts also a callable, e.g.
All versions of rdfinterface2easyrdf with dependencies
sweetrdf/rdf-interface Version ^2.0.0-RC1
sweetrdf/rdf-helpers Version ^2.0.0