Improve this doc View source

AdvancedSparqlService
service in module sparql

Description

Service for querying a SPARQL endpoint, with paging support.

Usage

new AdvancedSparqlService(configuration, mapper);

Parameters

ParamTypeDetails
configurationObjectstring

Configuration object or the SPARQL endpoit URL as a string. The object has the following properties:

  • endpointUrl - {string} - The SPARQL endpoint URL.
  • usePost - {boolean} - If truthy, use POST instead of GET. Default is false.
mapperObject

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)

Methods

Example

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);