sparql-optimizer
v0.1.1
Published
Standalone SPARQL query optimizer
Downloads
2
Readme
sparql-optimizer
Standalone SPARQL query optimizer
Installation
npm i --save sparql-optimiser
Getting started
Basic optimization
DefaultOptimizer
let you perform basic query optimizations on any SPARQL query
'use strict';
const DefaultOptimizer = require('sparql-optimizer').DefaultOptimizer;
const optimizer = new DefaultOptimizer();
// this query contains a join with an union clause, which should be rewritten into an union of two joins
const query = `
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
?airport a <http://dbpedia.org/ontology/Airport>; rdfs:label ?name.
{ ?airport <http://dbpedia.org/property/iata> 'EZE'@en. }
UNION
{ ?airport <http://dbpedia.org/ontology/iataLocationIdentifier> 'EZE'@en. }
}
`;
// optimize SPARQL query and then print it
console.log(optimizer.optimize(query));
The previous query will be optimized and rewritten as follow:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
{
?airport <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Airport>.
?airport rdfs:label ?name.
?airport <http://dbpedia.org/property/iata> "EZE"@en.
}
UNION
{
?airport <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Airport>.
?airport rdfs:label ?name.
?airport <http://dbpedia.org/ontology/iataLocationIdentifier> "EZE"@en.
}
}