forked from RubenVerborgh/SPARQL.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparql.js
32 lines (30 loc) · 1.06 KB
/
sparql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var Parser = require('./lib/SparqlParser').Parser;
var Generator = require('./lib/SparqlGenerator');
var Wildcard = require("./lib/Wildcard").Wildcard;
var N3 = require('n3');
module.exports = {
/**
* Creates a SPARQL parser with the given pre-defined prefixes and base IRI
* @param prefixes { [prefix: string]: string }
* @param baseIRI string
*/
Parser: function ({ prefixes, baseIRI, factory } = {}) {
// Create a copy of the prefixes
var prefixesCopy = {};
for (var prefix in prefixes || {})
prefixesCopy[prefix] = prefixes[prefix];
// Create a new parser with the given prefixes
// (Workaround for https://github.com/zaach/jison/issues/241)
var parser = new Parser();
parser.parse = function () {
Parser.base = baseIRI || '';
Parser.prefixes = Object.create(prefixesCopy);
Parser.factory = factory || N3.DataFactory;
return Parser.prototype.parse.apply(parser, arguments);
};
parser._resetBlanks = Parser._resetBlanks;
return parser;
},
Generator: Generator,
Wildcard: Wildcard,
};