Actions
Select
doSelect()
inits a SELECT query: the function accepts an array of items (by default plain strings are converted to Prefixed terms) that will be retrieved for each entity matching the conditions appended to the Builder. The query returns an instance of EasyRdf\Sparql\Result
.
use MadBob\Sparqler\Terms\OwnSubject;
$client->doSelect([new OwnSubject(), 'rdf:predicate'])
->where('rdf:filter', 'foobar')->get();
Show generated query
doSelectDistinct()
acts in the same way, but inits a SELECT DISTINCT query.
$client->doSelectDistinct(['rdf:predicate'])
->where('rdf:search', 'foobar')->get();
Show generated query
Insert and Delete
doInsert()
and doDelete()
are used to insert and delete data into the graph. Both accept an array of Triples to specify what to insert or remove, while the conditions appended to the Builder define which entities are the target of insert or remove operation.
use MadBob\Sparqler\Terms\Iri;
$client->doInsert([
['foaf:knows', new Iri('http://mydomain/Person/Foo')],
])->where('foaf:currentProject', new Iri('http://mydomain/Project/Bar'))->run();
Show generated query
use MadBob\Sparqler\Terms\Iri;
$client->doDelete([
['foaf:knows', new Iri('http://mydomain/Person/Foo')],
])->where('foaf:currentProject', new Iri('http://mydomain/Project/Bar'))->run();
Show generated query
If you want to perform multiple insert/delete operations (for example, to update some value or relation) you can use the queue()
function instead of run()
, and execute all queries at once with runQueue()
use MadBob\Sparqler\Terms\Iri;
use MadBob\Sparqler\Terms\Variable;
$client->doDelete([
['foaf:knows', new Variable()],
])->where('foaf:currentProject', new Iri('http://mydomain/Project/Bar'))->queue();
$client->doInsert([
['foaf:knows', new Iri('http://mydomain/Person/Foo')],
])->where('foaf:currentProject', new Iri('http://mydomain/Project/Bar'))->queue();
$client->runQueue();
Show generated query
Construct
doConstruct()
returns a Graph, including multiple Resource, and permits an accurate selection of predicates to be fetched and added to the Graph itself.
$client->doConstruct([['rdf:predicate1'], ['rdf:predicate2']])
->where('rdf:search', 'foobar')->get();
Show generated query
doConstruct()
gets an optional array of Triple as parameters, describing the properties you want to fetch for each entity matching the conditions, but usually you may want to omit the subject (implicit, due the conditions appended to the Builder) and the object (which is automatically mapped into the query for each required predicate). If no parameters are passed, all the predicates of matching entities are fetched from the endpoint.
The returned value is an iterable data structure which also tracks all modifications operated on the child resources and exposes a commit()
method to save them all back to the triplestore.
$graph = $client->doConstruct()->where('rdf:predicate', 'foobar')->get();
foreach($graph as $resource) {
$resource->set('new:predicate', 'new value');
}
$graph->commit();
Show generated query
For convenience, Client has a short hand find()
function which CONSTRUCTs a given subject.
$client->find('https://example.com/resource/sample');
Show generated query