AdvancedSparqlService
sparql
Service for querying a SPARQL endpoint, with paging support.
new AdvancedSparqlService(configuration, mapper);
| Param | Type | Details |
|---|---|---|
| configuration | Objectstring | Configuration object or the SPARQL endpoit URL as a string. The object has the following properties:
|
| mapper | Object | Object that maps the SPARQL results as objects. The mapper should provide 'makeObjectList' and 'makeObjectListNoGrouping' functions that take the SPARQL results as parameter and return the mapped objects. (default: objectMapperService) |
Get the SPARQL query results as a list of objects as mapped by the mapper
given at init. Results are paged using PagerService if pageSize is given.
This uses the makeObjectList method of the mapper.
| Param | Type | Details |
|---|---|---|
| sparqlQry | string | The SPARQL query. |
| [pageSize] | number | The page size. |
| [resultSetQry] | string | The query that defines the result set
of the query ( |
| [pagesPerQuery] | number | The number of pages to get per query. |
| promise | A promise of the list of the query results as objects,
or if pageSize was gicen, a promise of a |
var prefixes =
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ' +
'PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> ';
// Note the `<PAGE>` placeholder
var resultSet =
' { ' +
' SELECT DISTINCT ?id { ' +
' ?id a <http://dbpedia.org/ontology/Writer> . ' +
' } ORDER BY ?id <PAGE> ' +
' } ';
var qry = prefixes +
'SELECT * WHERE { ' +
resultSet +
' OPTIONAL { ?id rdfs:label ?label . } ' +
'}';
var resultSetQry = prefixes + resultSet;
var resultPromise = endpoint.getObjects(qry, 10, resultSetQry, 1);
// Or you can use the `QueryBuilderService` for convenience:
var resultSet = '?id a <http://dbpedia.org/ontology/Writer> .';
var queryTemplate =
'SELECT * WHERE { ' +
' <RESULT_SET ' +
' OPTIONAL { ?id rdfs:label ?label . } ' +
'}';
var queryBuilder = new QueryBuilderService(prefixes);
var qryObj = queryBuilder.buildQuery(qry, resultSet, '?id');
var resultPromise = endpoint.getObjects(qryObj.query, 10, qryObj.resultSetQry, 1);
Get the SPARQL query results as a list of objects. Results are paged
if pageSize is given. This uses the makeObjectListNoGrouping method
of the mapper.
| Param | Type | Details |
|---|---|---|
| sparqlQry | string | The SPARQL query. |
| [pageSize] | number | The page size. |
| [pagesPerQuery] | number | The number of pages to get per query. |
| promise | A promise of the list of the query results as objects,
or if pageSize was given, a promise of a |
var qry =
'PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> ';
'SELECT * WHERE { ' +
' ?id a <http://dbpedia.org/ontology/Writer> . ' +
' OPTIONAL { ?id rdfs:label ?label . } ' +
'}';
var resultPromise = endpoint.getObjects(qry, 10, 1);
// Without paging:
var resultPromise = endpoint.getObjects(qry);
var config = { endpointUrl: 'http://dbpedia.org/sparql', usePost: false };
var endpoint = new AdvancedSparqlServiceSparqlService(config, objectMapperService);
// Or using just a string parameter:
endpoint = new AdvancedSparqlService('http://dbpedia.org/sparql');
var resultSet = '?id a <http://dbpedia.org/ontology/Writer> .';
var queryTemplate =
'SELECT * WHERE { ' +
' <RESULT_SET ' +
' OPTIONAL { ?id rdfs:label ?label . } ' +
'}';
var queryBuilder = new QueryBuilderService(prefixes);
var qryObj = queryBuilder.buildQuery(qry, resultSet, '?id');
var resultPromise = endpoint.getObjects(qryObj.query, 10, qryObj.resultSetQry, 1);