@traqula/generator-sparql-1-2 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/index.js +47 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/integration.test.js +150 -0
- package/dist/cjs/test/statics.test.js +83 -0
- package/{lib → dist/esm/lib}/index.d.ts +34 -34
- package/dist/esm/lib/index.js.map +1 -0
- package/dist/esm/test/integration.test.d.ts +1 -0
- package/dist/esm/test/integration.test.js +155 -0
- package/dist/esm/test/integration.test.js.map +1 -0
- package/dist/esm/test/statics.test.d.ts +1 -0
- package/dist/esm/test/statics.test.js +64 -0
- package/dist/esm/test/statics.test.js.map +1 -0
- package/package.json +18 -19
- package/lib/index.cjs +0 -15605
- package/lib/index.js.map +0 -1
- /package/{lib → dist/esm/lib}/index.js +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var lib_exports = {};
|
|
20
|
+
__export(lib_exports, {
|
|
21
|
+
Generator: () => Generator,
|
|
22
|
+
sparql12GeneratorBuilder: () => sparql12GeneratorBuilder
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(lib_exports);
|
|
25
|
+
var import_core = require("@traqula/core");
|
|
26
|
+
var import_generator_sparql_1_1 = require("@traqula/generator-sparql-1-1");
|
|
27
|
+
var import_rules_sparql_1_2 = require("@traqula/rules-sparql-1-2");
|
|
28
|
+
const sparql12GeneratorBuilder = import_core.GeneratorBuilder.create(import_generator_sparql_1_1.sparql11GeneratorBuilder).widenContext().typePatch().addRule(import_rules_sparql_1_2.gram.tripleTerm).addRule(import_rules_sparql_1_2.gram.reifiedTriple).patchRule(import_rules_sparql_1_2.gram.graphNodePath).addRule(import_rules_sparql_1_2.gram.annotationBlockPath).addRule(import_rules_sparql_1_2.gram.annotationPath).addRule(import_rules_sparql_1_2.gram.versionDecl).patchRule(import_rules_sparql_1_2.gram.prologue).patchRule(import_rules_sparql_1_2.gram.generateTriplesBlock).patchRule(import_rules_sparql_1_2.gram.generateGraphTerm);
|
|
29
|
+
class Generator {
|
|
30
|
+
defaultContext;
|
|
31
|
+
constructor(defaultContext = {}) {
|
|
32
|
+
this.defaultContext = defaultContext;
|
|
33
|
+
}
|
|
34
|
+
generator = sparql12GeneratorBuilder.build();
|
|
35
|
+
F = new import_rules_sparql_1_2.AstFactory();
|
|
36
|
+
generate(ast, context = {}) {
|
|
37
|
+
return this.generator.queryOrUpdate(ast, (0, import_rules_sparql_1_2.completeParseContext)({ ...this.defaultContext, ...context })).trim();
|
|
38
|
+
}
|
|
39
|
+
generatePath(ast, context = {}) {
|
|
40
|
+
return this.generator.path(ast, (0, import_rules_sparql_1_2.completeParseContext)({ ...this.defaultContext, ...context }), void 0).trim();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
Generator,
|
|
46
|
+
sparql12GeneratorBuilder
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_parser_sparql_1_2 = require("@traqula/parser-sparql-1-2");
|
|
3
|
+
var import_rules_sparql_1_1 = require("@traqula/rules-sparql-1-1");
|
|
4
|
+
var import_rules_sparql_1_2 = require("@traqula/rules-sparql-1-2");
|
|
5
|
+
var import_vitest = require("vitest");
|
|
6
|
+
var import_lib = require("../lib/index.js");
|
|
7
|
+
(0, import_vitest.describe)("a SPARQL 1.2 generator", () => {
|
|
8
|
+
const generator = new import_lib.Generator();
|
|
9
|
+
const parser = new import_parser_sparql_1_2.Parser();
|
|
10
|
+
const F = new import_rules_sparql_1_2.AstFactory();
|
|
11
|
+
const transformer = new import_rules_sparql_1_1.AstTransformer();
|
|
12
|
+
(0, import_vitest.it)("generates simple round tripped", ({ expect }) => {
|
|
13
|
+
const query = "SELECT * WHERE { ?s ?p ?o }";
|
|
14
|
+
const ast = parser.parse(query);
|
|
15
|
+
const result = generator.generate(ast, { origSource: query });
|
|
16
|
+
expect(result).toBe(query);
|
|
17
|
+
});
|
|
18
|
+
(0, import_vitest.describe)("on altered nodes", () => {
|
|
19
|
+
(0, import_vitest.it)("translates ?s -> ?subject", ({ expect }) => {
|
|
20
|
+
const query = "SELECT * WHERE { ?s ?p ?o }";
|
|
21
|
+
const ast = parser.parse(query);
|
|
22
|
+
const altered = transformer.transformNodeSpecific(ast, {}, { term: { variable: {
|
|
23
|
+
transform: (variable) => variable.value === "s" ? F.termVariable("subject", F.sourceLocationNodeReplaceUnsafe(variable.loc)) : variable
|
|
24
|
+
} } });
|
|
25
|
+
const result = generator.generate(altered, { origSource: query });
|
|
26
|
+
expect(result).toBe(`SELECT * WHERE { ?subject ?p ?o }`);
|
|
27
|
+
});
|
|
28
|
+
(0, import_vitest.it)("translates blanknodes -> variables", ({ expect }) => {
|
|
29
|
+
const query = `BASE <ex:>
|
|
30
|
+
CONSTRUCT {
|
|
31
|
+
?s0 ?p0 _:g_0 .
|
|
32
|
+
_:g_0 <a0> _:g_1 .
|
|
33
|
+
_:g_1 <b0><c0> .
|
|
34
|
+
[
|
|
35
|
+
<a0> [
|
|
36
|
+
<b0> <c0> ;
|
|
37
|
+
] ;
|
|
38
|
+
] ?p0 ?o0 .
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
WHERE {
|
|
42
|
+
?s1 ?p1 [], <a1>; ?q1 <b1>, <c1>.
|
|
43
|
+
[] ?p2 ?o2.
|
|
44
|
+
?s3 ?p3 [ <a3> <b3> ].
|
|
45
|
+
?s4 ?p4 [ <a4> <b4>; <c4> <d4>, <e4> ].
|
|
46
|
+
?s5 ?p5 [ <a5> [ <b5> <c5> ] ].
|
|
47
|
+
[ <a6> [ <b6> <c6> ] ] ?p6 ?o6.
|
|
48
|
+
[ <a7> <b7>; <c7> <d7>, <e7> ].
|
|
49
|
+
}`;
|
|
50
|
+
const ast = parser.parse(query);
|
|
51
|
+
function extractCollection(collection) {
|
|
52
|
+
const result2 = [];
|
|
53
|
+
for (const entry of collection.triples) {
|
|
54
|
+
const subject = entry.subject;
|
|
55
|
+
const pred = entry.predicate;
|
|
56
|
+
if (F.isTripleCollection(entry.object)) {
|
|
57
|
+
const identifier = { ...F.graphNodeIdentifier(entry.object) };
|
|
58
|
+
result2.push(F.annotatedTriple(subject, pred, identifier, void 0, F.gen()));
|
|
59
|
+
result2.push(...extractCollection(entry.object));
|
|
60
|
+
} else {
|
|
61
|
+
result2.push(F.annotatedTriple(subject, pred, entry.object, void 0, F.gen()));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result2;
|
|
65
|
+
}
|
|
66
|
+
const flattenCollections = transformer.transformNodeSpecific(ast, {}, { pattern: { bgp: {
|
|
67
|
+
transform: (current) => {
|
|
68
|
+
const bgpCopy = F.forcedAutoGenTree(current);
|
|
69
|
+
const newTriples = [];
|
|
70
|
+
for (const entry of bgpCopy.triples) {
|
|
71
|
+
if (F.isTriple(entry)) {
|
|
72
|
+
const subject = entry.subject;
|
|
73
|
+
const pred = entry.predicate;
|
|
74
|
+
if (F.isTripleCollection(entry.object)) {
|
|
75
|
+
const object = entry.object;
|
|
76
|
+
const identifier = { ...F.graphNodeIdentifier(object) };
|
|
77
|
+
newTriples.push(F.annotatedTriple(subject, pred, identifier));
|
|
78
|
+
newTriples.push(...extractCollection(object));
|
|
79
|
+
} else {
|
|
80
|
+
newTriples.push(F.annotatedTriple(subject, pred, entry.object, void 0, F.gen()));
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
const genTriples = extractCollection(entry);
|
|
84
|
+
newTriples.push(...genTriples);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return F.patternBgp(newTriples, F.sourceLocationNodeReplaceUnsafe(current.loc));
|
|
88
|
+
}
|
|
89
|
+
} } });
|
|
90
|
+
const result = generator.generate(flattenCollections, { origSource: query });
|
|
91
|
+
expect(result).toBe(`BASE <ex:>
|
|
92
|
+
CONSTRUCT {
|
|
93
|
+
?s0 ?p0 _:g_0 .
|
|
94
|
+
_:g_0 <a0> _:g_1 .
|
|
95
|
+
_:g_1 <b0> <c0> .
|
|
96
|
+
[
|
|
97
|
+
<a0> [
|
|
98
|
+
<b0> <c0> ;
|
|
99
|
+
] ;
|
|
100
|
+
] ?p0 ?o0 .
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
WHERE {
|
|
105
|
+
?s1 ?p1 _:g_2 .
|
|
106
|
+
?s1 ?p1 <a1> .
|
|
107
|
+
?s1 ?q1 <b1> .
|
|
108
|
+
?s1 ?q1 <c1> .
|
|
109
|
+
_:g_3 ?p2 ?o2 .
|
|
110
|
+
?s3 ?p3 _:g_4 .
|
|
111
|
+
_:g_4 <a3> <b3> .
|
|
112
|
+
?s4 ?p4 _:g_5 .
|
|
113
|
+
_:g_5 <a4> <b4> .
|
|
114
|
+
_:g_5 <c4> <d4> .
|
|
115
|
+
_:g_5 <c4> <e4> .
|
|
116
|
+
?s5 ?p5 _:g_6 .
|
|
117
|
+
_:g_6 <a5> _:g_7 .
|
|
118
|
+
_:g_7 <b5> <c5> .
|
|
119
|
+
[
|
|
120
|
+
<a6> [
|
|
121
|
+
<b6> <c6> ;
|
|
122
|
+
] ;
|
|
123
|
+
] ?p6 ?o6 .
|
|
124
|
+
_:g_10 <a7> <b7> .
|
|
125
|
+
_:g_10 <c7> <d7> .
|
|
126
|
+
_:g_10 <c7> <e7> .
|
|
127
|
+
|
|
128
|
+
}`);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
(0, import_vitest.it)("generates hand constructed query", ({ expect }) => {
|
|
132
|
+
const query = `
|
|
133
|
+
SELECT * WHERE {
|
|
134
|
+
?s ?p ?o .
|
|
135
|
+
}`;
|
|
136
|
+
const ast = F.querySelect({
|
|
137
|
+
variables: [F.wildcard(F.gen())],
|
|
138
|
+
datasets: F.datasetClauses([], F.sourceLocation()),
|
|
139
|
+
context: [],
|
|
140
|
+
where: F.patternGroup([
|
|
141
|
+
F.patternBgp([
|
|
142
|
+
F.triple(F.termVariable("s", F.gen()), F.termVariable("p", F.gen()), F.termVariable("o", F.gen()))
|
|
143
|
+
], F.gen())
|
|
144
|
+
], F.gen()),
|
|
145
|
+
solutionModifiers: {}
|
|
146
|
+
}, F.gen());
|
|
147
|
+
const result = generator.generate(ast);
|
|
148
|
+
expect(result.trim()).toBe(query.trim());
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
25
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
26
|
+
var import_rules_sparql_1_2 = require("@traqula/rules-sparql-1-2");
|
|
27
|
+
var import_test_utils = require("@traqula/test-utils");
|
|
28
|
+
var import_vitest = require("vitest");
|
|
29
|
+
var import_lib = require("../lib/index.js");
|
|
30
|
+
(0, import_vitest.describe)("a SPARQL 1.2 generator", () => {
|
|
31
|
+
const generator = new import_lib.Generator();
|
|
32
|
+
const F = new import_rules_sparql_1_2.AstFactory();
|
|
33
|
+
function _sinkGenerated(suite, test, response) {
|
|
34
|
+
const dir = (0, import_test_utils.getStaticFilePath)();
|
|
35
|
+
const fileLoc = import_node_path.default.join(dir, suite, `${test}-generated.sparql`);
|
|
36
|
+
import_node_fs.default.writeFileSync(fileLoc, response);
|
|
37
|
+
}
|
|
38
|
+
(0, import_vitest.describe)("positive paths", () => {
|
|
39
|
+
for (const { name, statics } of (0, import_test_utils.positiveTest)("paths")) {
|
|
40
|
+
(0, import_vitest.it)(`can parse ${name}`, async ({ expect }) => {
|
|
41
|
+
const { query, ast, autoGen } = await statics();
|
|
42
|
+
const path2 = ast;
|
|
43
|
+
const generated = generator.generatePath(path2, { origSource: query });
|
|
44
|
+
expect(generated, "round tripped generation").toEqual(query.trim());
|
|
45
|
+
const replaceLoc = F.sourceLocationNodeReplaceUnsafe(path2.loc);
|
|
46
|
+
const autoGenAst = F.forcedAutoGenTree(path2);
|
|
47
|
+
autoGenAst.loc = replaceLoc;
|
|
48
|
+
const selfGenerated = generator.generatePath(autoGenAst);
|
|
49
|
+
expect(selfGenerated, "auto generated").toEqual(autoGen.trim());
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
(0, import_vitest.describe)("positive sparql 1.1", () => {
|
|
54
|
+
for (const { name, statics } of (0, import_test_utils.positiveTest)("sparql-1-1")) {
|
|
55
|
+
(0, import_vitest.it)(`can parse ${name}`, async ({ expect }) => {
|
|
56
|
+
const { query, ast, autoGen } = await statics();
|
|
57
|
+
const queryUpdate = ast;
|
|
58
|
+
const roundTripped = generator.generate(queryUpdate, { origSource: query });
|
|
59
|
+
expect(roundTripped, "round-tripped generation").toEqual(query.trim());
|
|
60
|
+
const replaceLoc = F.sourceLocationNodeReplaceUnsafe(queryUpdate.loc);
|
|
61
|
+
const autoGenAst = F.forcedAutoGenTree(queryUpdate);
|
|
62
|
+
autoGenAst.loc = replaceLoc;
|
|
63
|
+
const selfGenerated = generator.generate(autoGenAst);
|
|
64
|
+
expect(selfGenerated, "auto generated").toEqual(autoGen.trim());
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
(0, import_vitest.describe)("positive sparql 1.2", () => {
|
|
69
|
+
for (const { name, statics } of (0, import_test_utils.positiveTest)("sparql-1-2")) {
|
|
70
|
+
(0, import_vitest.it)(`can parse ${name}`, async ({ expect }) => {
|
|
71
|
+
const { query, ast, autoGen } = await statics();
|
|
72
|
+
const queryUpdate = ast;
|
|
73
|
+
const roundTripped = generator.generate(queryUpdate, { origSource: query });
|
|
74
|
+
expect(roundTripped, "round-tripped generation").toEqual(query.trim());
|
|
75
|
+
const replaceLoc = F.sourceLocationNodeReplaceUnsafe(queryUpdate.loc);
|
|
76
|
+
const autoGenAst = F.forcedAutoGenTree(queryUpdate);
|
|
77
|
+
autoGenAst.loc = replaceLoc;
|
|
78
|
+
const selfGenerated = generator.generate(autoGenAst);
|
|
79
|
+
expect(selfGenerated, "auto generated").toEqual(autoGen.trim());
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -2,42 +2,53 @@ import { GeneratorBuilder } from '@traqula/core';
|
|
|
2
2
|
import type { Wrap, Patch } from '@traqula/core';
|
|
3
3
|
import type { gram as g11 } from '@traqula/rules-sparql-1-1';
|
|
4
4
|
import type * as T12 from '@traqula/rules-sparql-1-2';
|
|
5
|
-
export declare const sparql12GeneratorBuilder: GeneratorBuilder<T12.SparqlGeneratorContext, "
|
|
6
|
-
|
|
5
|
+
export declare const sparql12GeneratorBuilder: GeneratorBuilder<T12.SparqlGeneratorContext, "filter" | "copy" | "graphRef" | "load" | "clear" | "drop" | "create" | "add" | "move" | "modify" | "update" | "query" | "datasetClauses" | "bind" | "solutionModifier" | "expression" | "aggregate" | "path" | "blankNode" | "selectQuery" | "selectClause" | "constructQuery" | "describeQuery" | "askQuery" | "update1" | "insertData" | "deleteData" | "deleteWhere" | "graphRefAll" | "quads" | "quadsNotTriples" | "usingClauses" | "argList" | "iriOrFunction" | "prologue" | "baseDecl" | "prefixDecl" | "varOrTerm" | "var" | "graphTerm" | "rdfLiteral" | "iri" | "iriFull" | "prefixedName" | "groupClause" | "havingClause" | "orderClause" | "limitOffsetClauses" | "triplesBlock" | "collectionPath" | "triplesNodePath" | "blankNodePropertyListPath" | "graphNodePath" | "whereClause" | "groupGraphPattern" | "generatePattern" | "graphPatternNotTriples" | "optionalGraphPattern" | "graphGraphPattern" | "serviceGraphPattern" | "inlineData" | "minusGraphPattern" | "groupOrUnionGraphPattern" | "queryOrUpdate" | "reifiedTriple" | "versionDecl" | "annotationPath" | "annotationBlockPath" | "tripleTerm", {
|
|
6
|
+
filter: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "filter", T12.PatternFilter, []>;
|
|
7
|
+
copy: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "copy", T12.UpdateOperationCopy, []>;
|
|
8
|
+
graphRef: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphRef", import("@traqula/rules-sparql-1-1").TermIri, []>;
|
|
9
|
+
load: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "load", T12.UpdateOperationLoad, []>;
|
|
10
|
+
clear: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "clear", T12.UpdateOperationClear, []>;
|
|
11
|
+
drop: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "drop", T12.UpdateOperationDrop, []>;
|
|
12
|
+
create: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "create", T12.UpdateOperationCreate, []>;
|
|
13
|
+
add: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "add", T12.UpdateOperationAdd, []>;
|
|
14
|
+
move: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "move", T12.UpdateOperationMove, []>;
|
|
15
|
+
modify: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "modify", T12.UpdateOperationModify, []>;
|
|
16
|
+
update: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "update", T12.Update, []>;
|
|
7
17
|
query: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "query", T12.Query, []>;
|
|
18
|
+
datasetClauses: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "datasetClauses", T12.DatasetClauses, []>;
|
|
19
|
+
bind: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "bind", T12.PatternBind, []>;
|
|
20
|
+
solutionModifier: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "solutionModifier", T12.SolutionModifiers, []>;
|
|
21
|
+
expression: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "expression", T12.Expression, []>;
|
|
22
|
+
aggregate: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "aggregate", T12.ExpressionAggregate, []>;
|
|
23
|
+
path: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "path", import("@traqula/rules-sparql-1-1").Path, [boolean | undefined]>;
|
|
24
|
+
blankNode: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "blankNode", import("@traqula/core").Node & {
|
|
25
|
+
type: "term";
|
|
26
|
+
subType: string;
|
|
27
|
+
} & {
|
|
28
|
+
subType: "blankNode";
|
|
29
|
+
} & {
|
|
30
|
+
label: string;
|
|
31
|
+
}, []>;
|
|
8
32
|
selectQuery: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "selectQuery", Omit<T12.QuerySelect, g11.HandledByBase>, []>;
|
|
33
|
+
selectClause: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "selectClause", Wrap<Pick<T12.QuerySelect, "variables" | "distinct" | "reduced">>, []>;
|
|
9
34
|
constructQuery: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "constructQuery", Omit<T12.QueryConstruct, g11.HandledByBase>, []>;
|
|
10
35
|
describeQuery: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "describeQuery", Omit<T12.QueryDescribe, g11.HandledByBase>, []>;
|
|
11
36
|
askQuery: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "askQuery", Omit<T12.QueryAsk, g11.HandledByBase>, []>;
|
|
12
|
-
selectClause: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "selectClause", Wrap<Pick<T12.QuerySelect, "variables" | "distinct" | "reduced">>, []>;
|
|
13
|
-
update: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "update", T12.Update, []>;
|
|
14
37
|
update1: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "update1", T12.UpdateOperation, []>;
|
|
15
|
-
load: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "load", T12.UpdateOperationLoad, []>;
|
|
16
|
-
clear: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "clear", T12.UpdateOperationClear, []>;
|
|
17
|
-
drop: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "drop", T12.UpdateOperationDrop, []>;
|
|
18
|
-
create: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "create", T12.UpdateOperationCreate, []>;
|
|
19
|
-
copy: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "copy", T12.UpdateOperationCopy, []>;
|
|
20
|
-
move: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "move", T12.UpdateOperationMove, []>;
|
|
21
|
-
add: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "add", T12.UpdateOperationAdd, []>;
|
|
22
38
|
insertData: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "insertData", T12.UpdateOperationInsertData, []>;
|
|
23
39
|
deleteData: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "deleteData", T12.UpdateOperationDeleteData, []>;
|
|
24
40
|
deleteWhere: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "deleteWhere", T12.UpdateOperationDeleteWhere, []>;
|
|
25
|
-
modify: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "modify", T12.UpdateOperationModify, []>;
|
|
26
|
-
graphRef: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphRef", import("@traqula/rules-sparql-1-1").TermIri, []>;
|
|
27
41
|
graphRefAll: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphRefAll", import("@traqula/rules-sparql-1-1").GraphRef, []>;
|
|
28
42
|
quads: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "quads", Wrap<T12.Quads[]>, []>;
|
|
29
43
|
quadsNotTriples: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "quadsNotTriples", T12.GraphQuads, []>;
|
|
30
|
-
aggregate: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "aggregate", T12.ExpressionAggregate, []>;
|
|
31
|
-
datasetClauses: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "datasetClauses", T12.DatasetClauses, []>;
|
|
32
44
|
usingClauses: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "usingClauses", T12.DatasetClauses, []>;
|
|
33
45
|
argList: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "argList", Patch<g11.IArgList, {
|
|
34
46
|
args: T12.Expression[];
|
|
35
47
|
}>, []>;
|
|
36
|
-
expression: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "expression", T12.Expression, []>;
|
|
37
48
|
iriOrFunction: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "iriOrFunction", import("@traqula/rules-sparql-1-1").TermIri | T12.ExpressionFunctionCall, []>;
|
|
38
49
|
prologue: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "prologue", T12.ContextDefinition[], []>;
|
|
39
|
-
prefixDecl: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "prefixDecl", import("@traqula/rules-sparql-1-1").ContextDefinitionPrefix, []>;
|
|
40
50
|
baseDecl: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "baseDecl", import("@traqula/rules-sparql-1-1").ContextDefinitionBase, []>;
|
|
51
|
+
prefixDecl: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "prefixDecl", import("@traqula/rules-sparql-1-1").ContextDefinitionPrefix, []>;
|
|
41
52
|
varOrTerm: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "varOrTerm", T12.Term, []>;
|
|
42
53
|
var: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "var", import("@traqula/core").Node & {
|
|
43
54
|
type: "term";
|
|
@@ -47,14 +58,6 @@ export declare const sparql12GeneratorBuilder: GeneratorBuilder<T12.SparqlGenera
|
|
|
47
58
|
value: string;
|
|
48
59
|
}, []>;
|
|
49
60
|
graphTerm: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphTerm", T12.GraphTerm, []>;
|
|
50
|
-
blankNode: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "blankNode", import("@traqula/core").Node & {
|
|
51
|
-
type: "term";
|
|
52
|
-
subType: string;
|
|
53
|
-
} & {
|
|
54
|
-
subType: "blankNode";
|
|
55
|
-
} & {
|
|
56
|
-
label: string;
|
|
57
|
-
}, []>;
|
|
58
61
|
rdfLiteral: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "rdfLiteral", import("@traqula/rules-sparql-1-1").TermLiteral, []>;
|
|
59
62
|
iri: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "iri", import("@traqula/rules-sparql-1-1").TermIri, []>;
|
|
60
63
|
iriFull: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "iriFull", import("@traqula/core").Node & {
|
|
@@ -74,40 +77,37 @@ export declare const sparql12GeneratorBuilder: GeneratorBuilder<T12.SparqlGenera
|
|
|
74
77
|
value: string;
|
|
75
78
|
prefix: string;
|
|
76
79
|
}, []>;
|
|
77
|
-
path: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "path", import("@traqula/rules-sparql-1-1").Path, [boolean | undefined]>;
|
|
78
|
-
solutionModifier: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "solutionModifier", T12.SolutionModifiers, []>;
|
|
79
80
|
groupClause: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "groupClause", T12.SolutionModifierGroup, []>;
|
|
80
81
|
havingClause: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "havingClause", T12.SolutionModifierHaving, []>;
|
|
81
82
|
orderClause: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "orderClause", T12.SolutionModifierOrder, []>;
|
|
82
83
|
limitOffsetClauses: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "limitOffsetClauses", import("@traqula/rules-sparql-1-1").SolutionModifierLimitOffset, []>;
|
|
83
84
|
triplesBlock: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "triplesBlock", T12.PatternBgp, []>;
|
|
84
85
|
collectionPath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "collectionPath", T12.TripleCollectionList, []>;
|
|
86
|
+
triplesNodePath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "triplesNodePath", T12.TripleCollection, []>;
|
|
85
87
|
blankNodePropertyListPath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "blankNodePropertyListPath", Patch<import("@traqula/rules-sparql-1-1").TripleCollectionBlankNodeProperties, {
|
|
86
88
|
triples: T12.TripleNesting[];
|
|
87
89
|
identifier: T12.TermBlank | T12.TermVariable | T12.TermIri;
|
|
88
90
|
}>, []>;
|
|
89
|
-
triplesNodePath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "triplesNodePath", T12.TripleCollection, []>;
|
|
90
91
|
graphNodePath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphNodePath", T12.GraphNode, []>;
|
|
91
92
|
whereClause: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "whereClause", Wrap<T12.PatternGroup>, []>;
|
|
92
|
-
generatePattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "generatePattern", T12.Pattern, []>;
|
|
93
93
|
groupGraphPattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "groupGraphPattern", T12.PatternGroup, []>;
|
|
94
|
+
generatePattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "generatePattern", T12.Pattern, []>;
|
|
94
95
|
graphPatternNotTriples: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphPatternNotTriples", T12.PatternGroup | T12.PatternUnion | T12.PatternOptional | T12.PatternMinus | T12.PatternGraph | T12.PatternService | T12.PatternFilter | T12.PatternBind | T12.PatternValues, []>;
|
|
95
|
-
filter: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "filter", T12.PatternFilter, []>;
|
|
96
|
-
bind: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "bind", T12.PatternBind, []>;
|
|
97
96
|
optionalGraphPattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "optionalGraphPattern", T12.PatternOptional, []>;
|
|
98
97
|
graphGraphPattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "graphGraphPattern", T12.PatternGroup, []>;
|
|
99
98
|
serviceGraphPattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "serviceGraphPattern", T12.PatternService, []>;
|
|
100
99
|
inlineData: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "inlineData", T12.PatternValues, []>;
|
|
101
100
|
minusGraphPattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "minusGraphPattern", T12.PatternMinus, []>;
|
|
102
101
|
groupOrUnionGraphPattern: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "groupOrUnionGraphPattern", T12.PatternGroup | T12.PatternUnion, []>;
|
|
102
|
+
queryOrUpdate: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "queryOrUpdate", T12.SparqlQuery, []>;
|
|
103
103
|
reifiedTriple: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "reifiedTriple", T12.TripleCollectionReifiedTriple, []>;
|
|
104
|
-
|
|
104
|
+
versionDecl: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "versionDecl", T12.ContextDefinitionVersion, []>;
|
|
105
|
+
annotationPath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "annotationPath", T12.Annotation[], []>;
|
|
105
106
|
annotationBlockPath: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "annotationBlockPath", Patch<import("@traqula/rules-sparql-1-1").TripleCollectionBlankNodeProperties, {
|
|
106
107
|
triples: T12.TripleNesting[];
|
|
107
108
|
identifier: T12.TermBlank | T12.TermVariable | T12.TermIri;
|
|
108
109
|
}>, []>;
|
|
109
|
-
|
|
110
|
-
versionDecl: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "versionDecl", T12.ContextDefinitionVersion, []>;
|
|
110
|
+
tripleTerm: import("@traqula/core").GeneratorRule<T12.SparqlGeneratorContext, "tripleTerm", T12.TermTriple, []>;
|
|
111
111
|
}>;
|
|
112
112
|
export type SparqlGenerator = ReturnType<typeof sparql12GeneratorBuilder.build>;
|
|
113
113
|
export declare class Generator {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAIzE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,IAAI,IAAI,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAG1F,MAAM,CAAC,MAAM,wBAAwB,GACnC,gBAAgB,CAAC,MAAM,CAAC,wBAAwB,CAAC;KAC9C,YAAY,EAA8B;KAC1C,SAAS,EA6EN;KACH,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;KACvB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;KAC1B,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC;KAC5B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;KAChC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;KAC3B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;KACxB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;KACvB,SAAS,CAAC,GAAG,CAAC,oBAAoB,CAAC;KACnC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAItC,MAAM,OAAO,SAAS;IACgB;IAApC,YAAoC,iBAAsD,EAAE;QAAxD,mBAAc,GAAd,cAAc,CAA0C;IAAG,CAAC;IAE/E,SAAS,GAAoB,wBAAwB,CAAC,KAAK,EAAE,CAAC;IAC9D,CAAC,GAAG,IAAI,UAAU,EAAE,CAAC;IAE/B,QAAQ,CAAC,GAA2B,EAAE,UAA+C,EAAE;QAC5F,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,oBAAoB,CAAC,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChH,CAAC;IAEM,YAAY,CAAC,GAAa,EAAE,UAA+C,EAAE;QAClF,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;IAClH,CAAC;CACF","sourcesContent":["import { GeneratorBuilder } from '@traqula/core';\nimport type { Wrap, Patch } from '@traqula/core';\nimport { sparql11GeneratorBuilder } from '@traqula/generator-sparql-1-1';\nimport type {\n gram as g11,\n} from '@traqula/rules-sparql-1-1';\nimport { completeParseContext, AstFactory, gram as g12 } from '@traqula/rules-sparql-1-2';\nimport type * as T12 from '@traqula/rules-sparql-1-2';\n\nexport const sparql12GeneratorBuilder =\n GeneratorBuilder.create(sparql11GeneratorBuilder)\n .widenContext<T12.SparqlGeneratorContext>()\n .typePatch<{\n [g11.queryOrUpdate.name]: [T12.SparqlQuery];\n [g11.query.name]: [T12.Query];\n [g11.selectQuery.name]: [Omit<T12.QuerySelect, g11.HandledByBase>];\n [g11.constructQuery.name]: [ Omit<T12.QueryConstruct, g11.HandledByBase>];\n [g11.describeQuery.name]: [Omit<T12.QueryDescribe, g11.HandledByBase>];\n [g11.askQuery.name]: [Omit<T12.QueryAsk, g11.HandledByBase>];\n [g11.selectClause.name]: [ Wrap<Pick<T12.QuerySelect, 'variables' | 'distinct' | 'reduced'>> ];\n\n [g11.update.name]: [T12.Update];\n [g11.update1.name]: [T12.UpdateOperation];\n [g11.load.name]: [T12.UpdateOperationLoad];\n [g11.clear.name]: [T12.UpdateOperationClear];\n [g11.drop.name]: [T12.UpdateOperationDrop];\n [g11.create.name]: [T12.UpdateOperationCreate];\n [g11.copy.name]: [T12.UpdateOperationCopy];\n [g11.move.name]: [T12.UpdateOperationMove];\n [g11.add.name]: [T12.UpdateOperationAdd];\n [g11.insertData.name]: [T12.UpdateOperationInsertData];\n [g11.deleteData.name]: [T12.UpdateOperationDeleteData];\n [g11.deleteWhere.name]: [T12.UpdateOperationDeleteWhere];\n [g11.modify.name]: [T12.UpdateOperationModify];\n [g11.graphRef.name]: [T12.TermIri];\n [g11.graphRefAll.name]: [T12.GraphRef];\n [g11.quads.name]: [Wrap<T12.Quads[]>];\n [g11.quadsNotTriples.name]: [T12.GraphQuads];\n\n [g11.aggregate.name]: [ T12.ExpressionAggregate ];\n\n [g11.datasetClauseStar.name]: [ T12.DatasetClauses ];\n [g11.usingClauseStar.name]: [ T12.DatasetClauses ];\n\n // [g11.datasetClause.name]: unchanged;\n [g11.argList.name]: [ Patch<g11.IArgList, { args: T12.Expression[] }> ];\n [g11.expression.name]: [ T12.Expression ];\n [g11.iriOrFunction.name]: [T12.TermIri | T12.ExpressionFunctionCall];\n\n [g11.prologue.name]: [ T12.ContextDefinition[] ];\n [g11.prefixDecl.name]: [ T12.ContextDefinitionPrefix ];\n [g11.baseDecl.name]: [ T12.ContextDefinitionBase ];\n // [g11.var_.name]: unchanged;\n [g11.varOrTerm.name]: [ T12.Term ];\n [g11.graphTerm.name]: [ T12.GraphTerm ];\n\n [g11.rdfLiteral.name]: [T12.TermLiteral];\n // [g11.string.name]: unchanged;\n // [g11.iri.name]: unchanged;\n // [g11.iriFull.name]: unchanged;\n // [g11.prefixedName.name]: unchanged;\n // [g11.blankNode.name]: unchanged;\n\n // [g11.path.name]: unchanged;\n //\n [g11.solutionModifier.name]: [ T12.SolutionModifiers ];\n [g11.groupClause.name]: [ T12.SolutionModifierGroup ];\n [g11.havingClause.name]: [ T12.SolutionModifierHaving ];\n [g11.orderClause.name]: [ T12.SolutionModifierOrder ];\n [g11.limitOffsetClauses.name]: [ T12.SolutionModifierLimitOffset ];\n\n [g11.triplesBlock.name]: [ T12.PatternBgp ];\n [g11.collectionPath.name]: [ T12.TripleCollectionList ];\n [g11.blankNodePropertyListPath.name]: [ T12.TripleCollectionBlankNodeProperties ];\n [g11.triplesNodePath.name]: [ T12.TripleCollection ];\n [g11.graphNodePath.name]: [ T12.Term | T12.TripleCollection ];\n\n [g11.whereClause.name]: [ Wrap<T12.PatternGroup> ];\n [g11.generatePattern.name]: [ T12.Pattern ];\n [g11.groupGraphPattern.name]: [ T12.PatternGroup ];\n [g11.graphPatternNotTriples.name]: [ Exclude<T12.Pattern, T12.SubSelect | T12.PatternBgp> ];\n [g11.optionalGraphPattern.name]: [ T12.PatternOptional ];\n [g11.graphGraphPattern.name]: [ T12.PatternGroup ];\n [g11.serviceGraphPattern.name]: [ T12.PatternService ];\n [g11.bind.name]: [ T12.PatternBind ];\n [g11.inlineData.name]: [ T12.PatternValues ];\n [g11.minusGraphPattern.name]: [ T12.PatternMinus ];\n [g11.groupOrUnionGraphPattern.name]: [ T12.PatternGroup | T12.PatternUnion ];\n [g11.filter.name]: [ T12.PatternFilter ];\n }>()\n .addRule(g12.tripleTerm)\n .addRule(g12.reifiedTriple)\n .patchRule(g12.graphNodePath)\n .addRule(g12.annotationBlockPath)\n .addRule(g12.annotationPath)\n .addRule(g12.versionDecl)\n .patchRule(g12.prologue)\n .patchRule(g12.generateTriplesBlock)\n .patchRule(g12.generateGraphTerm);\n\nexport type SparqlGenerator = ReturnType<typeof sparql12GeneratorBuilder.build>;\n\nexport class Generator {\n public constructor(private readonly defaultContext: Partial<T12.SparqlGeneratorContext> = {}) {}\n\n private readonly generator: SparqlGenerator = sparql12GeneratorBuilder.build();\n private readonly F = new AstFactory();\n\n public generate(ast: T12.Query | T12.Update, context: Partial<T12.SparqlGeneratorContext> = {}): string {\n return this.generator.queryOrUpdate(ast, completeParseContext({ ...this.defaultContext, ...context })).trim();\n }\n\n public generatePath(ast: T12.Path, context: Partial<T12.SparqlGeneratorContext> = {}): string {\n return this.generator.path(ast, completeParseContext({ ...this.defaultContext, ...context }), undefined).trim();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Parser } from '@traqula/parser-sparql-1-2';
|
|
2
|
+
import { AstTransformer } from '@traqula/rules-sparql-1-1';
|
|
3
|
+
import { AstFactory } from '@traqula/rules-sparql-1-2';
|
|
4
|
+
import { describe, it } from 'vitest';
|
|
5
|
+
import { Generator } from '../lib/index.js';
|
|
6
|
+
describe('a SPARQL 1.2 generator', () => {
|
|
7
|
+
const generator = new Generator();
|
|
8
|
+
const parser = new Parser();
|
|
9
|
+
const F = new AstFactory();
|
|
10
|
+
const transformer = new AstTransformer();
|
|
11
|
+
it('generates simple round tripped', ({ expect }) => {
|
|
12
|
+
const query = 'SELECT * WHERE { ?s ?p ?o }';
|
|
13
|
+
const ast = parser.parse(query);
|
|
14
|
+
const result = generator.generate(ast, { origSource: query });
|
|
15
|
+
expect(result).toBe(query);
|
|
16
|
+
});
|
|
17
|
+
describe('on altered nodes', () => {
|
|
18
|
+
it('translates ?s -> ?subject', ({ expect }) => {
|
|
19
|
+
const query = 'SELECT * WHERE { ?s ?p ?o }';
|
|
20
|
+
const ast = parser.parse(query);
|
|
21
|
+
const altered = transformer.transformNodeSpecific(ast, {}, { term: { variable: {
|
|
22
|
+
transform: variable => variable.value === 's' ?
|
|
23
|
+
F.termVariable('subject', F.sourceLocationNodeReplaceUnsafe(variable.loc)) :
|
|
24
|
+
variable,
|
|
25
|
+
} } });
|
|
26
|
+
const result = generator.generate(altered, { origSource: query });
|
|
27
|
+
expect(result).toBe(`SELECT * WHERE { ?subject ?p ?o }`);
|
|
28
|
+
});
|
|
29
|
+
it('translates blanknodes -> variables', ({ expect }) => {
|
|
30
|
+
const query = `BASE <ex:>
|
|
31
|
+
CONSTRUCT {
|
|
32
|
+
?s0 ?p0 _:g_0 .
|
|
33
|
+
_:g_0 <a0> _:g_1 .
|
|
34
|
+
_:g_1 <b0><c0> .
|
|
35
|
+
[
|
|
36
|
+
<a0> [
|
|
37
|
+
<b0> <c0> ;
|
|
38
|
+
] ;
|
|
39
|
+
] ?p0 ?o0 .
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
WHERE {
|
|
43
|
+
?s1 ?p1 [], <a1>; ?q1 <b1>, <c1>.
|
|
44
|
+
[] ?p2 ?o2.
|
|
45
|
+
?s3 ?p3 [ <a3> <b3> ].
|
|
46
|
+
?s4 ?p4 [ <a4> <b4>; <c4> <d4>, <e4> ].
|
|
47
|
+
?s5 ?p5 [ <a5> [ <b5> <c5> ] ].
|
|
48
|
+
[ <a6> [ <b6> <c6> ] ] ?p6 ?o6.
|
|
49
|
+
[ <a7> <b7>; <c7> <d7>, <e7> ].
|
|
50
|
+
}`;
|
|
51
|
+
const ast = parser.parse(query);
|
|
52
|
+
function extractCollection(collection) {
|
|
53
|
+
const result = [];
|
|
54
|
+
for (const entry of collection.triples) {
|
|
55
|
+
const subject = entry.subject;
|
|
56
|
+
const pred = entry.predicate;
|
|
57
|
+
if (F.isTripleCollection(entry.object)) {
|
|
58
|
+
const identifier = { ...F.graphNodeIdentifier(entry.object) };
|
|
59
|
+
result.push(F.annotatedTriple(subject, pred, identifier, undefined, F.gen()));
|
|
60
|
+
result.push(...extractCollection(entry.object));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result.push(F.annotatedTriple(subject, pred, entry.object, undefined, F.gen()));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
const flattenCollections = transformer.transformNodeSpecific(ast, {}, { pattern: { bgp: {
|
|
69
|
+
transform: (current) => {
|
|
70
|
+
const bgpCopy = F.forcedAutoGenTree(current);
|
|
71
|
+
const newTriples = [];
|
|
72
|
+
for (const entry of bgpCopy.triples) {
|
|
73
|
+
if (F.isTriple(entry)) {
|
|
74
|
+
const subject = entry.subject;
|
|
75
|
+
const pred = entry.predicate;
|
|
76
|
+
if (F.isTripleCollection(entry.object)) {
|
|
77
|
+
const object = entry.object;
|
|
78
|
+
const identifier = { ...F.graphNodeIdentifier(object) };
|
|
79
|
+
newTriples.push(F.annotatedTriple(subject, pred, identifier));
|
|
80
|
+
newTriples.push(...extractCollection(object));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
newTriples.push(F.annotatedTriple(subject, pred, entry.object, undefined, F.gen()));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const genTriples = extractCollection(entry);
|
|
88
|
+
newTriples.push(...genTriples);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return F.patternBgp(newTriples, F.sourceLocationNodeReplaceUnsafe(current.loc));
|
|
92
|
+
},
|
|
93
|
+
} } });
|
|
94
|
+
const result = generator.generate(flattenCollections, { origSource: query });
|
|
95
|
+
expect(result).toBe(`BASE <ex:>
|
|
96
|
+
CONSTRUCT {
|
|
97
|
+
?s0 ?p0 _:g_0 .
|
|
98
|
+
_:g_0 <a0> _:g_1 .
|
|
99
|
+
_:g_1 <b0> <c0> .
|
|
100
|
+
[
|
|
101
|
+
<a0> [
|
|
102
|
+
<b0> <c0> ;
|
|
103
|
+
] ;
|
|
104
|
+
] ?p0 ?o0 .
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
WHERE {
|
|
109
|
+
?s1 ?p1 _:g_2 .
|
|
110
|
+
?s1 ?p1 <a1> .
|
|
111
|
+
?s1 ?q1 <b1> .
|
|
112
|
+
?s1 ?q1 <c1> .
|
|
113
|
+
_:g_3 ?p2 ?o2 .
|
|
114
|
+
?s3 ?p3 _:g_4 .
|
|
115
|
+
_:g_4 <a3> <b3> .
|
|
116
|
+
?s4 ?p4 _:g_5 .
|
|
117
|
+
_:g_5 <a4> <b4> .
|
|
118
|
+
_:g_5 <c4> <d4> .
|
|
119
|
+
_:g_5 <c4> <e4> .
|
|
120
|
+
?s5 ?p5 _:g_6 .
|
|
121
|
+
_:g_6 <a5> _:g_7 .
|
|
122
|
+
_:g_7 <b5> <c5> .
|
|
123
|
+
[
|
|
124
|
+
<a6> [
|
|
125
|
+
<b6> <c6> ;
|
|
126
|
+
] ;
|
|
127
|
+
] ?p6 ?o6 .
|
|
128
|
+
_:g_10 <a7> <b7> .
|
|
129
|
+
_:g_10 <c7> <d7> .
|
|
130
|
+
_:g_10 <c7> <e7> .
|
|
131
|
+
|
|
132
|
+
}`);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
it('generates hand constructed query', ({ expect }) => {
|
|
136
|
+
const query = `
|
|
137
|
+
SELECT * WHERE {
|
|
138
|
+
?s ?p ?o .
|
|
139
|
+
}`;
|
|
140
|
+
const ast = F.querySelect({
|
|
141
|
+
variables: [F.wildcard(F.gen())],
|
|
142
|
+
datasets: F.datasetClauses([], F.sourceLocation()),
|
|
143
|
+
context: [],
|
|
144
|
+
where: F.patternGroup([
|
|
145
|
+
F.patternBgp([
|
|
146
|
+
F.triple(F.termVariable('s', F.gen()), F.termVariable('p', F.gen()), F.termVariable('o', F.gen())),
|
|
147
|
+
], F.gen()),
|
|
148
|
+
], F.gen()),
|
|
149
|
+
solutionModifiers: {},
|
|
150
|
+
}, F.gen());
|
|
151
|
+
const result = generator.generate(ast);
|
|
152
|
+
expect(result.trim()).toBe(query.trim());
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
//# sourceMappingURL=integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.test.js","sourceRoot":"","sources":["../../../test/integration.test.ts"],"names":[],"mappings":"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","sourcesContent":["import { Parser } from '@traqula/parser-sparql-1-2';\nimport type * as T11 from '@traqula/rules-sparql-1-1';\nimport { AstTransformer } from '@traqula/rules-sparql-1-1';\nimport type * as T12 from '@traqula/rules-sparql-1-2';\nimport { AstFactory } from '@traqula/rules-sparql-1-2';\nimport { describe, it } from 'vitest';\nimport { Generator } from '../lib/index.js';\n\ndescribe('a SPARQL 1.2 generator', () => {\n const generator = new Generator();\n const parser = new Parser();\n const F = new AstFactory();\n const transformer = new AstTransformer();\n\n it ('generates simple round tripped', ({ expect }) => {\n const query = 'SELECT * WHERE { ?s ?p ?o }';\n const ast = <T11.Query> parser.parse(query);\n const result = generator.generate(ast, { origSource: query });\n expect(result).toBe(query);\n });\n\n describe('on altered nodes', () => {\n it('translates ?s -> ?subject', ({ expect }) => {\n const query = 'SELECT * WHERE { ?s ?p ?o }';\n const ast = <T11.Query> parser.parse(query);\n\n const altered = transformer.transformNodeSpecific<'unsafe', T11.Query>(\n ast,\n {},\n { term: { variable: {\n transform: variable => variable.value === 's' ?\n F.termVariable('subject', F.sourceLocationNodeReplaceUnsafe(variable.loc)) :\n variable,\n }}},\n );\n\n const result = generator.generate(altered, { origSource: query });\n expect(result).toBe(`SELECT * WHERE { ?subject ?p ?o }`);\n });\n\n it('translates blanknodes -> variables', ({ expect }) => {\n const query = `BASE <ex:>\nCONSTRUCT { \n ?s0 ?p0 _:g_0 .\n_:g_0 <a0> _:g_1 .\n_:g_1 <b0><c0> .\n[\n <a0> [\n <b0> <c0> ;\n ] ;\n] ?p0 ?o0 .\n\n}\nWHERE {\n ?s1 ?p1 [], <a1>; ?q1 <b1>, <c1>.\n [] ?p2 ?o2.\n ?s3 ?p3 [ <a3> <b3> ].\n ?s4 ?p4 [ <a4> <b4>; <c4> <d4>, <e4> ].\n ?s5 ?p5 [ <a5> [ <b5> <c5> ] ].\n [ <a6> [ <b6> <c6> ] ] ?p6 ?o6.\n [ <a7> <b7>; <c7> <d7>, <e7> ].\n}`;\n const ast = <T12.Query> parser.parse(query);\n\n function extractCollection(collection: T12.TripleCollection): T12.TripleNesting[] {\n const result: T12.TripleNesting[] = [];\n for (const entry of collection.triples) {\n const subject = entry.subject;\n const pred = entry.predicate;\n if (F.isTripleCollection(entry.object)) {\n const identifier = { ...F.graphNodeIdentifier(<T11.GraphNode>entry.object) };\n result.push(F.annotatedTriple(subject, pred, identifier, undefined, F.gen()));\n result.push(...extractCollection(entry.object));\n } else {\n result.push(F.annotatedTriple(\n subject,\n pred,\n entry.object,\n undefined,\n F.gen(),\n ));\n }\n }\n return result;\n }\n const flattenCollections = transformer.transformNodeSpecific<'unsafe', T12.Query>(\n ast,\n {},\n { pattern: { bgp: {\n transform: (current) => {\n const bgpCopy = F.forcedAutoGenTree(current);\n const newTriples: T12.TripleNesting[] = [];\n for (const entry of bgpCopy.triples) {\n if (F.isTriple(entry)) {\n const subject = entry.subject;\n const pred = entry.predicate;\n if (F.isTripleCollection(entry.object)) {\n const object = entry.object;\n const identifier = { ...F.graphNodeIdentifier(<T11.GraphNode>object) };\n newTriples.push(F.annotatedTriple(subject, pred, identifier));\n newTriples.push(...extractCollection(object));\n } else {\n newTriples.push(F.annotatedTriple(\n subject,\n pred,\n entry.object,\n undefined,\n F.gen(),\n ));\n }\n } else {\n const genTriples = extractCollection(entry);\n newTriples.push(...genTriples);\n }\n }\n return F.patternBgp(<T11.BasicGraphPattern> newTriples, F.sourceLocationNodeReplaceUnsafe(current.loc));\n },\n }}},\n );\n\n const result = generator.generate(flattenCollections, { origSource: query });\n expect(result).toBe(`BASE <ex:>\nCONSTRUCT { \n ?s0 ?p0 _:g_0 .\n_:g_0 <a0> _:g_1 .\n_:g_1 <b0> <c0> .\n[\n <a0> [\n <b0> <c0> ;\n ] ;\n] ?p0 ?o0 .\n\n\n}\nWHERE {\n ?s1 ?p1 _:g_2 .\n?s1 ?p1 <a1> .\n?s1 ?q1 <b1> .\n?s1 ?q1 <c1> .\n_:g_3 ?p2 ?o2 .\n?s3 ?p3 _:g_4 .\n_:g_4 <a3> <b3> .\n?s4 ?p4 _:g_5 .\n_:g_5 <a4> <b4> .\n_:g_5 <c4> <d4> .\n_:g_5 <c4> <e4> .\n?s5 ?p5 _:g_6 .\n_:g_6 <a5> _:g_7 .\n_:g_7 <b5> <c5> .\n[\n <a6> [\n <b6> <c6> ;\n ] ;\n] ?p6 ?o6 .\n_:g_10 <a7> <b7> .\n_:g_10 <c7> <d7> .\n_:g_10 <c7> <e7> .\n\n}`);\n });\n });\n\n it ('generates hand constructed query', ({ expect }) => {\n const query = `\nSELECT * WHERE {\n ?s ?p ?o .\n}`;\n const ast = F.querySelect({\n variables: [ F.wildcard(F.gen()) ],\n datasets: F.datasetClauses([], F.sourceLocation()),\n context: [],\n where: F.patternGroup([\n F.patternBgp([\n F.triple(F.termVariable('s', F.gen()), F.termVariable('p', F.gen()), F.termVariable('o', F.gen())),\n ], F.gen()),\n ], F.gen()),\n solutionModifiers: {},\n }, F.gen());\n const result = generator.generate(ast);\n expect(result.trim()).toBe(query.trim());\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|