Improve this doc View source

QueryBuilderService
service in module sparql

Description

Service for building pageable SPARQL queries.

Usage

new QueryBuilderService(Prefixes);

Parameters

ParamTypeDetails
Prefixesstring

prefixes used in the SPARQL query.

Methods

Example

var prefixes =
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ' +
'PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> ';

var queryBuilder = new QueryBuilderService(prefixes);

var resultSet = '?id a <http://dbpedia.org/ontology/Writer> .';

var queryTemplate =
'SELECT * WHERE { ' +
' <RESULT_SET ' +
' OPTIONAL { ?id rdfs:label ?label . } ' +
'}';

var qryObj = queryBuilder.buildQuery(qry, resultSet, '?id');

// qryObj.query returns (without line breaks):
// PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
// PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
// SELECT * WHERE {
//   {
//     SELECT DISTINCT ?id {
//       ?id a <http://dbpedia.org/ontology/Writer>.
//     } ORDER BY ?id <PAGE>
//   }
//   OPTIONAL { ?id rdfs:label ?label . }
// }

// qryObj.resultSetQry returns (without line breaks):
// PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
// PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
// SELECT DISTINCT ?id {
//   ?id a <http://dbpedia.org/ontology/Writer>.
// } ORDER BY ?id <PAGE>