QueryBuilderService
sparql
Service for building pageable SPARQL queries.
new QueryBuilderService(Prefixes);
| Param | Type | Details |
|---|---|---|
| Prefixes | string | prefixes used in the SPARQL query. |
Build a pageable SPARQL query.
| Param | Type | Details |
|---|---|---|
| queryTemplate | string | The SPARQL query with |
| resultSet | string | Constraints that result in the URIs of
the resources to page. The URIs should be bound as |
| [orderBy] | string | A SPARQL expression that can be used to order the results. Default is '?id'. |
| Object | a query object with the following properties:
|
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>
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>