Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor (dataset: Dataset, prefixes: any = {}, customFunctions?: CustomFunctions) {
this._dataset = dataset
this._parser = new Parser(prefixes)
this._optimizer = Optimizer.getDefault()
this._customFunctions = customFunctions
this._stageBuilders = new Map()
// add default stage builders
this.use(SPARQL_OPERATION.AGGREGATE, new AggregateStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.BGP, new BGPStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.BIND, new BindStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.DISTINCT, new DistinctStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.FILTER, new FilterStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.GRAPH, new GraphStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.MINUS, new MinusStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.SERVICE, new ServiceStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.OPTIONAL, new OptionalStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.ORDER_BY, new OrderByStageBuilder(this._dataset))
this.use(SPARQL_OPERATION.PROPERTY_PATH, new GlushkovStageBuilder(this._dataset))
function post (req, res) {
req.setTimeout(0) // no timeout
var graphUri
if (req.body.graph === 'user') {
graphUri = req.user.graphUri
} else {
graphUri = null
}
const parser = new SparqlParser()
const generator = new SparqlGenerator()
var query
try {
query = parser.parse(req.body.query)
} catch (e) {
form(req, res, {
query: req.body.query,
graph: req.body.graph,
errors: [
e.stack
]
})
return
function SparqlIterator(source, query, options) {
// Set argument defaults
if (typeof source.read !== 'function')
options = query, query = source, source = null;
options = options || {};
source = source || AsyncIterator.single({});
// Transform the query into a cascade of iterators
try {
// Parse the query if needed
if (typeof query === 'string')
query = new SparqlParser(options.prefixes).parse(query);
// Create an iterator that projects the bindings according to the query type
var queryIterator, QueryConstructor = queryConstructors[query.queryType];
if (!QueryConstructor)
throw new Error('No iterator available for query type: ' + query.queryType);
queryIterator = new QueryConstructor(null, query, options);
// Create an iterator for bindings of the query's graph pattern
var graphIterator = new SparqlGroupsIterator(source,
queryIterator.patterns || query.where, options);
// Create iterators for each order
for (var i = query.order && (query.order.length - 1); i >= 0; i--) {
var order = new SparqlExpressionEvaluator(query.order[i].expression),
ascending = !query.order[i].descending;
graphIterator = new SortIterator(graphIterator, function (a, b) {
var orderA = '', orderB = '';
import RemoteSparqlService from '../remote-sparql-service'
import {getPrefixesFromQuery} from '../query'
import _ from 'lodash'
import {Parser, Generator} from 'sparqljs'
const parser = new Parser()
const generator = new Generator()
const sparqlService = new RemoteSparqlService()
export default {
state: {
'query': '',
'isLoading': false,
outstandingQuery: undefined // Used to store query for aborting
},
getters: {
query: state => {
return state.query
},
isLoading: state => {
return state.isLoading
}
let limitStr = "";
if (limit) {
limitStr = `LIMIT ${parseInt(limit)}`;
}
const queryTemplate = `
${prefixesString(prefixes)}
SELECT ${distinctStr} ${variables.join(" ")}
WHERE {
${where ? where.join(" \n") : ""}
} ${orderByStr} ${groupByStr} ${limitStr}`;
// ---------- parse root-query ----------
const queryAST = new SparqlParser().parse(queryTemplate);
// ---------- if there are sub-queries, add their ASTs and prefixes ----------
addSubQueries(queryAST, subQueries);
// ---------- return AST ----------
return queryAST;
}
build (query, options = { format: 'raw' }) {
// If needed, parse the string query into a logical query execution plan
if (typeof query === 'string') {
query = new Parser(options.prefixes).parse(query)
}
switch (query.type) {
case 'query':
const iterator = this._buildQueryPlan(query, options)
// only use results formatters for select & ask queries
if (query.queryType === 'CONSTRUCT' || query.queryType === 'DESCRIBE') {
return iterator
}
switch (options.format) {
case 'xml':
case 'application/xml':
case 'application/sparql-results+xml':
return new XMLFormatter(iterator, query.variables)
default:
return iterator
}
const findTemplatesForUri = (
dropTemplateConfig: DropTemplateConfigItem[], uri: string
): Kefir.Property => {
const query = new SparqlJs.Parser().parse(`
PREFIX rdfs:
SELECT ?type ?label ?lang WHERE {
<${uri}> a ?type .
OPTIONAL {
?type rdfs:label ?label .
BIND(LANG(?label) AS ?lang)
}
}
`);
return SparqlClient.select(query).map((result: SparqlClient.SparqlSelectResult) => {
const types = result.results.bindings;
let possibleTemplates = [];
dropTemplateConfig.map(configItem => {
const {type} = configItem;
if (type === 'any' || _.find(types, value => value['type'].value === type)) {
possibleTemplates.push(configItem);
constructor(stores) {
this._stores = stores;
this._parser = new SparqlParser();
}
export function parsePatterns(
patterns: string, prefixes?: { [prefix: string]: string }
): SparqlJs.Pattern[] {
const wrappedPattern = `SELECT * WHERE { ${patterns} }`;
const parser = prefixes
? new SparqlJs.Parser(prefixes)
: Parser;
const query = parser.parse(
encodeLegacyVars(replaceQueryParams(wrappedPattern))
) as SparqlJs.SelectQuery;
return query.where;
}