sparqlalgebrajs
Advanced tools
Comparing version 0.6.4 to 0.6.5
17
index.js
@@ -9,19 +9,2 @@ "use strict"; | ||
exports.Factory = Factory_1.default; | ||
// let algebra = translate( | ||
// `PREFIX : <http://www.example.org> | ||
// PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | ||
// SELECT ?L | ||
// WHERE { | ||
// ?O :hasItem [ rdfs:label ?L ] . | ||
// { | ||
// SELECT DISTINCT ?O | ||
// WHERE { ?O a :Order } | ||
// ORDER BY ?O | ||
// LIMIT 2 | ||
// } | ||
// } ORDER BY ?L` | ||
// ); | ||
// console.log(JSON.stringify(algebra, null, 2)); | ||
// console.log(JSON.stringify(toSparqlJs(algebra), null, 2)); | ||
// console.log(toSparql(algebra)); | ||
//# sourceMappingURL=index.js.map |
@@ -5,5 +5,7 @@ import * as rdfjs from "rdf-js"; | ||
ALT: string; | ||
ASK: string; | ||
BGP: string; | ||
CONSTRUCT: string; | ||
DESC: string; | ||
DESCRIBE: string; | ||
DISTINCT: string; | ||
@@ -92,2 +94,5 @@ EXPRESSION: string; | ||
} | ||
export interface Ask extends Single { | ||
type: 'ask'; | ||
} | ||
export interface BoundAggregate extends AggregateExpression { | ||
@@ -104,2 +109,6 @@ variable: rdfjs.Variable; | ||
} | ||
export interface Describe extends Single { | ||
type: 'describe'; | ||
terms: rdfjs.Term[]; | ||
} | ||
export interface Distinct extends Single { | ||
@@ -106,0 +115,0 @@ type: 'distinct'; |
@@ -8,5 +8,7 @@ "use strict"; | ||
ALT: 'alt', | ||
ASK: 'ask', | ||
BGP: 'bgp', | ||
CONSTRUCT: 'construct', | ||
DESC: 'desc', | ||
DESCRIBE: 'describe', | ||
DISTINCT: 'distinct', | ||
@@ -13,0 +15,0 @@ EXPRESSION: 'expression', |
@@ -8,5 +8,7 @@ import * as A from './algebra'; | ||
createAlt(left: A.Operation, right: A.Operation): A.Alt; | ||
createAsk(input: A.Operation): A.Ask; | ||
createBoundAggregate(variable: RDF.Variable, aggregate: string, expression: A.Expression, distinct: boolean, separator?: string): A.BoundAggregate; | ||
createBgp(patterns: A.Pattern[]): A.Bgp; | ||
createConstruct(input: A.Operation, template: A.Pattern[]): A.Construct; | ||
createDescribe(input: A.Operation, terms: RDF.Term[]): A.Describe; | ||
createDistinct(input: A.Operation): A.Distinct; | ||
@@ -13,0 +15,0 @@ createExtend(input: A.Operation, variable: RDF.Variable, expression: A.Expression): A.Extend; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const n3_1 = require("n3"); | ||
const rdf_string_1 = require("rdf-string"); | ||
const defaultGraph = { termType: 'DefaultGraph', value: '' }; | ||
@@ -11,2 +11,3 @@ class Factory { | ||
createAlt(left, right) { return { type: 'alt', left, right }; } | ||
createAsk(input) { return { type: 'ask', input }; } | ||
createBoundAggregate(variable, aggregate, expression, distinct, separator) { | ||
@@ -19,2 +20,3 @@ let result = this.createAggregateExpression(aggregate, expression, distinct, separator); | ||
createConstruct(input, template) { return { type: 'construct', input, template }; } | ||
createDescribe(input, terms) { return { type: 'describe', input, terms }; } | ||
createDistinct(input) { return { type: 'distinct', input }; } | ||
@@ -74,18 +76,3 @@ createExtend(input, variable, expression) { return { type: 'extend', input, variable, expression }; } | ||
createTerm(str) { | ||
if (str[0] === '?') | ||
return this.dataFactory.variable(str.substring(1)); | ||
if (str.startsWith('_:')) | ||
return this.dataFactory.blankNode(str.substring(2)); | ||
if (n3_1.Util.isLiteral(str)) { | ||
let value = n3_1.Util.getLiteralValue(str); | ||
let lang = n3_1.Util.getLiteralLanguage(str); | ||
if (lang && lang.length > 0) | ||
return this.dataFactory.literal(value, lang); | ||
let type = n3_1.Util.getLiteralType(str); | ||
let datatype = this.stringType; | ||
if (type && type.length > 0) | ||
datatype = this.createTerm(type); | ||
return this.dataFactory.literal(value, datatype); | ||
} | ||
return this.dataFactory.namedNode(str); | ||
return rdf_string_1.stringToTerm(str, this.dataFactory); | ||
} | ||
@@ -92,0 +79,0 @@ } |
@@ -40,4 +40,4 @@ "use strict"; | ||
throw new Error('Translate only works on complete query objects.'); | ||
// group and where are identical, having only 1 makes parsing easier | ||
let group = { type: 'group', patterns: sparql.where }; | ||
// group and where are identical, having only 1 makes parsing easier, can be undefined in DESCRIBE | ||
let group = { type: 'group', patterns: sparql.where || [] }; | ||
let vars = new Set(Object.keys(inScopeVariables(group)).map(factory.createTerm.bind(factory))); | ||
@@ -349,12 +349,13 @@ let res = translateGroupGraphPattern(group); | ||
let PV = new Set(); | ||
// interpret other query types as SELECT * | ||
if (query.queryType !== 'SELECT' || query.variables.indexOf('*') >= 0) | ||
PV = variables; | ||
else { | ||
for (let v of query.variables) { | ||
if (isVariable(v)) | ||
PV.add(factory.createTerm(v)); | ||
else if (v.variable) { | ||
PV.add(factory.createTerm(v.variable)); | ||
E.push(v); | ||
if (query.queryType === 'SELECT') { | ||
if (query.variables.indexOf('*') >= 0) | ||
PV = variables; | ||
else { | ||
for (let v of query.variables) { | ||
if (isVariable(v)) | ||
PV.add(factory.createTerm(v)); | ||
else if (v.variable) { | ||
PV.add(factory.createTerm(v.variable)); | ||
E.push(v); | ||
} | ||
} | ||
@@ -378,3 +379,3 @@ } | ||
// construct does not need a project (select, ask and describe do) | ||
if (query.queryType !== 'CONSTRUCT') | ||
if (query.queryType === 'SELECT') | ||
res = factory.createProject(res, Array.from(PV)); | ||
@@ -387,6 +388,2 @@ // 18.2.5.3 | ||
res = factory.createReduced(res); | ||
// NEW: support for construct queries | ||
// limits are also applied to construct results, which is why those come last, although results should be the same | ||
if (query.queryType === 'CONSTRUCT') | ||
res = factory.createConstruct(res, query.template.map(translateTriple)); | ||
// 18.2.5.5 | ||
@@ -398,2 +395,9 @@ if (query.offset || query.limit) { | ||
} | ||
// NEW: support for ask/construct/describe queries | ||
if (query.queryType === 'CONSTRUCT') | ||
res = factory.createConstruct(res, query.template.map(translateTriple)); | ||
else if (query.queryType === 'ASK') | ||
res = factory.createAsk(res); | ||
else if (query.queryType === 'DESCRIBE') | ||
res = factory.createDescribe(res, query.variables.map(factory.createTerm.bind(factory))); | ||
return res; | ||
@@ -400,0 +404,0 @@ } |
{ | ||
"name": "sparqlalgebrajs", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "Convert SPARQL to SPARL algebra", | ||
@@ -15,4 +15,4 @@ "author": "Joachim Van Herwegen", | ||
"minimist": "^1.2.0", | ||
"n3": "^0.11.2", | ||
"rdf-data-model": "^1.0.0", | ||
"rdf-string": "^1.1.0", | ||
"sparqljs": "^1.5.2" | ||
@@ -30,2 +30,3 @@ }, | ||
"mocha": "^3.5.3", | ||
"n3": "^0.11.2", | ||
"pre-commit": "^1.2.2", | ||
@@ -32,0 +33,0 @@ "typescript": "^2.5.3" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49562
13
1211
12
+ Addedrdf-string@^1.1.0
+ Added@rdfjs/types@1.1.2(transitive)
+ Added@types/node@22.5.5(transitive)
+ Addedrdf-data-factory@1.1.2(transitive)
+ Addedrdf-string@1.6.3(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removedn3@^0.11.2
- Removedn3@0.11.3(transitive)