SPARQLer 🥂

Terms

All of the tokens into each Triple must be enclosed within a wrapper Term class (eventually determined automatically based on his position on the Triple itself, see below). Here a summary of each Term type, with some example.


Variable Any SPARQL variable (the tokens having a ? before the name). If no parameters are passed, the name is randomly generated.
This is usually used if you explicitely want a given value to be used in different parts of the query: init one or more Variable PHP variables and pass it as parameter to the different functions.
use MadBob\Sparqler\Terms\Variable;

$variable = new Variable('foobar');

$client->doSelect()
    ->where('rdf:predicate1', $variable)
    ->where('rdf:predicate2', $variable)->get();
Show generated query

Literal A typed value. May be a string, a number, a date...
This wraps the Literal class from EasyRDF.
use MadBob\Sparqler\Terms\Literal;
use Carbon\Carbon;

$client->doSelect()
    ->where('rdf:date', new Literal(Carbon::now()))
    ->where('rdf:number', new Literal(42))
    ->get();
Show generated query

OwnSubject The subject of the query. Can be used as a Variable (actually: it is a Variable) and placed in different parts of the query.
Multiple OwnSubject distributed within the same query will have the same value (note: subqueries are not part of the parent queries, so a different OwnSubject will be assigned).
use MadBob\Sparqler\Terms\OwnSubject;

$client->doSelect()
    ->where('rdf:predicate', new OwnSubject())->get();
Show generated query

Iri Wraps all predicate names and entity subjects.
The parameters passed to doSelect(), and the first parameter of where() functions (if only two are passed), are automatically wrapped within a Iri.
use MadBob\Sparqler\Terms\Iri;

$client->doSelect()
    ->where('rdf:predicate1', 'no:iri')
    ->where('rdf:predicate2', new Iri('as:iri'))
    ->where('rdf:predicate3', new Iri('http://example.org/my/resource'))->get();
Show generated query

Plain Includes a generic string that will be enclosed between quotes in the final query.
Useful to explicitely enforce a string where another type of Term is expected.
use MadBob\Sparqler\Terms\Plain;

$client->doSelect()
    ->where('rdf:predicate1', new Plain('value'))->get();
Show generated query

Raw Includes a generic string that will be appended as-is (with no quotes or escapes) in the final query.
Useful to enforce specific parts of the query and special syntax non handled by SPARQLer.
Optional Used to wrap a Iri (default, if a plain string is passed) or a Variable to be optionally added into the result set.
Mostly used in the parameters list of doSelect() and doConstruct().
use MadBob\Sparqler\Terms\Optional;

$client->doSelect(['rdf:required', new Optional('rdf:optpredicate')])
    ->where('rdf:predicate', 'foobar')->get();
Show generated query

Aggregate A SPARQL function applied to some value. Parameters are: the name of the function, the parameter(s) to that function (note: plain strings will be handled as Iri), and optionally an alternative name to hold the final result of the function.
use MadBob\Sparqler\Terms\Aggregate;

$client->doSelect([new Aggregate('COUNT', 'rdf:tocount', 'counter')])
    ->where('rdf:predicate', 'foobar')->get();
Show generated query

SPARQLer 🥂