legrand / sparql
Library that generate SPARQL queries and request a endpoints
Installs: 101
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 2
pkg:composer/legrand/sparql
Requires
- php: >=5.3.0
- phpunit/phpunit: 3.7.*@dev
This package is not auto-updated.
Last update: 2025-11-08 19:36:22 UTC
README
A library that generate SPARQL queries and request a endpoints
Exemple
A quick and easy sparql request to understand how it works. You can find more exemples in the SparqlTest.php file.
$sparql = new Legrand\SPARQL;
$sparql->variable('?z')
->where('<http://dbpedia.org/resource/Nine_Inch_Nails>', '?y', '?z')
->limit(20);
$response = $sparql->launch();
Methods
prefixe($namespace, $url)You can add several prefixes with this methoddistinct($boolean)Set a request with a distinct selectvariable($var)Add a variable to select i.e.?zfrom($graph)Add a from graph i.e.http://graphwhere($subject, $predicate, $object)add a where conditionoptionalWhere($subject, $predicate, $object)add a conditional where conditionoptionalWhereComplexe($sparql)add a more complex conditional where in the queryunion($sparql)define where condition on a SPARQL object and give it to this methodfilter($filter)add a filter inside the where bracketsorderBy($order)define the order i.e.?z DESClimit($nb)define the limitoffset($nb)define the offsetinsert($graph)create an insert sparql query by giving the graph uridelete($graph)create a delete sparql query by giving the graph urigetSPARQL()get the SPARQL query without calling the endpoint
Defaults
Some attributes are set with defaults value. You can of course change these values :
$sparql->baseUrl = 'http://dbpedia.org/sparql';$sparql->format = 'json';$sparql->method = 'GET';$sparql->queryParam = 'query';$sparql->formatParam = 'format';