@manta-eu/datalog-parser 0.1.2 → 0.1.4
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/index.js +1415 -1440
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
function
|
|
16
|
-
return $r.test(e);
|
|
17
|
-
}
|
|
18
|
-
function We(e) {
|
|
1
|
+
import { match as p, P as l } from "ts-pattern";
|
|
2
|
+
import Ce from "decimal.js";
|
|
3
|
+
import { GeneratorBuilder as Rr, ParserBuilder as F } from "@traqula/core";
|
|
4
|
+
import { sparql11GeneratorBuilder as It } from "@traqula/generator-sparql-1-1";
|
|
5
|
+
import { AstFactory as br, lex as Qe, completeGeneratorContext as Or, gram as n, MinimalSparqlParser as xr, sparqlCodepointEscape as vr } from "@traqula/rules-sparql-1-1";
|
|
6
|
+
import { createToken as c, Lexer as Mt, CstParser as Cr, EOF as Ir } from "chevrotain";
|
|
7
|
+
import { z as j } from "zod";
|
|
8
|
+
const xn = (e) => p(e).with({ type: "triple" }, () => !0).otherwise(() => !1), vn = (e) => p(e).with({ type: "property" }, () => !0).otherwise(() => !1), Cn = (e) => p(e).with({ type: "class" }, () => !0).otherwise(() => !1), In = (e) => p(e).with({ type: "general" }, () => !0).otherwise(() => !1), v = (e) => p(e).with({ type: "variable" }, () => !0).otherwise(() => !1), Mn = (e) => p(e).with({ type: "iri" }, () => !0).otherwise(() => !1), Z = (e) => p(e).with({ type: "literal" }, () => !0).otherwise(() => !1), Bn = (e) => p(e).with({ type: "blank" }, () => !0).otherwise(() => !1), Fn = (e) => p(e).with({ type: "negation" }, () => !0).otherwise(() => !1), Pn = (e) => p(e).with({ type: "filter" }, () => !0).otherwise(() => !1), kn = (e) => p(e).with({ type: "bind" }, () => !0).otherwise(() => !1), $n = (e) => p(e).with({ type: "aggregate" }, () => !0).otherwise(() => !1), Dn = (e) => p(e).with({ type: "skolem" }, () => !0).otherwise(() => !1), Gn = (e) => p(e).with({ type: "binary" }, () => !0).otherwise(() => !1), _n = (e) => p(e).with({ type: "unary" }, () => !0).otherwise(() => !1), Vn = (e) => p(e).with({ type: "term" }, () => !0).otherwise(() => !1), jn = (e) => p(e).with({ type: "function" }, () => !0).otherwise(() => !1), qn = (e) => p(e).with({ type: "triple" }, () => "triple").with({ type: "property" }, () => "property").with({ type: "class" }, () => "class").with({ type: "general" }, () => "general").exhaustive(), Xn = (e) => p(e).with({ type: "variable" }, () => "variable").with({ type: "iri" }, () => "iri").with({ type: "literal" }, () => "literal").with({ type: "blank" }, () => "blank").exhaustive(), Hn = (e) => p(e).with({ type: "binary" }, () => "binary").with({ type: "unary" }, () => "unary").with({ type: "term" }, () => "term").with({ type: "function" }, () => "function").with({ type: "in" }, () => "in").exhaustive(), Mr = (e) => p(e).with({ type: "triple" }, (t) => [t.subject, t.predicate, t.object].filter(v)).with({ type: "property" }, (t) => [t.subject, t.object].filter(v)).with({ type: "class" }, (t) => [t.instance].filter(v)).with({ type: "general" }, (t) => t.terms.filter(v)).exhaustive(), Br = (e) => {
|
|
9
|
+
const t = Mr(e), r = "graph" in e ? e.graph : void 0;
|
|
10
|
+
return r && v(r) ? [...t, r] : t;
|
|
11
|
+
}, Qn = (e) => e.function, zn = (e) => p(e).with(l.union("+", "-", "*", "/", "<", ">", "<=", ">="), () => !0).with(l.union("=", "!=", "||", "&&"), () => !1).exhaustive(), Kn = (e) => p(e).with(l.union("||", "&&", "=", "!=", "<", ">", "<=", ">="), () => !0).with(l.union("+", "-", "*", "/"), () => !1).exhaustive(), ze = '[^\\s<>"{}|^`\\\\]', Fr = new RegExp(`^[a-z][a-z0-9+.-]*:${ze}*$`, "i");
|
|
12
|
+
function Wn(e) {
|
|
13
|
+
return Fr.test(e);
|
|
14
|
+
}
|
|
15
|
+
function Ke(e) {
|
|
19
16
|
return e.includes("://");
|
|
20
17
|
}
|
|
21
|
-
const
|
|
22
|
-
`^[+-]?(?:\\d+\\.\\d*(?:${
|
|
18
|
+
const Pr = /^(true|false)$/i, kr = /^"(true|false)"\^\^<?\S*boolean>?$/i, Tt = "[eE][+-]?\\d+", $r = new RegExp(
|
|
19
|
+
`^[+-]?(?:\\d+\\.\\d*(?:${Tt})|\\d+\\.\\d+|\\.\\d+(?:${Tt})?|\\d+(?:${Tt})?)$`
|
|
23
20
|
);
|
|
24
|
-
function
|
|
25
|
-
return
|
|
21
|
+
function Nt(e) {
|
|
22
|
+
return $r.test(e);
|
|
26
23
|
}
|
|
27
|
-
const
|
|
28
|
-
function
|
|
24
|
+
const Dr = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/, Gr = 21;
|
|
25
|
+
function _r(e, t) {
|
|
29
26
|
return t <= 0 ? { integer: "0", fraction: "0".repeat(-t) + e } : t >= e.length ? { integer: e + "0".repeat(t - e.length), fraction: "" } : { integer: e.slice(0, t), fraction: e.slice(t) };
|
|
30
27
|
}
|
|
31
|
-
function
|
|
32
|
-
const t =
|
|
28
|
+
function Vr(e) {
|
|
29
|
+
const t = Nt(e) ? e.match(Dr) : null;
|
|
33
30
|
if (!t) return e;
|
|
34
|
-
const [, r = "", i = "", s = "",
|
|
35
|
-
if (
|
|
36
|
-
const
|
|
31
|
+
const [, r = "", i = "", s = "", o] = t, a = i + s, u = i.length + Number(o ?? 0);
|
|
32
|
+
if (a.length + Math.abs(u) > Gr) return e;
|
|
33
|
+
const f = _r(a, u), y = f.integer.replace(/^0+(?=\d)/, ""), m = f.fraction.replace(/0+$/, ""), h = m ? `${y}.${m}` : y;
|
|
37
34
|
return h === "0" || r === "+" ? h : `${r}${h}`;
|
|
38
35
|
}
|
|
39
|
-
function
|
|
40
|
-
if (
|
|
41
|
-
const t = e.match(
|
|
42
|
-
if (t
|
|
36
|
+
function Yn(e) {
|
|
37
|
+
if (Pr.test(e)) return e.toLowerCase() === "true";
|
|
38
|
+
const t = e.match(kr);
|
|
39
|
+
if (t?.[1]) return t[1].toLowerCase() === "true";
|
|
43
40
|
}
|
|
44
|
-
const
|
|
41
|
+
const Rt = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", bt = "http://www.w3.org/2001/XMLSchema#", V = {
|
|
45
42
|
integer: "xsd:integer",
|
|
46
43
|
decimal: "xsd:decimal",
|
|
47
44
|
double: "xsd:double",
|
|
@@ -49,7 +46,7 @@ const bt = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", Ot = "http://www.w
|
|
|
49
46
|
string: "xsd:string",
|
|
50
47
|
date: "xsd:date",
|
|
51
48
|
dateTime: "xsd:dateTime"
|
|
52
|
-
},
|
|
49
|
+
}, jr = ["integer", "decimal", "double"], Ie = {
|
|
53
50
|
"||": 1,
|
|
54
51
|
"&&": 2,
|
|
55
52
|
"=": 3,
|
|
@@ -62,7 +59,7 @@ const bt = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", Ot = "http://www.w
|
|
|
62
59
|
"-": 4,
|
|
63
60
|
"*": 5,
|
|
64
61
|
"/": 5
|
|
65
|
-
},
|
|
62
|
+
}, Bt = {
|
|
66
63
|
"=": "=",
|
|
67
64
|
"!=": "!=",
|
|
68
65
|
"<": ">",
|
|
@@ -70,30 +67,30 @@ const bt = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", Ot = "http://www.w
|
|
|
70
67
|
">": "<",
|
|
71
68
|
">=": "<="
|
|
72
69
|
};
|
|
73
|
-
function
|
|
74
|
-
return p(e).with({ type:
|
|
70
|
+
function Me(e) {
|
|
71
|
+
return p(e).with({ type: l.union("triple", "property", "class", "general") }, () => !0).otherwise(() => !1);
|
|
75
72
|
}
|
|
76
|
-
function
|
|
77
|
-
return p(e).with({ type: "binary" }, ({ left: t, right: r }) =>
|
|
73
|
+
function M(e) {
|
|
74
|
+
return p(e).with({ type: "binary" }, ({ left: t, right: r }) => M(t) || M(r)).with({ type: "unary" }, ({ operand: t }) => M(t)).with({ type: "term" }, () => !1).with(
|
|
78
75
|
{ type: "function" },
|
|
79
|
-
({ name: t, args: r }) => t.toUpperCase() === "SKOLEM" || r.some(
|
|
76
|
+
({ name: t, args: r }) => t.toUpperCase() === "SKOLEM" || r.some(M)
|
|
80
77
|
).with(
|
|
81
78
|
{ type: "in" },
|
|
82
|
-
({ expression: t, list: r }) =>
|
|
79
|
+
({ expression: t, list: r }) => M(t) || r.some(M)
|
|
83
80
|
).exhaustive();
|
|
84
81
|
}
|
|
85
|
-
function
|
|
86
|
-
return p(e).with({ type: "skolem" }, () => !0).with({ type:
|
|
82
|
+
function Ot(e) {
|
|
83
|
+
return p(e).with({ type: "skolem" }, () => !0).with({ type: l.union("filter", "bind") }, ({ expression: t }) => M(t)).with({ type: "negation" }, ({ formulas: t }) => t.some(Ot)).with(
|
|
87
84
|
{ type: "aggregate" },
|
|
88
|
-
({ atoms: t, bindings: r }) => t.some(
|
|
89
|
-
({ expression: i, secondExpression: s }) => i !== "*" &&
|
|
90
|
-
)
|
|
91
|
-
).with({ type:
|
|
85
|
+
({ atoms: t, bindings: r }) => t.some(Ot) || (r?.some(
|
|
86
|
+
({ expression: i, secondExpression: s }) => i !== "*" && M(i) || s !== void 0 && M(s)
|
|
87
|
+
) ?? !1)
|
|
88
|
+
).with({ type: l.union("triple", "property", "class", "general") }, () => !1).exhaustive();
|
|
92
89
|
}
|
|
93
|
-
function
|
|
94
|
-
return e.some((t) => t.type !== "negation" &&
|
|
90
|
+
function We(e) {
|
|
91
|
+
return e.some((t) => t.type !== "negation" && Ot(t));
|
|
95
92
|
}
|
|
96
|
-
function
|
|
93
|
+
function Ye(e) {
|
|
97
94
|
return p(e).with({ type: "class" }, (t) => ({
|
|
98
95
|
className: t.className,
|
|
99
96
|
instance: t.instance,
|
|
@@ -101,7 +98,7 @@ function Ze(e) {
|
|
|
101
98
|
})).with(
|
|
102
99
|
{
|
|
103
100
|
type: "property",
|
|
104
|
-
predicate:
|
|
101
|
+
predicate: l.union("a", "rdf:type", Rt),
|
|
105
102
|
object: { type: "iri" }
|
|
106
103
|
},
|
|
107
104
|
(t) => ({
|
|
@@ -112,7 +109,7 @@ function Ze(e) {
|
|
|
112
109
|
).with(
|
|
113
110
|
{
|
|
114
111
|
type: "triple",
|
|
115
|
-
predicate: { type: "iri", value:
|
|
112
|
+
predicate: { type: "iri", value: l.union("a", "rdf:type", Rt) },
|
|
116
113
|
object: { type: "iri" }
|
|
117
114
|
},
|
|
118
115
|
(t) => ({
|
|
@@ -122,14 +119,14 @@ function Ze(e) {
|
|
|
122
119
|
})
|
|
123
120
|
).otherwise(() => null);
|
|
124
121
|
}
|
|
125
|
-
function
|
|
122
|
+
function Ze(e) {
|
|
126
123
|
return p(e).with({ type: "property" }, (t) => ({
|
|
127
124
|
predicate: t.predicate,
|
|
128
125
|
subject: t.subject,
|
|
129
126
|
object: t.object,
|
|
130
127
|
graph: t.graph
|
|
131
128
|
})).with(
|
|
132
|
-
{ type: "triple", predicate: { type: "iri", value:
|
|
129
|
+
{ type: "triple", predicate: { type: "iri", value: l.not(l.union("a", "rdf:type", Rt)) } },
|
|
133
130
|
(t) => ({
|
|
134
131
|
predicate: t.predicate.value,
|
|
135
132
|
subject: t.subject,
|
|
@@ -138,320 +135,318 @@ function Je(e) {
|
|
|
138
135
|
})
|
|
139
136
|
).otherwise(() => null);
|
|
140
137
|
}
|
|
141
|
-
function
|
|
142
|
-
return e in
|
|
138
|
+
function Zn(e) {
|
|
139
|
+
return e in Bt;
|
|
143
140
|
}
|
|
144
|
-
function
|
|
145
|
-
return
|
|
141
|
+
function Jn(e) {
|
|
142
|
+
return Bt[e];
|
|
146
143
|
}
|
|
147
|
-
function
|
|
148
|
-
return e ===
|
|
144
|
+
function et(e, t) {
|
|
145
|
+
return e === V[t] || e === `${bt}${t}`;
|
|
149
146
|
}
|
|
150
|
-
function
|
|
147
|
+
function Be(e) {
|
|
151
148
|
const { datatype: t } = e;
|
|
152
|
-
if (!(!t ||
|
|
153
|
-
return t.startsWith(
|
|
149
|
+
if (!(!t || et(t, "string")))
|
|
150
|
+
return t.startsWith(bt) ? `xsd:${t.slice(bt.length)}` : t;
|
|
154
151
|
}
|
|
155
|
-
function
|
|
156
|
-
return p([e, t]).with([{ type: "literal" }, { type: "literal" }], ([r, i]) =>
|
|
152
|
+
function Je(e, t) {
|
|
153
|
+
return p([e, t]).with([{ type: "literal" }, { type: "literal" }], ([r, i]) => H(r) && H(i) && Nt(r.value) && Nt(i.value) ? new Ce(r.value).equals(new Ce(i.value)) : r.value === i.value && r.language === i.language && Be(r) === Be(i)).with([{ type: "iri" }, { type: "iri" }], ([r, i]) => r.value === i.value).with([{ type: "blank" }, { type: "blank" }], ([r, i]) => r.label === i.label).with([{ type: "variable" }, { type: "variable" }], ([r, i]) => r.name === i.name).otherwise(() => !1);
|
|
157
154
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
155
|
+
function H(e) {
|
|
156
|
+
return jr.some((t) => et(e.datatype, t));
|
|
160
157
|
}
|
|
161
|
-
function
|
|
162
|
-
return !
|
|
158
|
+
function ts(e) {
|
|
159
|
+
return !H(e) || !e.termSpan || !e.valueSpan ? !1 : e.termSpan.start === e.valueSpan.start && e.termSpan.end === e.valueSpan.end;
|
|
163
160
|
}
|
|
164
|
-
function
|
|
165
|
-
return
|
|
161
|
+
function es(e) {
|
|
162
|
+
return Z(e) && H(e);
|
|
166
163
|
}
|
|
167
|
-
function
|
|
168
|
-
return
|
|
164
|
+
function tr(e) {
|
|
165
|
+
return et(e.datatype, "boolean");
|
|
169
166
|
}
|
|
170
|
-
function
|
|
171
|
-
return
|
|
167
|
+
function qr(e) {
|
|
168
|
+
return et(e.datatype, "date");
|
|
172
169
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
170
|
+
function Xr(e) {
|
|
171
|
+
return et(e.datatype, "dateTime");
|
|
175
172
|
}
|
|
176
|
-
function
|
|
177
|
-
return
|
|
173
|
+
function rs(e) {
|
|
174
|
+
return H(e) ? Vr(e.value) : tr(e) || qr(e) ? e.value : Xr(e) ? e.value.replace("T", " ") : JSON.stringify(e.value);
|
|
178
175
|
}
|
|
179
|
-
function
|
|
180
|
-
return
|
|
176
|
+
function is(e) {
|
|
177
|
+
return Hr(e.expression);
|
|
181
178
|
}
|
|
182
|
-
function
|
|
179
|
+
function Hr(e) {
|
|
183
180
|
return p(e).with(
|
|
184
|
-
{ type: "binary", operator:
|
|
181
|
+
{ type: "binary", operator: l.union("=", "!=", "<", ">", "<=", ">=") },
|
|
185
182
|
(t) => {
|
|
186
|
-
const r =
|
|
187
|
-
return !r || !i ? null :
|
|
183
|
+
const r = D(t.left), i = D(t.right);
|
|
184
|
+
return !r || !i ? null : v(r) && Z(i) ? { variableName: r.name, operator: t.operator, literal: i } : Z(r) && v(i) ? {
|
|
188
185
|
variableName: i.name,
|
|
189
|
-
operator:
|
|
186
|
+
operator: Bt[t.operator],
|
|
190
187
|
literal: r
|
|
191
188
|
} : null;
|
|
192
189
|
}
|
|
193
190
|
).otherwise(() => null);
|
|
194
191
|
}
|
|
195
|
-
function
|
|
192
|
+
function Qr(e) {
|
|
196
193
|
return p(e).returnType().with(
|
|
197
194
|
{ type: "binary", operator: "=" },
|
|
198
|
-
(t) => p([
|
|
195
|
+
(t) => p([D(t.left), D(t.right)]).returnType().with([l.not(l.nullish), { type: "literal" }], ([r, i]) => ({ subject: r, literal: i })).with([{ type: "literal" }, l.not(l.nullish)], ([r, i]) => ({ subject: i, literal: r })).otherwise(() => null)
|
|
199
196
|
).otherwise(() => null);
|
|
200
197
|
}
|
|
201
|
-
function
|
|
202
|
-
var s;
|
|
198
|
+
function ns(e) {
|
|
203
199
|
if (e.type === "in") {
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
return
|
|
200
|
+
const s = D(e.expression), o = e.list.flatMap((a) => {
|
|
201
|
+
const u = Yr(a);
|
|
202
|
+
return u ? [u] : [];
|
|
207
203
|
});
|
|
208
|
-
return
|
|
204
|
+
return s && o.length > 0 && o.length === e.list.length ? { subject: s, literals: o, negated: e.negated } : null;
|
|
209
205
|
}
|
|
210
|
-
const t =
|
|
206
|
+
const t = xt(e, "||");
|
|
211
207
|
if (t.length < 2) return null;
|
|
212
|
-
const r = t.flatMap((
|
|
213
|
-
const o =
|
|
208
|
+
const r = t.flatMap((s) => {
|
|
209
|
+
const o = Qr(s);
|
|
214
210
|
return o ? [o] : [];
|
|
215
211
|
});
|
|
216
212
|
if (r.length !== t.length) return null;
|
|
217
|
-
const i =
|
|
218
|
-
return !i || !r.every((
|
|
213
|
+
const i = r[0]?.subject;
|
|
214
|
+
return !i || !r.every((s) => Je(s.subject, i)) ? null : {
|
|
219
215
|
subject: i,
|
|
220
|
-
literals: r.map((
|
|
216
|
+
literals: r.map((s) => s.literal),
|
|
221
217
|
negated: !1
|
|
222
218
|
};
|
|
223
219
|
}
|
|
224
|
-
function
|
|
225
|
-
const t =
|
|
226
|
-
return t &&
|
|
220
|
+
function zr(e) {
|
|
221
|
+
const t = D(e);
|
|
222
|
+
return t && v(t) ? t.name : null;
|
|
227
223
|
}
|
|
228
|
-
function
|
|
224
|
+
function Kr(e) {
|
|
229
225
|
return p(e).with({ type: "skolem" }, (t) => {
|
|
230
226
|
const r = t.args.at(-1);
|
|
231
|
-
return r ?
|
|
227
|
+
return r ? zr(r) : null;
|
|
232
228
|
}).with({ type: "bind", expression: { type: "function", name: "SKOLEM" } }, (t) => t.variable).otherwise(() => null);
|
|
233
229
|
}
|
|
234
|
-
function
|
|
235
|
-
const t = /* @__PURE__ */ new Set(), r = (
|
|
236
|
-
|
|
237
|
-
}, i = (
|
|
238
|
-
|
|
239
|
-
}, s = (
|
|
240
|
-
p(
|
|
241
|
-
r(
|
|
242
|
-
}).with({ type: "aggregate" }, (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
t.add(y.variable), y.expression !== "*" && r(y.expression), y.secondExpression && r(y.secondExpression);
|
|
230
|
+
function ss(e) {
|
|
231
|
+
const t = /* @__PURE__ */ new Set(), r = (o) => {
|
|
232
|
+
w(o).forEach((a) => t.add(a));
|
|
233
|
+
}, i = (o) => {
|
|
234
|
+
rt(o).forEach((a) => t.add(a));
|
|
235
|
+
}, s = (o) => {
|
|
236
|
+
p(o).with({ type: l.union("triple", "property", "class", "general") }, i).with({ type: "negation" }, (a) => a.formulas.forEach(s)).with({ type: "filter" }, (a) => r(a.expression)).with({ type: "bind" }, (a) => {
|
|
237
|
+
r(a.expression), t.add(a.variable);
|
|
238
|
+
}).with({ type: "aggregate" }, (a) => {
|
|
239
|
+
a.atoms.forEach(s), a.onVars?.forEach((u) => t.add(u)), a.bindings?.forEach((u) => {
|
|
240
|
+
t.add(u.variable), u.expression !== "*" && r(u.expression), u.secondExpression && r(u.secondExpression);
|
|
246
241
|
});
|
|
247
|
-
}).with({ type: "skolem" }, (
|
|
242
|
+
}).with({ type: "skolem" }, (a) => a.args.forEach(r)).exhaustive();
|
|
248
243
|
};
|
|
249
244
|
return e.head.forEach(i), e.body.forEach(s), Array.from(t);
|
|
250
245
|
}
|
|
251
|
-
function
|
|
252
|
-
const r = /* @__PURE__ */ new Set(), i = (
|
|
253
|
-
|
|
254
|
-
}, s = (
|
|
255
|
-
i(
|
|
256
|
-
},
|
|
257
|
-
p(
|
|
246
|
+
function as(e, t) {
|
|
247
|
+
const r = /* @__PURE__ */ new Set(), i = (a) => {
|
|
248
|
+
a.includes(t) && a.forEach((u) => r.add(u));
|
|
249
|
+
}, s = (a) => {
|
|
250
|
+
i(rt(a));
|
|
251
|
+
}, o = (a) => {
|
|
252
|
+
p(a).with({ type: l.union("triple", "property", "class", "general") }, s).with({ type: "negation" }, (u) => u.formulas.forEach(o)).with({ type: "filter" }, (u) => i(w(u.expression))).with(
|
|
258
253
|
{ type: "bind" },
|
|
259
|
-
(
|
|
260
|
-
).with({ type: "aggregate" }, (
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
...
|
|
264
|
-
...(
|
|
254
|
+
(u) => i([...w(u.expression), u.variable])
|
|
255
|
+
).with({ type: "aggregate" }, (u) => {
|
|
256
|
+
u.atoms.forEach(o);
|
|
257
|
+
const f = [
|
|
258
|
+
...u.onVars ?? [],
|
|
259
|
+
...(u.bindings ?? []).flatMap((y) => [
|
|
265
260
|
y.variable,
|
|
266
|
-
...y.expression === "*" ? [] :
|
|
267
|
-
...y.secondExpression ?
|
|
261
|
+
...y.expression === "*" ? [] : w(y.expression),
|
|
262
|
+
...y.secondExpression ? w(y.secondExpression) : []
|
|
268
263
|
])
|
|
269
264
|
];
|
|
270
|
-
i(
|
|
265
|
+
i(f);
|
|
271
266
|
}).with(
|
|
272
267
|
{ type: "skolem" },
|
|
273
|
-
(
|
|
268
|
+
(u) => i(u.args.flatMap((f) => w(f)))
|
|
274
269
|
).exhaustive();
|
|
275
270
|
};
|
|
276
|
-
return e.head.forEach(s), e.body.forEach(
|
|
271
|
+
return e.head.forEach(s), e.body.forEach(o), r;
|
|
277
272
|
}
|
|
278
|
-
function
|
|
279
|
-
return
|
|
273
|
+
function rt(e) {
|
|
274
|
+
return Br(e).map((t) => t.name);
|
|
280
275
|
}
|
|
281
|
-
function
|
|
282
|
-
return e &&
|
|
276
|
+
function Wr(e) {
|
|
277
|
+
return e && v(e) ? [e.name] : [];
|
|
283
278
|
}
|
|
284
|
-
function
|
|
279
|
+
function w(e) {
|
|
285
280
|
return p(e).with({ type: "binary" }, (t) => [
|
|
286
|
-
...
|
|
287
|
-
...
|
|
288
|
-
]).with({ type: "unary" }, (t) =>
|
|
289
|
-
...
|
|
290
|
-
...t.list.flatMap(
|
|
281
|
+
...w(t.left),
|
|
282
|
+
...w(t.right)
|
|
283
|
+
]).with({ type: "unary" }, (t) => w(t.operand)).with({ type: "term" }, (t) => Wr(t.term)).with({ type: "function" }, (t) => t.args.flatMap(w)).with({ type: "in" }, (t) => [
|
|
284
|
+
...w(t.expression),
|
|
285
|
+
...t.list.flatMap(w)
|
|
291
286
|
]).exhaustive();
|
|
292
287
|
}
|
|
293
|
-
function
|
|
294
|
-
const t =
|
|
295
|
-
return t &&
|
|
288
|
+
function Yr(e) {
|
|
289
|
+
const t = D(e);
|
|
290
|
+
return t && Z(t) ? t : null;
|
|
296
291
|
}
|
|
297
|
-
function
|
|
292
|
+
function xt(e, t) {
|
|
298
293
|
return e.type !== "binary" || e.operator !== t ? [e] : [
|
|
299
|
-
...
|
|
300
|
-
...
|
|
294
|
+
...xt(e.left, t),
|
|
295
|
+
...xt(e.right, t)
|
|
301
296
|
];
|
|
302
297
|
}
|
|
303
|
-
function
|
|
304
|
-
return
|
|
298
|
+
function er(e) {
|
|
299
|
+
return Ke(e) ? `<${e}>` : e;
|
|
305
300
|
}
|
|
306
|
-
function
|
|
301
|
+
function b(e, t = {}) {
|
|
307
302
|
return p(e).with({ type: "variable" }, (r) => `?${r.name}`).with({ type: "iri" }, (r) => r.prefixed ? r.value : `<${r.value}>`).with({ type: "literal" }, (r) => {
|
|
308
|
-
const i = t.stripSimpleLiteralDatatypes &&
|
|
309
|
-
return r.language ? `${i}@${r.language}` : r.datatype ? t.stripSimpleLiteralDatatypes &&
|
|
303
|
+
const i = t.stripSimpleLiteralDatatypes && Fe(r) ? r.value : JSON.stringify(r.value);
|
|
304
|
+
return r.language ? `${i}@${r.language}` : r.datatype ? t.stripSimpleLiteralDatatypes && Fe(r) ? i : `${i}^^${er(r.datatype)}` : i;
|
|
310
305
|
}).with({ type: "blank" }, (r) => `_:${r.label}`).exhaustive();
|
|
311
306
|
}
|
|
312
|
-
function
|
|
313
|
-
const r = "graph" in e && e.graph ? ` ${
|
|
307
|
+
function os(e, t = {}) {
|
|
308
|
+
const r = "graph" in e && e.graph ? ` ${b(e.graph, t)}` : "";
|
|
314
309
|
return p(e).with(
|
|
315
310
|
{ type: "property" },
|
|
316
|
-
(i) => `${i.predicate}[${
|
|
311
|
+
(i) => `${i.predicate}[${b(i.subject, t)}, ${b(i.object, t)}]${r}`
|
|
317
312
|
).with(
|
|
318
313
|
{ type: "triple" },
|
|
319
|
-
(i) => `[${
|
|
314
|
+
(i) => `[${b(i.subject, t)}, ${b(i.predicate, t)}, ${b(i.object, t)}]${r}`
|
|
320
315
|
).with(
|
|
321
316
|
{ type: "class" },
|
|
322
|
-
(i) => `${i.className}[${
|
|
317
|
+
(i) => `${i.className}[${b(i.instance, t)}]${r}`
|
|
323
318
|
).with(
|
|
324
319
|
{ type: "general" },
|
|
325
|
-
(i) => `${i.tableName}(${i.terms.map((s) =>
|
|
320
|
+
(i) => `${i.tableName}(${i.terms.map((s) => b(s, t)).join(", ")})`
|
|
326
321
|
).exhaustive();
|
|
327
322
|
}
|
|
328
|
-
function
|
|
329
|
-
return
|
|
323
|
+
function Fe(e) {
|
|
324
|
+
return H(e) || tr(e);
|
|
330
325
|
}
|
|
331
|
-
function
|
|
332
|
-
return
|
|
326
|
+
function ls(e, t = {}) {
|
|
327
|
+
return ri(X(e, t));
|
|
333
328
|
}
|
|
334
|
-
function
|
|
329
|
+
function X(e, t = {}) {
|
|
335
330
|
return p(e).with({ type: "binary" }, (r) => [
|
|
336
|
-
...
|
|
337
|
-
|
|
338
|
-
...
|
|
339
|
-
]).with({ type: "unary" }, (r) => [
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
r.args.map((i) =>
|
|
331
|
+
...Pe(r.left, r.operator, "left", t),
|
|
332
|
+
x(` ${r.operator} `),
|
|
333
|
+
...Pe(r.right, r.operator, "right", t)
|
|
334
|
+
]).with({ type: "unary" }, (r) => [x(r.operator), ...ti(r.operand, t)]).with({ type: "term" }, (r) => ei(r.term, t)).with({ type: "function" }, (r) => [
|
|
335
|
+
x(`${r.name}(`),
|
|
336
|
+
...ke(
|
|
337
|
+
r.args.map((i) => X(i, t)),
|
|
343
338
|
", "
|
|
344
339
|
),
|
|
345
|
-
|
|
340
|
+
x(")")
|
|
346
341
|
]).with({ type: "in" }, (r) => [
|
|
347
|
-
...
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
r.list.map((i) =>
|
|
342
|
+
...X(r.expression, t),
|
|
343
|
+
x(` ${r.negated ? "NOT IN" : "IN"} (`),
|
|
344
|
+
...ke(
|
|
345
|
+
r.list.map((i) => X(i, t)),
|
|
351
346
|
", "
|
|
352
347
|
),
|
|
353
|
-
|
|
348
|
+
x(")")
|
|
354
349
|
]).exhaustive();
|
|
355
350
|
}
|
|
356
|
-
function
|
|
351
|
+
function Zr(e, t, r) {
|
|
357
352
|
if (e.type !== "binary") return !1;
|
|
358
|
-
const i =
|
|
353
|
+
const i = Ie[e.operator], s = Ie[t];
|
|
359
354
|
return i < s || r === "right" && i === s && (t === "-" || t === "/");
|
|
360
355
|
}
|
|
361
|
-
function
|
|
356
|
+
function Jr(e) {
|
|
362
357
|
return e.type === "binary" || e.type === "in";
|
|
363
358
|
}
|
|
364
|
-
function
|
|
365
|
-
const s =
|
|
366
|
-
return
|
|
359
|
+
function Pe(e, t, r, i) {
|
|
360
|
+
const s = X(e, i);
|
|
361
|
+
return Zr(e, t, r) ? rr(s) : s;
|
|
367
362
|
}
|
|
368
|
-
function
|
|
369
|
-
const r =
|
|
370
|
-
return
|
|
363
|
+
function ti(e, t) {
|
|
364
|
+
const r = X(e, t);
|
|
365
|
+
return Jr(e) ? rr(r) : r;
|
|
371
366
|
}
|
|
372
|
-
function
|
|
373
|
-
return
|
|
367
|
+
function ei(e, t) {
|
|
368
|
+
return v(e) ? [ii(e.name)] : Z(e) ? [ni(e, t)] : [x(b(e, t))];
|
|
374
369
|
}
|
|
375
|
-
function
|
|
376
|
-
return [
|
|
370
|
+
function rr(e) {
|
|
371
|
+
return [x("("), ...e, x(")")];
|
|
377
372
|
}
|
|
378
|
-
function
|
|
379
|
-
return e.flatMap((r, i) => i === 0 ? r : [
|
|
373
|
+
function ke(e, t) {
|
|
374
|
+
return e.flatMap((r, i) => i === 0 ? r : [x(t), ...r]);
|
|
380
375
|
}
|
|
381
|
-
function
|
|
376
|
+
function ri(e) {
|
|
382
377
|
return e.map((t) => t.type === "variable" ? `?${t.name}` : t.text).join("");
|
|
383
378
|
}
|
|
384
|
-
function
|
|
379
|
+
function x(e) {
|
|
385
380
|
return { type: "text", text: e };
|
|
386
381
|
}
|
|
387
|
-
function
|
|
382
|
+
function ii(e) {
|
|
388
383
|
return { type: "variable", name: e };
|
|
389
384
|
}
|
|
390
|
-
function
|
|
391
|
-
return { type: "literal", literal: e, text:
|
|
385
|
+
function ni(e, t) {
|
|
386
|
+
return { type: "literal", literal: e, text: b(e, t) };
|
|
392
387
|
}
|
|
393
|
-
function
|
|
388
|
+
function D(e) {
|
|
394
389
|
return e.type === "term" ? e.term : null;
|
|
395
390
|
}
|
|
396
|
-
const
|
|
397
|
-
function
|
|
398
|
-
if (e.some(
|
|
391
|
+
const si = "Cannot translate grounded Datalog rules to SPARQL.";
|
|
392
|
+
function ir(e) {
|
|
393
|
+
if (e.some(vt)) throw new Error(si);
|
|
399
394
|
}
|
|
400
|
-
function
|
|
395
|
+
function vt(e) {
|
|
401
396
|
return p(e).with({ type: "bind" }, ({ groundedTarget: t }) => t !== void 0).with(
|
|
402
397
|
{ type: "aggregate" },
|
|
403
|
-
({ groundedOnTargets: t, bindings: r, atoms: i }) => t !== void 0 || (
|
|
404
|
-
).with({ type: "negation" }, ({ formulas: t }) => t.some(
|
|
398
|
+
({ groundedOnTargets: t, bindings: r, atoms: i }) => t !== void 0 || (r?.some((s) => s.groundedTarget !== void 0) ?? !1) || i.some(vt)
|
|
399
|
+
).with({ type: "negation" }, ({ formulas: t }) => t.some(vt)).with({ type: l.union("triple", "property", "class", "general", "filter", "skolem") }, () => !1).exhaustive();
|
|
405
400
|
}
|
|
406
|
-
const
|
|
407
|
-
|
|
401
|
+
const E = new br(), g = E.gen(), $e = It.getRule("aggregate"), De = It.getRule("expression"), ai = {
|
|
402
|
+
...$e,
|
|
408
403
|
gImpl: (e) => (t, r) => {
|
|
409
404
|
const i = t.secondExpression;
|
|
410
405
|
if (!i)
|
|
411
|
-
return
|
|
412
|
-
const { PRINT_WORD: s, SUBRULE:
|
|
413
|
-
if (
|
|
406
|
+
return $e.gImpl(e)(t, r);
|
|
407
|
+
const { PRINT_WORD: s, SUBRULE: o } = e, a = t.expression[0], u = r.astFactory;
|
|
408
|
+
if (u.isWildcard(a))
|
|
414
409
|
throw new Error(`Aggregate ${t.aggregation.toUpperCase()} cannot combine * with a second expression.`);
|
|
415
|
-
|
|
410
|
+
u.printFilter(t, () => {
|
|
416
411
|
s(t.aggregation.toUpperCase(), "("), t.distinct && s("DISTINCT");
|
|
417
|
-
}),
|
|
412
|
+
}), o(De, a), u.printFilter(t, () => s(",")), o(De, i), u.printFilter(t, () => s(")"));
|
|
418
413
|
}
|
|
419
|
-
},
|
|
420
|
-
Object.entries(
|
|
414
|
+
}, oi = Rr.create(It).patchRule(ai).build(), li = /* @__PURE__ */ new Set(["MIN_ARGMIN", "MAX_ARGMIN", "MIN_ARGMAX", "MAX_ARGMAX"]), ui = new Map(
|
|
415
|
+
Object.entries(Qe.builtIn).filter(([e]) => e !== "BuiltInCalls" && e !== "allBuiltInCalls").filter(([, e]) => e && typeof e == "object" && "LABEL" in e).map(([, e]) => {
|
|
421
416
|
const t = e;
|
|
422
417
|
return [t.LABEL.toLowerCase(), t.LABEL];
|
|
423
418
|
})
|
|
424
419
|
);
|
|
425
|
-
function
|
|
420
|
+
function $(e) {
|
|
426
421
|
if (e.includes("://") || e.startsWith("urn:") || e.startsWith("mailto:") || e.startsWith("tel:") || e.startsWith("data:"))
|
|
427
|
-
return
|
|
422
|
+
return E.termNamed(g, e);
|
|
428
423
|
const r = e.indexOf(":");
|
|
429
|
-
return r >= 0 ?
|
|
424
|
+
return r >= 0 ? E.termNamed(g, e.slice(r + 1), e.slice(0, r)) : E.termNamed(g, e);
|
|
430
425
|
}
|
|
431
|
-
function
|
|
432
|
-
return
|
|
426
|
+
function st(e, t) {
|
|
427
|
+
return E.expressionOperation(e, t, g);
|
|
433
428
|
}
|
|
434
|
-
function
|
|
435
|
-
const { function: r, expression: i, secondExpression: s } = e,
|
|
436
|
-
if (
|
|
429
|
+
function ci(e, t) {
|
|
430
|
+
const { function: r, expression: i, secondExpression: s } = e, o = li.has(r), a = s !== void 0;
|
|
431
|
+
if (o && s == null)
|
|
437
432
|
throw new Error(`Aggregate ${r} requires two expressions.`);
|
|
438
|
-
if (
|
|
433
|
+
if (o && i === "*")
|
|
439
434
|
throw new Error(`Aggregate ${r} cannot use * as an expression.`);
|
|
440
|
-
if (!
|
|
435
|
+
if (!o && a)
|
|
441
436
|
throw new Error(`Aggregate ${r} accepts only one expression.`);
|
|
442
|
-
const
|
|
437
|
+
const u = i === "*" ? E.wildcard(g) : R(i, t), f = E.aggregate(
|
|
443
438
|
r.toLowerCase(),
|
|
444
439
|
e.distinct || !1,
|
|
445
|
-
|
|
440
|
+
u,
|
|
446
441
|
void 0,
|
|
447
|
-
|
|
442
|
+
g
|
|
448
443
|
);
|
|
449
|
-
return
|
|
450
|
-
...
|
|
451
|
-
secondExpression:
|
|
452
|
-
} :
|
|
444
|
+
return a ? {
|
|
445
|
+
...f,
|
|
446
|
+
secondExpression: R(s, t)
|
|
447
|
+
} : f;
|
|
453
448
|
}
|
|
454
|
-
function
|
|
449
|
+
function P(e, t, r = void 0) {
|
|
455
450
|
return p(r).with("predicate", () => {
|
|
456
451
|
if (e.type !== "variable" && e.type !== "iri")
|
|
457
452
|
throw new Error(`Invalid predicate term: ${e.type}. RDF predicates cannot be ${e.type} nodes.`);
|
|
@@ -461,137 +456,136 @@ function $(e, t, r = void 0) {
|
|
|
461
456
|
}).with("graph", () => {
|
|
462
457
|
if (e.type !== "variable" && e.type !== "iri")
|
|
463
458
|
throw new Error(`Invalid graph name term: ${e.type}. Graph names can only be variables or IRIs.`);
|
|
464
|
-
}).with(
|
|
465
|
-
}).exhaustive(), r === "predicate" && e.type === "iri" && e.value === "a" ?
|
|
466
|
-
{ type: "literal", language:
|
|
467
|
-
(i) =>
|
|
468
|
-
).with({ type: "literal", datatype:
|
|
469
|
-
const s =
|
|
470
|
-
return
|
|
471
|
-
}).with({ type: "literal" }, (i) =>
|
|
472
|
-
}
|
|
473
|
-
function
|
|
474
|
-
const r = e.args.map((
|
|
459
|
+
}).with(l.nullish, () => {
|
|
460
|
+
}).exhaustive(), r === "predicate" && e.type === "iri" && e.value === "a" ? $("rdf:type") : p(e).with({ type: "variable" }, (i) => (t.add(i.name), E.termVariable(i.name, g))).with({ type: "iri", prefixed: !0 }, (i) => $(i.value)).with({ type: "iri", prefixed: !1 }, (i) => E.termNamed(g, i.value)).with(
|
|
461
|
+
{ type: "literal", language: l.string },
|
|
462
|
+
(i) => E.termLiteral(g, i.value, i.language)
|
|
463
|
+
).with({ type: "literal", datatype: l.string }, (i) => {
|
|
464
|
+
const s = $(i.datatype);
|
|
465
|
+
return E.termLiteral(g, i.value, s);
|
|
466
|
+
}).with({ type: "literal" }, (i) => E.termLiteral(g, i.value)).with({ type: "blank" }, (i) => E.termBlank(i.label, g)).exhaustive();
|
|
467
|
+
}
|
|
468
|
+
function pi(e, t) {
|
|
469
|
+
const r = e.args.map((o) => R(o, t)), i = ui.get(e.name.toLowerCase());
|
|
475
470
|
if (i)
|
|
476
|
-
return
|
|
477
|
-
const s =
|
|
478
|
-
return
|
|
471
|
+
return st(i.toLowerCase(), r);
|
|
472
|
+
const s = $(e.name);
|
|
473
|
+
return E.expressionFunctionCall(s, r, !1, g);
|
|
479
474
|
}
|
|
480
|
-
function
|
|
475
|
+
function R(e, t) {
|
|
481
476
|
return p(e).with(
|
|
482
477
|
{ type: "binary" },
|
|
483
|
-
(r) =>
|
|
484
|
-
|
|
485
|
-
|
|
478
|
+
(r) => st(r.operator, [
|
|
479
|
+
R(r.left, t),
|
|
480
|
+
R(r.right, t)
|
|
486
481
|
])
|
|
487
482
|
).with(
|
|
488
483
|
{ type: "unary" },
|
|
489
|
-
(r) =>
|
|
490
|
-
).with({ type: "term" }, (r) =>
|
|
484
|
+
(r) => st(r.operator, [R(r.operand, t)])
|
|
485
|
+
).with({ type: "term" }, (r) => P(r.term, t, "expression")).with({ type: "function" }, (r) => pi(r, t)).with(
|
|
491
486
|
{ type: "in" },
|
|
492
|
-
(r) =>
|
|
493
|
-
|
|
494
|
-
...r.list.map((i) =>
|
|
487
|
+
(r) => st(r.negated ? "notin" : "in", [
|
|
488
|
+
R(r.expression, t),
|
|
489
|
+
...r.list.map((i) => R(i, t))
|
|
495
490
|
])
|
|
496
491
|
).exhaustive();
|
|
497
492
|
}
|
|
498
|
-
function
|
|
493
|
+
function Ft(e, t) {
|
|
499
494
|
const r = p(e).with(
|
|
500
495
|
{ type: "triple" },
|
|
501
|
-
(i) =>
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
496
|
+
(i) => E.triple(
|
|
497
|
+
P(i.subject, t),
|
|
498
|
+
P(i.predicate, t, "predicate"),
|
|
499
|
+
P(i.object, t)
|
|
505
500
|
)
|
|
506
501
|
).with({ type: "property" }, (i) => {
|
|
507
|
-
const s =
|
|
508
|
-
return
|
|
502
|
+
const s = $(i.predicate);
|
|
503
|
+
return E.triple(P(i.subject, t), s, P(i.object, t));
|
|
509
504
|
}).with({ type: "class" }, (i) => {
|
|
510
|
-
const s =
|
|
511
|
-
return
|
|
505
|
+
const s = $("rdf:type"), o = $(i.className);
|
|
506
|
+
return E.triple(P(i.instance, t), s, o);
|
|
512
507
|
}).with({ type: "general" }, () => {
|
|
513
508
|
throw new Error("General formulas are not supported as triple patterns.");
|
|
514
509
|
}).exhaustive();
|
|
515
510
|
if (!r) return { triples: [] };
|
|
516
511
|
if ("graph" in e && e.graph) {
|
|
517
|
-
const i =
|
|
518
|
-
return { graph:
|
|
519
|
-
|
|
512
|
+
const i = E.patternBgp([r], g);
|
|
513
|
+
return { graph: E.patternGraph(
|
|
514
|
+
P(e.graph, t, "graph"),
|
|
520
515
|
[i],
|
|
521
|
-
|
|
516
|
+
g
|
|
522
517
|
) };
|
|
523
518
|
}
|
|
524
519
|
return { triples: [r] };
|
|
525
520
|
}
|
|
526
|
-
function
|
|
521
|
+
function hi(e, t) {
|
|
527
522
|
return e.formulas.filter((r) => "type" in r).flatMap(
|
|
528
|
-
(r) => p(r).with({ type:
|
|
523
|
+
(r) => p(r).with({ type: l.union("triple", "property", "class") }, (i) => Ft(i, t).triples || []).with({ type: "general" }, () => {
|
|
529
524
|
throw new Error("General formulas are not supported in negation patterns.");
|
|
530
525
|
}).exhaustive()
|
|
531
526
|
);
|
|
532
527
|
}
|
|
533
|
-
function
|
|
528
|
+
function di(e, t) {
|
|
534
529
|
return e.reduce(
|
|
535
|
-
(r, i) => "type" in i ? p(i).with({ type:
|
|
536
|
-
const
|
|
537
|
-
return
|
|
530
|
+
(r, i) => "type" in i ? p(i).with({ type: l.union("triple", "property", "class") }, (s) => {
|
|
531
|
+
const o = Ft(s, t);
|
|
532
|
+
return o.graph ? { ...r, graphPatterns: [...r.graphPatterns, o.graph] } : o.triples ? { ...r, triples: [...r.triples, ...o.triples] } : r;
|
|
538
533
|
}).with({ type: "filter" }, (s) => {
|
|
539
|
-
const
|
|
540
|
-
return { ...r, filters: [...r.filters,
|
|
534
|
+
const o = R(s.expression, t), a = E.patternFilter(o, g);
|
|
535
|
+
return { ...r, filters: [...r.filters, a] };
|
|
541
536
|
}).with({ type: "bind" }, (s) => {
|
|
542
537
|
t.add(s.variable);
|
|
543
|
-
const
|
|
544
|
-
return { ...r, binds: [...r.binds,
|
|
538
|
+
const o = R(s.expression, t), a = E.termVariable(s.variable, g), u = E.patternBind(o, a, g);
|
|
539
|
+
return { ...r, binds: [...r.binds, u] };
|
|
545
540
|
}).with({ type: "general" }, () => {
|
|
546
541
|
throw new Error("General formulas are not supported in atom processing.");
|
|
547
542
|
}).exhaustive() : r,
|
|
548
543
|
{ triples: [], filters: [], binds: [], graphPatterns: [] }
|
|
549
544
|
);
|
|
550
545
|
}
|
|
551
|
-
function
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
throw new Error(`${W} requires an expression.`);
|
|
546
|
+
function Ei(e, t) {
|
|
547
|
+
const { triples: r, filters: i, binds: s, graphPatterns: o } = di(e.atoms, t), a = e.onVars || [], u = a.map((m) => (t.add(m), E.termVariable(m, g))), f = [], y = [];
|
|
548
|
+
return e.bindings?.forEach((m) => {
|
|
549
|
+
if (t.add(m.variable), m.expression === void 0) {
|
|
550
|
+
const k = m.function !== void 0 ? `Aggregate ${m.function}` : "Expression-only aggregate binding";
|
|
551
|
+
throw new Error(`${k} requires an expression.`);
|
|
558
552
|
}
|
|
559
|
-
if (
|
|
553
|
+
if (m.function === void 0 && m.secondExpression !== void 0)
|
|
560
554
|
throw new Error("Expression-only aggregate bindings cannot have a second expression.");
|
|
561
|
-
const
|
|
562
|
-
|
|
555
|
+
const h = m.function !== void 0, C = h ? ci(m, t) : R(m.expression, t), T = E.termVariable(m.variable, g), A = E.patternBind(C, T, g);
|
|
556
|
+
h ? f.push(A) : y.push(A);
|
|
563
557
|
}), {
|
|
564
558
|
triples: r,
|
|
565
559
|
filters: i,
|
|
566
560
|
binds: [...s, ...y],
|
|
567
|
-
graphPatterns:
|
|
568
|
-
selectVars: [...
|
|
569
|
-
groupBy:
|
|
561
|
+
graphPatterns: o,
|
|
562
|
+
selectVars: [...u, ...f],
|
|
563
|
+
groupBy: a
|
|
570
564
|
};
|
|
571
565
|
}
|
|
572
|
-
function
|
|
573
|
-
|
|
566
|
+
function fi(e, t) {
|
|
567
|
+
ir(e);
|
|
574
568
|
const r = /* @__PURE__ */ new Set(), i = e.reduce(
|
|
575
|
-
(h,
|
|
576
|
-
const A =
|
|
569
|
+
(h, C) => p(C).with({ type: l.union("triple", "property", "class", "general") }, (T) => {
|
|
570
|
+
const A = Ft(T, r);
|
|
577
571
|
return A.graph ? { ...h, graphPatterns: [...h.graphPatterns, A.graph] } : A.triples ? { ...h, triples: [...h.triples, ...A.triples] } : h;
|
|
578
|
-
}).with({ type: "filter" }, (
|
|
579
|
-
const A =
|
|
572
|
+
}).with({ type: "filter" }, (T) => {
|
|
573
|
+
const A = R(T.expression, r), k = E.patternFilter(A, g);
|
|
580
574
|
return { ...h, filters: [...h.filters, k] };
|
|
581
|
-
}).with({ type: "bind" }, (
|
|
582
|
-
const A =
|
|
583
|
-
r.add(
|
|
584
|
-
const k =
|
|
585
|
-
return { ...h, binds: [...h.binds,
|
|
586
|
-
}).with({ type: "negation" }, (
|
|
587
|
-
const A =
|
|
575
|
+
}).with({ type: "bind" }, (T) => {
|
|
576
|
+
const A = R(T.expression, r);
|
|
577
|
+
r.add(T.variable);
|
|
578
|
+
const k = E.termVariable(T.variable, g), At = E.patternBind(A, k, g);
|
|
579
|
+
return { ...h, binds: [...h.binds, At] };
|
|
580
|
+
}).with({ type: "negation" }, (T) => {
|
|
581
|
+
const A = hi(T, r);
|
|
588
582
|
if (A.length > 0) {
|
|
589
|
-
const k =
|
|
590
|
-
return { ...h, filters: [...h.filters,
|
|
583
|
+
const k = E.patternBgp(A, g), At = E.patternGroup([k], g), Sr = E.expressionPatternOperation("notexists", At, g), Nr = E.patternFilter(Sr, g);
|
|
584
|
+
return { ...h, filters: [...h.filters, Nr] };
|
|
591
585
|
}
|
|
592
586
|
return h;
|
|
593
|
-
}).with({ type: "aggregate" }, (
|
|
594
|
-
const A =
|
|
587
|
+
}).with({ type: "aggregate" }, (T) => {
|
|
588
|
+
const A = Ei(T, r);
|
|
595
589
|
return {
|
|
596
590
|
triples: [...h.triples, ...A.triples],
|
|
597
591
|
filters: [...h.filters, ...A.filters],
|
|
@@ -612,139 +606,140 @@ function yi(e, t) {
|
|
|
612
606
|
aggregateSelectVars: []
|
|
613
607
|
}
|
|
614
608
|
), s = [
|
|
615
|
-
...i.triples.length > 0 ? [
|
|
609
|
+
...i.triples.length > 0 ? [E.patternBgp(i.triples, g)] : [],
|
|
616
610
|
...i.graphPatterns,
|
|
617
611
|
...i.filters,
|
|
618
612
|
...i.binds
|
|
619
|
-
],
|
|
620
|
-
group:
|
|
621
|
-
i.groupByVars.map((h) =>
|
|
622
|
-
|
|
613
|
+
], o = i.aggregateSelectVars.length > 0 ? i.aggregateSelectVars : r.size > 0 ? Array.from(r).map((h) => E.termVariable(h, g)) : [E.wildcard(g)], a = i.groupByVars.length > 0 ? {
|
|
614
|
+
group: E.solutionModifierGroup(
|
|
615
|
+
i.groupByVars.map((h) => E.termVariable(h, g)),
|
|
616
|
+
g
|
|
623
617
|
)
|
|
624
|
-
} : {},
|
|
625
|
-
const
|
|
626
|
-
return
|
|
627
|
-
}) : [],
|
|
618
|
+
} : {}, u = t ? Object.entries(t).map(([h, C]) => {
|
|
619
|
+
const T = E.termNamed(g, C);
|
|
620
|
+
return E.contextDefinitionPrefix(g, h, T);
|
|
621
|
+
}) : [], f = E.querySelect(
|
|
628
622
|
{
|
|
629
|
-
context:
|
|
623
|
+
context: u,
|
|
630
624
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-ts-comment
|
|
631
|
-
variables:
|
|
625
|
+
variables: o,
|
|
632
626
|
// @ts-ignore - Fails in CI for some reason
|
|
633
|
-
where:
|
|
634
|
-
datasets:
|
|
635
|
-
solutionModifiers:
|
|
627
|
+
where: E.patternGroup(s, g),
|
|
628
|
+
datasets: E.datasetClauses([], g),
|
|
629
|
+
solutionModifiers: a
|
|
636
630
|
},
|
|
637
|
-
|
|
638
|
-
), y =
|
|
631
|
+
g
|
|
632
|
+
), y = oi.queryOrUpdate(f, Or({ indentInc: 2 })).trim(), m = i.aggregateSelectVars.length > 0 ? i.aggregateSelectVars.map((h) => "value" in h && typeof h.value == "string" ? h.value : "variable" in h && h.variable && "value" in h.variable ? h.variable.value : null).filter((h) => h !== null) : Array.from(r);
|
|
639
633
|
return {
|
|
640
634
|
query: y,
|
|
641
|
-
variables:
|
|
635
|
+
variables: m
|
|
642
636
|
};
|
|
643
637
|
}
|
|
644
|
-
const
|
|
638
|
+
const Pt = c({ name: "RULE_ARROW", pattern: /:-/ }), at = c({ name: "NOT", pattern: /NOT/ }), kt = c({ name: "EXISTS", pattern: /EXISTS?/ }), W = c({ name: "IN", pattern: /IN/ }), $t = c({ name: "FILTER", pattern: /FILTER/ }), Q = c({ name: "BIND", pattern: /BIND/ }), z = c({ name: "AS", pattern: /AS/ }), Lt = c({ name: "AGGREGATE", pattern: /AGGREGATE/ }), Ut = c({ name: "ON", pattern: /ON/ }), Dt = c({ name: "COUNT", pattern: /COUNT/ }), Gt = c({ name: "MIN", pattern: /MIN/ }), _t = c({ name: "MAX", pattern: /MAX/ }), Vt = c({ name: "SUM", pattern: /SUM/ }), jt = c({ name: "MUL", pattern: /MUL/ }), qt = c({ name: "AVG", pattern: /AVG/ }), Xt = c({ name: "COUNT_MIN", pattern: /COUNT_MIN/ }), Ht = c({ name: "COUNT_MAX", pattern: /COUNT_MAX/ }), Qt = c({ name: "MIN_ARGMIN", pattern: /MIN_ARGMIN/ }), zt = c({ name: "MAX_ARGMIN", pattern: /MAX_ARGMIN/ }), Kt = c({ name: "MIN_ARGMAX", pattern: /MIN_ARGMAX/ }), Wt = c({ name: "MAX_ARGMAX", pattern: /MAX_ARGMAX/ }), ot = c({ name: "DISTINCT", pattern: /DISTINCT/ }), Yt = c({ name: "CONCAT", pattern: /CONCAT/ }), Zt = c({ name: "STR", pattern: /STR/ }), Jt = c({ name: "IF", pattern: /IF/ }), te = c({ name: "IRI", pattern: /IRI/ }), lt = c({ name: "SKOLEM", pattern: /SKOLEM/ }), ee = c({ name: "ROUND", pattern: /ROUND/ }), re = c({ name: "REGEX", pattern: /REGEX/ }), ie = c({ name: "TRUE", pattern: /true/ }), ne = c({ name: "FALSE", pattern: /false/ }), se = c({ name: "EQUALS", pattern: /=/ }), ae = c({ name: "NOT_EQUALS", pattern: /!=/ }), oe = c({ name: "LESS_THAN", pattern: /</ }), le = c({ name: "LESS_THAN_OR_EQUAL", pattern: /<=/ }), ue = c({ name: "GREATER_THAN", pattern: />/ }), ce = c({ name: "GREATER_THAN_OR_EQUAL", pattern: />=/ }), pe = c({ name: "AND", pattern: /&&/ }), he = c({ name: "OR", pattern: /\|\|/ }), ut = c({ name: "PLUS", pattern: /\+/ }), ct = c({ name: "MINUS", pattern: /-/ }), pt = c({ name: "STAR", pattern: /\*/ }), de = c({ name: "SLASH", pattern: /\// }), Ee = c({ name: "EXCLAMATION", pattern: /!/ }), fe = c({ name: "DOT", pattern: /\./ }), S = c({ name: "COMMA", pattern: /,/ }), L = c({ name: "LPAREN", pattern: /\(/ }), U = c({ name: "RPAREN", pattern: /\)/ }), ht = c({ name: "LBRACKET", pattern: /\[/ }), dt = c({ name: "RBRACKET", pattern: /\]/ }), nr = c({ name: "AT", pattern: /@/ }), Et = c({ name: "HAT", pattern: /\^/ }), sr = c({ name: "COLON", pattern: /:/ }), N = c({ name: "VARIABLE", pattern: /\?[a-zA-Z_][a-zA-Z0-9_]*/ }), ge = c({ name: "IRI_REF", pattern: new RegExp(`<${ze}*>`) }), me = c({ name: "INTERNAL_FUNCTION", pattern: /<internal:[^>]+>/ }), J = c({ name: "BLANK_NODE", pattern: /_:[\w](?:[\w.-]*[\w-])?/ }), ye = "%[0-9a-fA-F]{2}|\\\\[-_~.!$&'()*+,;=/?#@%]", gi = `(?:[\\w:]|${ye})`, mi = `(?:[\\w:.-]|${ye})`, yi = `(?:[\\w:-]|${ye})`, ar = `${gi}(?:${mi}*${yi})?`, it = c({
|
|
645
639
|
name: "PREFIXED_NAME",
|
|
646
|
-
pattern: new RegExp(`[a-zA-Z_][\\w]*:${
|
|
647
|
-
}),
|
|
640
|
+
pattern: new RegExp(`[a-zA-Z_][\\w]*:${ar}`)
|
|
641
|
+
}), wt = c({ name: "PREFIX_ONLY", pattern: /[a-zA-Z_][\w]*:/ }), Le = c({
|
|
648
642
|
name: "DEFAULT_NS_IRI",
|
|
649
|
-
pattern: new RegExp(`:${
|
|
650
|
-
}),
|
|
643
|
+
pattern: new RegExp(`:${ar}`)
|
|
644
|
+
}), Ue = c({ name: "INTEGER", pattern: /[+-]?\d+/ }), we = c({ name: "DECIMAL", pattern: /[+-]?\d*\.\d+/ }), Ae = c({
|
|
651
645
|
name: "DOUBLE",
|
|
652
646
|
pattern: /[+-]?(\d+\.\d*[eE][+-]?\d+|\.\d+[eE][+-]?\d+|\d+[eE][+-]?\d+)/
|
|
653
|
-
}),
|
|
647
|
+
}), Te = c({
|
|
654
648
|
name: "STRING_LITERAL_LONG",
|
|
655
649
|
pattern: /"""(?:[^"\\]|\\.|"(?!""))*"""|'''(?:[^'\\]|\\.|'(?!''))*'''/
|
|
656
|
-
}),
|
|
650
|
+
}), ft = c({
|
|
657
651
|
name: "STRING_LITERAL",
|
|
658
652
|
pattern: /"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/
|
|
659
|
-
}),
|
|
653
|
+
}), Se = c({ name: "LANGTAG", pattern: /@[a-zA-Z]+(-[a-zA-Z0-9]+)*/ }), tt = c({
|
|
660
654
|
name: "IDENTIFIER",
|
|
661
655
|
pattern: /[a-zA-Z_][a-zA-Z0-9_]*/,
|
|
662
|
-
longer_alt:
|
|
663
|
-
}),
|
|
656
|
+
longer_alt: it
|
|
657
|
+
}), Li = c({
|
|
664
658
|
name: "COMMENT",
|
|
665
659
|
pattern: /#[^\r\n]*/,
|
|
666
|
-
group:
|
|
667
|
-
}),
|
|
660
|
+
group: Mt.SKIPPED
|
|
661
|
+
}), Ui = c({
|
|
668
662
|
name: "WHITESPACE",
|
|
669
663
|
pattern: /\s+/,
|
|
670
|
-
group:
|
|
671
|
-
}),
|
|
664
|
+
group: Mt.SKIPPED
|
|
665
|
+
}), or = [
|
|
672
666
|
// Whitespace and comments (skipped)
|
|
673
|
-
|
|
674
|
-
|
|
667
|
+
Ui,
|
|
668
|
+
Li,
|
|
675
669
|
// Multi-character operators (before single-char)
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
670
|
+
Pt,
|
|
671
|
+
ae,
|
|
672
|
+
le,
|
|
673
|
+
ce,
|
|
679
674
|
pe,
|
|
680
675
|
he,
|
|
681
|
-
|
|
682
|
-
gt,
|
|
676
|
+
Et,
|
|
683
677
|
// Keywords (before identifiers)
|
|
684
|
-
|
|
678
|
+
at,
|
|
679
|
+
kt,
|
|
680
|
+
W,
|
|
685
681
|
$t,
|
|
686
|
-
|
|
687
|
-
Dt,
|
|
682
|
+
Q,
|
|
688
683
|
z,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
684
|
+
Lt,
|
|
685
|
+
Ut,
|
|
686
|
+
Qt,
|
|
692
687
|
zt,
|
|
693
688
|
Kt,
|
|
694
689
|
Wt,
|
|
695
|
-
|
|
690
|
+
Xt,
|
|
696
691
|
Ht,
|
|
697
|
-
|
|
692
|
+
Dt,
|
|
698
693
|
Gt,
|
|
699
694
|
_t,
|
|
700
695
|
Vt,
|
|
701
696
|
jt,
|
|
702
697
|
qt,
|
|
703
|
-
|
|
704
|
-
|
|
698
|
+
ot,
|
|
699
|
+
Yt,
|
|
705
700
|
Zt,
|
|
706
701
|
Jt,
|
|
707
702
|
te,
|
|
703
|
+
lt,
|
|
708
704
|
ee,
|
|
709
|
-
ct,
|
|
710
705
|
re,
|
|
711
706
|
ie,
|
|
712
707
|
ne,
|
|
713
|
-
se,
|
|
714
708
|
// Literals (specific patterns before generic)
|
|
715
|
-
Se,
|
|
716
|
-
mt,
|
|
717
709
|
Te,
|
|
710
|
+
ft,
|
|
718
711
|
Ae,
|
|
719
712
|
we,
|
|
720
|
-
|
|
713
|
+
Ue,
|
|
714
|
+
Se,
|
|
721
715
|
// Identifiers and names
|
|
722
|
-
|
|
723
|
-
ye,
|
|
716
|
+
N,
|
|
724
717
|
me,
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
718
|
+
ge,
|
|
719
|
+
J,
|
|
720
|
+
it,
|
|
721
|
+
Le,
|
|
722
|
+
wt,
|
|
723
|
+
tt,
|
|
730
724
|
// Single character tokens
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
725
|
+
se,
|
|
726
|
+
oe,
|
|
727
|
+
ue,
|
|
728
|
+
ut,
|
|
729
|
+
ct,
|
|
734
730
|
pt,
|
|
735
|
-
|
|
736
|
-
dt,
|
|
731
|
+
de,
|
|
737
732
|
Ee,
|
|
738
733
|
fe,
|
|
739
|
-
|
|
740
|
-
|
|
734
|
+
S,
|
|
735
|
+
L,
|
|
741
736
|
U,
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
sr
|
|
746
|
-
|
|
747
|
-
|
|
737
|
+
ht,
|
|
738
|
+
dt,
|
|
739
|
+
nr,
|
|
740
|
+
sr
|
|
741
|
+
], wi = /* @__PURE__ */ new Set([at, kt, W, $t, Q, z, Lt, Ut, ot]), Ai = /* @__PURE__ */ new Set([
|
|
742
|
+
Dt,
|
|
748
743
|
Gt,
|
|
749
744
|
_t,
|
|
750
745
|
Vt,
|
|
@@ -760,12 +755,12 @@ const kt = c({ name: "RULE_ARROW", pattern: /:-/ }), lt = c({ name: "NOT", patte
|
|
|
760
755
|
Zt,
|
|
761
756
|
Jt,
|
|
762
757
|
te,
|
|
758
|
+
lt,
|
|
763
759
|
ee,
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
kt,
|
|
760
|
+
re
|
|
761
|
+
]), Ti = /* @__PURE__ */ new Set([ie, ne]), us = /* @__PURE__ */ new Set([Ue, we, Ae]), Si = /* @__PURE__ */ new Set([ft, Te]), cs = /* @__PURE__ */ new Set([ge, me, it, wt, Le]), ps = /* @__PURE__ */ new Set([
|
|
762
|
+
Pt,
|
|
763
|
+
se,
|
|
769
764
|
ae,
|
|
770
765
|
oe,
|
|
771
766
|
le,
|
|
@@ -773,31 +768,29 @@ const kt = c({ name: "RULE_ARROW", pattern: /:-/ }), lt = c({ name: "NOT", patte
|
|
|
773
768
|
ce,
|
|
774
769
|
pe,
|
|
775
770
|
he,
|
|
776
|
-
|
|
771
|
+
ut,
|
|
772
|
+
ct,
|
|
777
773
|
pt,
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
function J(e, t, r, i) {
|
|
790
|
-
var o;
|
|
791
|
-
const a = e.slice(0, t).split(/\r\n|\r|\n/);
|
|
774
|
+
de,
|
|
775
|
+
Ee
|
|
776
|
+
]), hs = /* @__PURE__ */ new Set([fe, S, L, U, ht, dt, nr, Et, sr]), ds = /* @__PURE__ */ new Set([N, J, Se, tt]);
|
|
777
|
+
for (const e of [...wi, ...Ai, ...Ti])
|
|
778
|
+
e.LONGER_ALT = [it, wt, tt];
|
|
779
|
+
let Ni;
|
|
780
|
+
function Ne(e) {
|
|
781
|
+
return (Ni ??= new Mt(or)).tokenize(e);
|
|
782
|
+
}
|
|
783
|
+
function Y(e, t, r, i) {
|
|
784
|
+
const o = e.slice(0, t).split(/\r\n|\r|\n/);
|
|
792
785
|
return {
|
|
793
786
|
message: i,
|
|
794
|
-
line:
|
|
795
|
-
column: (
|
|
787
|
+
line: o.length,
|
|
788
|
+
column: (o.at(-1)?.length ?? 0) + 1,
|
|
796
789
|
offset: t,
|
|
797
790
|
endOffset: t + r
|
|
798
791
|
};
|
|
799
792
|
}
|
|
800
|
-
function
|
|
793
|
+
function Re(e) {
|
|
801
794
|
for (let t = 0; t < e.length; t++) {
|
|
802
795
|
const r = e.charCodeAt(t);
|
|
803
796
|
if (r >= 55296 && r <= 56319) {
|
|
@@ -806,15 +799,15 @@ function be(e) {
|
|
|
806
799
|
t++;
|
|
807
800
|
continue;
|
|
808
801
|
}
|
|
809
|
-
return
|
|
802
|
+
return Y(e, t, 1, "Unpaired high surrogate is not a valid Unicode scalar value");
|
|
810
803
|
}
|
|
811
804
|
if (r >= 56320 && r <= 57343)
|
|
812
|
-
return
|
|
805
|
+
return Y(e, t, 1, "Unpaired low surrogate is not a valid Unicode scalar value");
|
|
813
806
|
}
|
|
814
807
|
}
|
|
815
|
-
function
|
|
808
|
+
function be(e, t) {
|
|
816
809
|
for (const r of t)
|
|
817
|
-
if (
|
|
810
|
+
if (Si.has(r.tokenType))
|
|
818
811
|
for (let i = 0; i < r.image.length; i++) {
|
|
819
812
|
if (r.image[i] !== "\\") continue;
|
|
820
813
|
const s = r.image[i + 1];
|
|
@@ -822,416 +815,416 @@ function Oe(e, t) {
|
|
|
822
815
|
i++;
|
|
823
816
|
continue;
|
|
824
817
|
}
|
|
825
|
-
const
|
|
826
|
-
if (
|
|
827
|
-
return
|
|
818
|
+
const o = s === "u" ? 4 : 8, a = o + 2, u = r.image.slice(i, i + a), f = r.image.slice(i + 2, i + a), y = r.startOffset + i;
|
|
819
|
+
if (f.length !== o || !/^[0-9a-fA-F]+$/.test(f))
|
|
820
|
+
return Y(
|
|
828
821
|
e,
|
|
829
822
|
y,
|
|
830
|
-
|
|
831
|
-
`Unicode escape \\${s} must contain ${
|
|
823
|
+
u.length,
|
|
824
|
+
`Unicode escape \\${s} must contain ${o} hexadecimal digits`
|
|
832
825
|
);
|
|
833
|
-
const
|
|
834
|
-
if (
|
|
835
|
-
return
|
|
836
|
-
if (
|
|
837
|
-
return
|
|
838
|
-
i +=
|
|
826
|
+
const m = Number.parseInt(f, 16);
|
|
827
|
+
if (m >= 55296 && m <= 57343)
|
|
828
|
+
return Y(e, y, a, `Unicode escape ${u} denotes a surrogate code point`);
|
|
829
|
+
if (m > 1114111)
|
|
830
|
+
return Y(e, y, a, `Unicode escape ${u} is outside the Unicode range`);
|
|
831
|
+
i += a - 1;
|
|
839
832
|
}
|
|
840
833
|
}
|
|
841
|
-
class
|
|
842
|
-
constructor(
|
|
843
|
-
super(
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
834
|
+
class Oe extends Cr {
|
|
835
|
+
constructor(t = {}) {
|
|
836
|
+
super(or);
|
|
837
|
+
const { selfAnalysis: r = !0 } = t;
|
|
838
|
+
r && this.performSelfAnalysis();
|
|
839
|
+
}
|
|
840
|
+
// Chevrotain only reports leftover input for the rule it was entered on, so
|
|
841
|
+
// callers entering on a nested rule have to reject trailing tokens themselves.
|
|
842
|
+
get atEndOfInput() {
|
|
843
|
+
return this.LA(1).tokenType === Ir;
|
|
844
|
+
}
|
|
845
|
+
// Rule := RuleHead ':-' RuleBody '.'
|
|
846
|
+
rule = this.RULE("rule", () => {
|
|
847
|
+
this.SUBRULE(this.ruleHead), this.CONSUME(Pt), this.OPTION(() => {
|
|
848
|
+
this.SUBRULE(this.ruleBody);
|
|
849
|
+
}), this.CONSUME(fe);
|
|
850
|
+
});
|
|
851
|
+
// RuleHead := TupleTableAtom (',' TupleTableAtom)*
|
|
852
|
+
ruleHead = this.RULE("ruleHead", () => {
|
|
853
|
+
this.SUBRULE(this.tupleTableAtom), this.MANY(() => {
|
|
854
|
+
this.CONSUME(S), this.SUBRULE2(this.tupleTableAtom);
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
// RuleBody := BodyFormula (',' BodyFormula)*
|
|
858
|
+
ruleBody = this.RULE("ruleBody", () => {
|
|
859
|
+
this.SUBRULE(this.bodyFormula), this.MANY(() => {
|
|
860
|
+
this.CONSUME(S), this.SUBRULE2(this.bodyFormula);
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
// BodyFormula := Negation | FilterAtom | BindAtom | Aggregate | SkolemAtom | TupleTableAtom
|
|
864
|
+
bodyFormula = this.RULE("bodyFormula", () => {
|
|
865
|
+
this.OR([
|
|
866
|
+
{ ALT: () => this.SUBRULE(this.negation) },
|
|
867
|
+
{ ALT: () => this.SUBRULE(this.filterAtom) },
|
|
868
|
+
{ ALT: () => this.SUBRULE(this.bindAtom) },
|
|
869
|
+
{ ALT: () => this.SUBRULE(this.aggregate) },
|
|
870
|
+
{ ALT: () => this.SUBRULE(this.skolemAtom) },
|
|
871
|
+
{ ALT: () => this.SUBRULE(this.tupleTableAtom) }
|
|
872
|
+
]);
|
|
873
|
+
});
|
|
874
|
+
// TupleTableAtom := (DefaultGraphAtom Graph?) | GeneralAtom
|
|
875
|
+
// NamedGraphAtom := DefaultGraphAtom Graph
|
|
876
|
+
// Graph := Term (IRI or Variable)
|
|
877
|
+
tupleTableAtom = this.RULE("tupleTableAtom", () => {
|
|
878
|
+
this.OR([{ ALT: () => this.SUBRULE(this.defaultGraphAtom) }, { ALT: () => this.SUBRULE(this.generalAtom) }]), this.OPTION(() => {
|
|
879
|
+
this.SUBRULE(this.graphName, { LABEL: "graph" });
|
|
880
|
+
});
|
|
881
|
+
});
|
|
882
|
+
// Graph name for named graph atoms - can be IRI or Variable
|
|
883
|
+
graphName = this.RULE("graphName", () => {
|
|
884
|
+
this.OR([{ ALT: () => this.CONSUME(N) }, { ALT: () => this.SUBRULE(this.iri) }]);
|
|
885
|
+
});
|
|
886
|
+
// DefaultGraphAtom := TripleAtom | PropertyAtom | ClassAtom
|
|
887
|
+
defaultGraphAtom = this.RULE("defaultGraphAtom", () => {
|
|
888
|
+
this.OR([
|
|
889
|
+
// TripleAtom: [term, term, term]
|
|
890
|
+
{
|
|
891
|
+
ALT: () => {
|
|
892
|
+
this.CONSUME(ht), this.SUBRULE(this.term, { LABEL: "subject" }), this.CONSUME(S), this.SUBRULE2(this.term, { LABEL: "predicate" }), this.CONSUME2(S), this.SUBRULE3(this.term, { LABEL: "object" }), this.CONSUME(dt);
|
|
893
|
+
}
|
|
894
|
+
},
|
|
895
|
+
// PropertyAtom: predicate[term, term] or ClassAtom: class[term]
|
|
896
|
+
{
|
|
897
|
+
ALT: () => {
|
|
898
|
+
this.SUBRULE(this.iri, { LABEL: "predicateOrClass" }), this.CONSUME2(ht), this.SUBRULE4(this.term, { LABEL: "firstTerm" }), this.OPTION(() => {
|
|
899
|
+
this.CONSUME3(S), this.SUBRULE5(this.term, { LABEL: "secondTerm" });
|
|
900
|
+
}), this.CONSUME2(dt);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
]);
|
|
904
|
+
});
|
|
905
|
+
// GeneralAtom := tableName(term, ...)
|
|
906
|
+
generalAtom = this.RULE("generalAtom", () => {
|
|
907
|
+
this.OR([{ ALT: () => this.CONSUME(tt) }, { ALT: () => this.CONSUME(ft) }]), this.CONSUME(L), this.SUBRULE(this.term), this.MANY(() => {
|
|
908
|
+
this.CONSUME(S), this.SUBRULE2(this.term);
|
|
909
|
+
}), this.CONSUME(U);
|
|
910
|
+
});
|
|
911
|
+
// Term := Variable | IRI | Literal | BlankNode
|
|
912
|
+
term = this.RULE("term", () => {
|
|
913
|
+
this.OR([
|
|
914
|
+
{ ALT: () => this.CONSUME(N) },
|
|
915
|
+
{ ALT: () => this.SUBRULE(this.iri) },
|
|
916
|
+
{ ALT: () => this.SUBRULE(this.literal) },
|
|
917
|
+
{ ALT: () => this.CONSUME(J) }
|
|
918
|
+
]);
|
|
919
|
+
});
|
|
920
|
+
// IRI := IRI_REF | PrefixedName | DefaultNsIRI | InternalFunction
|
|
921
|
+
iri = this.RULE("iri", () => {
|
|
922
|
+
this.OR([
|
|
923
|
+
{ ALT: () => this.CONSUME(ge) },
|
|
924
|
+
{ ALT: () => this.CONSUME(me) },
|
|
925
|
+
{ ALT: () => this.CONSUME(it) },
|
|
926
|
+
{ ALT: () => this.CONSUME(Le) },
|
|
927
|
+
{ ALT: () => this.CONSUME(wt) },
|
|
928
|
+
{ ALT: () => this.CONSUME(tt) }
|
|
929
|
+
]);
|
|
930
|
+
});
|
|
931
|
+
// Literal := NumericLiteral | BooleanLiteral | StringLiteral
|
|
932
|
+
literal = this.RULE("literal", () => {
|
|
933
|
+
this.OR([
|
|
934
|
+
{ ALT: () => this.SUBRULE(this.numericLiteral) },
|
|
935
|
+
{ ALT: () => this.SUBRULE(this.booleanLiteral) },
|
|
936
|
+
{ ALT: () => this.SUBRULE(this.stringLiteral) }
|
|
937
|
+
]);
|
|
938
|
+
});
|
|
939
|
+
numericLiteral = this.RULE("numericLiteral", () => {
|
|
940
|
+
this.OR([
|
|
941
|
+
{ ALT: () => this.CONSUME(Ae) },
|
|
942
|
+
{ ALT: () => this.CONSUME(we) },
|
|
943
|
+
{ ALT: () => this.CONSUME(Ue) }
|
|
944
|
+
]);
|
|
945
|
+
});
|
|
946
|
+
booleanLiteral = this.RULE("booleanLiteral", () => {
|
|
947
|
+
this.OR([{ ALT: () => this.CONSUME(ie) }, { ALT: () => this.CONSUME(ne) }]);
|
|
948
|
+
});
|
|
949
|
+
stringLiteral = this.RULE("stringLiteral", () => {
|
|
950
|
+
this.OR([
|
|
951
|
+
{ ALT: () => this.CONSUME(Te) },
|
|
952
|
+
{ ALT: () => this.CONSUME(ft) }
|
|
953
|
+
]), this.OPTION(() => {
|
|
954
|
+
this.OR2([
|
|
955
|
+
{ ALT: () => this.CONSUME(Se) },
|
|
895
956
|
{
|
|
896
957
|
ALT: () => {
|
|
897
|
-
this.
|
|
898
|
-
this.CONSUME3(N), this.SUBRULE5(this.term, { LABEL: "secondTerm" });
|
|
899
|
-
}), this.CONSUME2(ft);
|
|
958
|
+
this.CONSUME(Et), this.CONSUME2(Et), this.SUBRULE(this.iri);
|
|
900
959
|
}
|
|
901
960
|
}
|
|
902
961
|
]);
|
|
903
|
-
})
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
})
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
this.
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
// Negation := 'NOT' ExistsClause? (Atom | '(' BodyFormulaList ')')
|
|
965
|
+
negation = this.RULE("negation", () => {
|
|
966
|
+
this.CONSUME(at), this.OPTION(() => {
|
|
967
|
+
this.SUBRULE(this.existsClause);
|
|
968
|
+
}), this.OR([
|
|
969
|
+
{
|
|
970
|
+
ALT: () => {
|
|
971
|
+
this.CONSUME(L), this.SUBRULE(this.bodyFormulaList), this.CONSUME(U);
|
|
972
|
+
}
|
|
973
|
+
},
|
|
974
|
+
{ ALT: () => this.SUBRULE(this.tupleTableAtom) }
|
|
975
|
+
]);
|
|
976
|
+
});
|
|
977
|
+
// ExistsClause := 'EXISTS' variable (',' variable)* 'IN'
|
|
978
|
+
existsClause = this.RULE("existsClause", () => {
|
|
979
|
+
this.CONSUME(kt), this.CONSUME(N), this.MANY(() => {
|
|
980
|
+
this.CONSUME(S), this.CONSUME2(N);
|
|
981
|
+
}), this.CONSUME(W);
|
|
982
|
+
});
|
|
983
|
+
// AtomList := Atom (',' Atom)*
|
|
984
|
+
atomList = this.RULE("atomList", () => {
|
|
985
|
+
this.SUBRULE(this.atom), this.MANY(() => {
|
|
986
|
+
this.CONSUME(S), this.SUBRULE2(this.atom);
|
|
987
|
+
});
|
|
988
|
+
});
|
|
989
|
+
// Atom := TupleTableAtom | FilterAtom | BindAtom
|
|
990
|
+
atom = this.RULE("atom", () => {
|
|
991
|
+
this.OR([
|
|
992
|
+
{ ALT: () => this.SUBRULE(this.tupleTableAtom) },
|
|
993
|
+
{ ALT: () => this.SUBRULE(this.filterAtom) },
|
|
994
|
+
{ ALT: () => this.SUBRULE(this.bindAtom) }
|
|
995
|
+
]);
|
|
996
|
+
});
|
|
997
|
+
// BodyFormulaList := BodyFormula (',' BodyFormula)*
|
|
998
|
+
bodyFormulaList = this.RULE("bodyFormulaList", () => {
|
|
999
|
+
this.SUBRULE(this.bodyFormula), this.MANY(() => {
|
|
1000
|
+
this.CONSUME(S), this.SUBRULE2(this.bodyFormula);
|
|
1001
|
+
});
|
|
1002
|
+
});
|
|
1003
|
+
// FilterAtom := 'FILTER' '(' Expression ')'
|
|
1004
|
+
filterAtom = this.RULE("filterAtom", () => {
|
|
1005
|
+
this.CONSUME($t), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(U);
|
|
1006
|
+
});
|
|
1007
|
+
// BindAtom := 'BIND' '(' Expression 'AS' variable ')'
|
|
1008
|
+
bindAtom = this.RULE("bindAtom", () => {
|
|
1009
|
+
this.CONSUME(Q), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(z), this.CONSUME(N), this.CONSUME(U);
|
|
1010
|
+
});
|
|
1011
|
+
// SkolemAtom := 'SKOLEM' '(' ArgumentList ')'
|
|
1012
|
+
skolemAtom = this.RULE("skolemAtom", () => {
|
|
1013
|
+
this.CONSUME(lt), this.CONSUME(L), this.SUBRULE(this.argumentList), this.CONSUME(U);
|
|
1014
|
+
});
|
|
1015
|
+
// Aggregate := 'AGGREGATE' '(' AtomList OnClause? AggregateBind* ')'
|
|
1016
|
+
aggregate = this.RULE("aggregate", () => {
|
|
1017
|
+
this.CONSUME(Lt), this.CONSUME(L), this.SUBRULE(this.atomList), this.OPTION(() => {
|
|
1018
|
+
this.SUBRULE(this.onClause);
|
|
1019
|
+
}), this.MANY(() => {
|
|
1020
|
+
this.SUBRULE(this.aggregateBind);
|
|
1021
|
+
}), this.CONSUME(U);
|
|
1022
|
+
});
|
|
1023
|
+
// OnClause := 'ON' variable+
|
|
1024
|
+
onClause = this.RULE("onClause", () => {
|
|
1025
|
+
this.CONSUME(Ut), this.CONSUME(N), this.MANY(() => {
|
|
1026
|
+
this.CONSUME2(N);
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1029
|
+
// AggregateBind := ('BIND' AggregateFunction | AggregateFunction) 'AS' variable
|
|
1030
|
+
aggregateBind = this.RULE("aggregateBind", () => {
|
|
1031
|
+
this.OPTION(() => {
|
|
1032
|
+
this.CONSUME(Q);
|
|
1033
|
+
}), this.SUBRULE(this.aggregateFunction), this.CONSUME(z), this.CONSUME(N);
|
|
1034
|
+
});
|
|
1035
|
+
// AggregateFunction := AggregateFunction1 | AggregateFunction2
|
|
1036
|
+
aggregateFunction = this.RULE("aggregateFunction", () => {
|
|
1037
|
+
this.OR([
|
|
1038
|
+
{ ALT: () => this.SUBRULE(this.aggregateFunction1) },
|
|
1039
|
+
{ ALT: () => this.SUBRULE(this.aggregateFunction2) }
|
|
1040
|
+
]);
|
|
1041
|
+
});
|
|
1042
|
+
// AggregateFunction1 := (SUM | MUL | AVG | MIN | COUNT_MIN | MAX | COUNT_MAX | COUNT) '(' DISTINCT? (STAR | Expression) ')'
|
|
1043
|
+
aggregateFunction1 = this.RULE("aggregateFunction1", () => {
|
|
1044
|
+
this.OR([
|
|
1045
|
+
{ ALT: () => this.CONSUME(Xt) },
|
|
1046
|
+
{ ALT: () => this.CONSUME(Ht) },
|
|
1047
|
+
{ ALT: () => this.CONSUME(Dt) },
|
|
1048
|
+
{ ALT: () => this.CONSUME(Gt) },
|
|
1049
|
+
{ ALT: () => this.CONSUME(_t) },
|
|
1050
|
+
{ ALT: () => this.CONSUME(Vt) },
|
|
1051
|
+
{ ALT: () => this.CONSUME(jt) },
|
|
1052
|
+
{ ALT: () => this.CONSUME(qt) }
|
|
1053
|
+
]), this.CONSUME(L), this.OPTION(() => {
|
|
1054
|
+
this.CONSUME(ot);
|
|
1055
|
+
}), this.OR2([{ ALT: () => this.CONSUME(pt) }, { ALT: () => this.SUBRULE(this.expression) }]), this.CONSUME(U);
|
|
1056
|
+
});
|
|
1057
|
+
// AggregateFunction2 := (MIN_ARGMIN | MAX_ARGMIN | MIN_ARGMAX | MAX_ARGMAX) '(' DISTINCT? Expression ',' Expression ')'
|
|
1058
|
+
aggregateFunction2 = this.RULE("aggregateFunction2", () => {
|
|
1059
|
+
this.OR([
|
|
1060
|
+
{ ALT: () => this.CONSUME(Qt) },
|
|
1061
|
+
{ ALT: () => this.CONSUME(zt) },
|
|
1062
|
+
{ ALT: () => this.CONSUME(Kt) },
|
|
1063
|
+
{ ALT: () => this.CONSUME(Wt) }
|
|
1064
|
+
]), this.CONSUME(L), this.OPTION(() => {
|
|
1065
|
+
this.CONSUME(ot);
|
|
1066
|
+
}), this.SUBRULE(this.expression, { LABEL: "firstExpr" }), this.CONSUME(S), this.SUBRULE2(this.expression, { LABEL: "secondExpr" }), this.CONSUME(U);
|
|
1067
|
+
});
|
|
1068
|
+
// Expression (simplified for now)
|
|
1069
|
+
expression = this.RULE("expression", () => {
|
|
1070
|
+
this.SUBRULE(this.conditionalOrExpression);
|
|
1071
|
+
});
|
|
1072
|
+
conditionalOrExpression = this.RULE("conditionalOrExpression", () => {
|
|
1073
|
+
this.SUBRULE(this.conditionalAndExpression), this.MANY(() => {
|
|
1074
|
+
this.CONSUME(he), this.SUBRULE2(this.conditionalAndExpression);
|
|
1075
|
+
});
|
|
1076
|
+
});
|
|
1077
|
+
conditionalAndExpression = this.RULE("conditionalAndExpression", () => {
|
|
1078
|
+
this.SUBRULE(this.relationalExpression), this.MANY(() => {
|
|
1079
|
+
this.CONSUME(pe), this.SUBRULE2(this.relationalExpression);
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
relationalExpression = this.RULE("relationalExpression", () => {
|
|
1083
|
+
this.SUBRULE(this.additiveExpression), this.OPTION(() => {
|
|
949
1084
|
this.OR([
|
|
950
|
-
{ ALT: () => this.CONSUME(Se) },
|
|
951
|
-
{ ALT: () => this.CONSUME(mt) }
|
|
952
|
-
]), this.OPTION(() => {
|
|
953
|
-
this.OR2([
|
|
954
|
-
{ ALT: () => this.CONSUME(Ne) },
|
|
955
|
-
{
|
|
956
|
-
ALT: () => {
|
|
957
|
-
this.CONSUME(gt), this.CONSUME2(gt), this.SUBRULE(this.iri);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
]);
|
|
961
|
-
});
|
|
962
|
-
}));
|
|
963
|
-
// Negation := 'NOT' ExistsClause? (Atom | '(' BodyFormulaList ')')
|
|
964
|
-
d(this, "negation", this.RULE("negation", () => {
|
|
965
|
-
this.CONSUME(lt), this.OPTION(() => {
|
|
966
|
-
this.SUBRULE(this.existsClause);
|
|
967
|
-
}), this.OR([
|
|
968
1085
|
{
|
|
969
1086
|
ALT: () => {
|
|
970
|
-
this.
|
|
1087
|
+
this.OR2([
|
|
1088
|
+
{ ALT: () => this.CONSUME(se) },
|
|
1089
|
+
{ ALT: () => this.CONSUME(ae) },
|
|
1090
|
+
{ ALT: () => this.CONSUME(oe) },
|
|
1091
|
+
{ ALT: () => this.CONSUME(ue) },
|
|
1092
|
+
{ ALT: () => this.CONSUME(le) },
|
|
1093
|
+
{ ALT: () => this.CONSUME(ce) }
|
|
1094
|
+
]), this.SUBRULE2(this.additiveExpression);
|
|
971
1095
|
}
|
|
972
1096
|
},
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
d(this, "existsClause", this.RULE("existsClause", () => {
|
|
978
|
-
this.CONSUME($t), this.CONSUME(b), this.MANY(() => {
|
|
979
|
-
this.CONSUME(N), this.CONSUME2(b);
|
|
980
|
-
}), this.CONSUME(Z);
|
|
981
|
-
}));
|
|
982
|
-
// AtomList := Atom (',' Atom)*
|
|
983
|
-
d(this, "atomList", this.RULE("atomList", () => {
|
|
984
|
-
this.SUBRULE(this.atom), this.MANY(() => {
|
|
985
|
-
this.CONSUME(N), this.SUBRULE2(this.atom);
|
|
986
|
-
});
|
|
987
|
-
}));
|
|
988
|
-
// Atom := TupleTableAtom | FilterAtom | BindAtom
|
|
989
|
-
d(this, "atom", this.RULE("atom", () => {
|
|
990
|
-
this.OR([
|
|
991
|
-
{ ALT: () => this.SUBRULE(this.tupleTableAtom) },
|
|
992
|
-
{ ALT: () => this.SUBRULE(this.filterAtom) },
|
|
993
|
-
{ ALT: () => this.SUBRULE(this.bindAtom) }
|
|
994
|
-
]);
|
|
995
|
-
}));
|
|
996
|
-
// BodyFormulaList := BodyFormula (',' BodyFormula)*
|
|
997
|
-
d(this, "bodyFormulaList", this.RULE("bodyFormulaList", () => {
|
|
998
|
-
this.SUBRULE(this.bodyFormula), this.MANY(() => {
|
|
999
|
-
this.CONSUME(N), this.SUBRULE2(this.bodyFormula);
|
|
1000
|
-
});
|
|
1001
|
-
}));
|
|
1002
|
-
// FilterAtom := 'FILTER' '(' Expression ')'
|
|
1003
|
-
d(this, "filterAtom", this.RULE("filterAtom", () => {
|
|
1004
|
-
this.CONSUME(Dt), this.CONSUME(U), this.SUBRULE(this.expression), this.CONSUME(w);
|
|
1005
|
-
}));
|
|
1006
|
-
// BindAtom := 'BIND' '(' Expression 'AS' variable ')'
|
|
1007
|
-
d(this, "bindAtom", this.RULE("bindAtom", () => {
|
|
1008
|
-
this.CONSUME(z), this.CONSUME(U), this.SUBRULE(this.expression), this.CONSUME(K), this.CONSUME(b), this.CONSUME(w);
|
|
1009
|
-
}));
|
|
1010
|
-
// SkolemAtom := 'SKOLEM' '(' ArgumentList ')'
|
|
1011
|
-
d(this, "skolemAtom", this.RULE("skolemAtom", () => {
|
|
1012
|
-
this.CONSUME(ct), this.CONSUME(U), this.SUBRULE(this.argumentList), this.CONSUME(w);
|
|
1013
|
-
}));
|
|
1014
|
-
// Aggregate := 'AGGREGATE' '(' AtomList OnClause? AggregateBind* ')'
|
|
1015
|
-
d(this, "aggregate", this.RULE("aggregate", () => {
|
|
1016
|
-
this.CONSUME(wt), this.CONSUME(U), this.SUBRULE(this.atomList), this.OPTION(() => {
|
|
1017
|
-
this.SUBRULE(this.onClause);
|
|
1018
|
-
}), this.MANY(() => {
|
|
1019
|
-
this.SUBRULE(this.aggregateBind);
|
|
1020
|
-
}), this.CONSUME(w);
|
|
1021
|
-
}));
|
|
1022
|
-
// OnClause := 'ON' variable+
|
|
1023
|
-
d(this, "onClause", this.RULE("onClause", () => {
|
|
1024
|
-
this.CONSUME(At), this.CONSUME(b), this.MANY(() => {
|
|
1025
|
-
this.CONSUME2(b);
|
|
1026
|
-
});
|
|
1027
|
-
}));
|
|
1028
|
-
// AggregateBind := ('BIND' AggregateFunction | AggregateFunction) 'AS' variable
|
|
1029
|
-
d(this, "aggregateBind", this.RULE("aggregateBind", () => {
|
|
1030
|
-
this.OPTION(() => {
|
|
1031
|
-
this.CONSUME(z);
|
|
1032
|
-
}), this.SUBRULE(this.aggregateFunction), this.CONSUME(K), this.CONSUME(b);
|
|
1033
|
-
}));
|
|
1034
|
-
// AggregateFunction := AggregateFunction1 | AggregateFunction2
|
|
1035
|
-
d(this, "aggregateFunction", this.RULE("aggregateFunction", () => {
|
|
1036
|
-
this.OR([
|
|
1037
|
-
{ ALT: () => this.SUBRULE(this.aggregateFunction1) },
|
|
1038
|
-
{ ALT: () => this.SUBRULE(this.aggregateFunction2) }
|
|
1039
|
-
]);
|
|
1040
|
-
}));
|
|
1041
|
-
// AggregateFunction1 := (SUM | MUL | AVG | MIN | COUNT_MIN | MAX | COUNT_MAX | COUNT) '(' DISTINCT? (STAR | Expression) ')'
|
|
1042
|
-
d(this, "aggregateFunction1", this.RULE("aggregateFunction1", () => {
|
|
1043
|
-
this.OR([
|
|
1044
|
-
{ ALT: () => this.CONSUME(Ht) },
|
|
1045
|
-
{ ALT: () => this.CONSUME(Qt) },
|
|
1046
|
-
{ ALT: () => this.CONSUME(Gt) },
|
|
1047
|
-
{ ALT: () => this.CONSUME(_t) },
|
|
1048
|
-
{ ALT: () => this.CONSUME(Vt) },
|
|
1049
|
-
{ ALT: () => this.CONSUME(jt) },
|
|
1050
|
-
{ ALT: () => this.CONSUME(qt) },
|
|
1051
|
-
{ ALT: () => this.CONSUME(Xt) }
|
|
1052
|
-
]), this.CONSUME(U), this.OPTION(() => {
|
|
1053
|
-
this.CONSUME(ut);
|
|
1054
|
-
}), this.OR2([{ ALT: () => this.CONSUME(dt) }, { ALT: () => this.SUBRULE(this.expression) }]), this.CONSUME(w);
|
|
1055
|
-
}));
|
|
1056
|
-
// AggregateFunction2 := (MIN_ARGMIN | MAX_ARGMIN | MIN_ARGMAX | MAX_ARGMAX) '(' DISTINCT? Expression ',' Expression ')'
|
|
1057
|
-
d(this, "aggregateFunction2", this.RULE("aggregateFunction2", () => {
|
|
1058
|
-
this.OR([
|
|
1059
|
-
{ ALT: () => this.CONSUME(zt) },
|
|
1060
|
-
{ ALT: () => this.CONSUME(Kt) },
|
|
1061
|
-
{ ALT: () => this.CONSUME(Wt) },
|
|
1062
|
-
{ ALT: () => this.CONSUME(Yt) }
|
|
1063
|
-
]), this.CONSUME(U), this.OPTION(() => {
|
|
1064
|
-
this.CONSUME(ut);
|
|
1065
|
-
}), this.SUBRULE(this.expression, { LABEL: "firstExpr" }), this.CONSUME(N), this.SUBRULE2(this.expression, { LABEL: "secondExpr" }), this.CONSUME(w);
|
|
1066
|
-
}));
|
|
1067
|
-
// Expression (simplified for now)
|
|
1068
|
-
d(this, "expression", this.RULE("expression", () => {
|
|
1069
|
-
this.SUBRULE(this.conditionalOrExpression);
|
|
1070
|
-
}));
|
|
1071
|
-
d(this, "conditionalOrExpression", this.RULE("conditionalOrExpression", () => {
|
|
1072
|
-
this.SUBRULE(this.conditionalAndExpression), this.MANY(() => {
|
|
1073
|
-
this.CONSUME(de), this.SUBRULE2(this.conditionalAndExpression);
|
|
1074
|
-
});
|
|
1075
|
-
}));
|
|
1076
|
-
d(this, "conditionalAndExpression", this.RULE("conditionalAndExpression", () => {
|
|
1077
|
-
this.SUBRULE(this.relationalExpression), this.MANY(() => {
|
|
1078
|
-
this.CONSUME(he), this.SUBRULE2(this.relationalExpression);
|
|
1079
|
-
});
|
|
1080
|
-
}));
|
|
1081
|
-
d(this, "relationalExpression", this.RULE("relationalExpression", () => {
|
|
1082
|
-
this.SUBRULE(this.additiveExpression), this.OPTION(() => {
|
|
1083
|
-
this.OR([
|
|
1084
|
-
{
|
|
1085
|
-
ALT: () => {
|
|
1086
|
-
this.OR2([
|
|
1087
|
-
{ ALT: () => this.CONSUME(ae) },
|
|
1088
|
-
{ ALT: () => this.CONSUME(oe) },
|
|
1089
|
-
{ ALT: () => this.CONSUME(le) },
|
|
1090
|
-
{ ALT: () => this.CONSUME(ce) },
|
|
1091
|
-
{ ALT: () => this.CONSUME(ue) },
|
|
1092
|
-
{ ALT: () => this.CONSUME(pe) }
|
|
1093
|
-
]), this.SUBRULE2(this.additiveExpression);
|
|
1094
|
-
}
|
|
1095
|
-
},
|
|
1096
|
-
// Handle IN
|
|
1097
|
-
{
|
|
1098
|
-
ALT: () => {
|
|
1099
|
-
this.CONSUME(Z), this.CONSUME2(U), this.SUBRULE(this.argumentList), this.CONSUME3(w);
|
|
1100
|
-
}
|
|
1101
|
-
},
|
|
1102
|
-
// Handle NOT IN
|
|
1103
|
-
{
|
|
1104
|
-
ALT: () => {
|
|
1105
|
-
this.CONSUME(lt), this.CONSUME2(Z), this.CONSUME4(U), this.SUBRULE2(this.argumentList), this.CONSUME5(w);
|
|
1106
|
-
}
|
|
1097
|
+
// Handle IN
|
|
1098
|
+
{
|
|
1099
|
+
ALT: () => {
|
|
1100
|
+
this.CONSUME(W), this.CONSUME2(L), this.SUBRULE(this.argumentList), this.CONSUME3(U);
|
|
1107
1101
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
}));
|
|
1111
|
-
d(this, "additiveExpression", this.RULE("additiveExpression", () => {
|
|
1112
|
-
this.SUBRULE(this.multiplicativeExpression), this.MANY(() => {
|
|
1113
|
-
this.OR([{ ALT: () => this.CONSUME(pt) }, { ALT: () => this.CONSUME(ht) }]), this.SUBRULE2(this.multiplicativeExpression);
|
|
1114
|
-
});
|
|
1115
|
-
}));
|
|
1116
|
-
d(this, "multiplicativeExpression", this.RULE("multiplicativeExpression", () => {
|
|
1117
|
-
this.SUBRULE(this.unaryExpression), this.MANY(() => {
|
|
1118
|
-
this.OR([{ ALT: () => this.CONSUME(dt) }, { ALT: () => this.CONSUME(Ee) }]), this.SUBRULE2(this.unaryExpression);
|
|
1119
|
-
});
|
|
1120
|
-
}));
|
|
1121
|
-
d(this, "unaryExpression", this.RULE("unaryExpression", () => {
|
|
1122
|
-
this.OPTION(() => {
|
|
1123
|
-
this.OR([
|
|
1124
|
-
{ ALT: () => this.CONSUME(fe) },
|
|
1125
|
-
{ ALT: () => this.CONSUME(pt) },
|
|
1126
|
-
{ ALT: () => this.CONSUME(ht) }
|
|
1127
|
-
]);
|
|
1128
|
-
}), this.SUBRULE(this.primaryExpression);
|
|
1129
|
-
}));
|
|
1130
|
-
// Function calls
|
|
1131
|
-
d(this, "functionCall", this.RULE("functionCall", () => {
|
|
1132
|
-
this.OR([
|
|
1133
|
-
// Built-in functions
|
|
1134
|
-
{ ALT: () => this.SUBRULE(this.concatFunction) },
|
|
1135
|
-
{ ALT: () => this.SUBRULE(this.strFunction) },
|
|
1136
|
-
{ ALT: () => this.SUBRULE(this.ifFunction) },
|
|
1137
|
-
{ ALT: () => this.SUBRULE(this.iriFunction) },
|
|
1138
|
-
{ ALT: () => this.SUBRULE(this.skolemFunction) },
|
|
1139
|
-
{ ALT: () => this.SUBRULE(this.roundFunction) },
|
|
1140
|
-
{ ALT: () => this.SUBRULE(this.regexFunction) },
|
|
1141
|
-
// Generic function call (IRI followed by arguments)
|
|
1102
|
+
},
|
|
1103
|
+
// Handle NOT IN
|
|
1142
1104
|
{
|
|
1143
1105
|
ALT: () => {
|
|
1144
|
-
this.
|
|
1145
|
-
this.SUBRULE(this.argumentList);
|
|
1146
|
-
}), this.CONSUME(w);
|
|
1106
|
+
this.CONSUME(at), this.CONSUME2(W), this.CONSUME4(L), this.SUBRULE2(this.argumentList), this.CONSUME5(U);
|
|
1147
1107
|
}
|
|
1148
1108
|
}
|
|
1149
1109
|
]);
|
|
1150
|
-
})
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
d(this, "iriFunction", this.RULE("iriFunction", () => {
|
|
1165
|
-
this.CONSUME(ee), this.CONSUME(U), this.SUBRULE(this.expression, { LABEL: "iriExpr" }), this.OPTION(() => {
|
|
1166
|
-
this.CONSUME(N), this.SUBRULE2(this.expression, { LABEL: "baseIri" });
|
|
1167
|
-
}), this.CONSUME(w);
|
|
1168
|
-
}));
|
|
1169
|
-
// SKOLEM function
|
|
1170
|
-
d(this, "skolemFunction", this.RULE("skolemFunction", () => {
|
|
1171
|
-
this.CONSUME(ct), this.CONSUME(U), this.SUBRULE(this.argumentList), this.CONSUME(w);
|
|
1172
|
-
}));
|
|
1173
|
-
// ROUND function
|
|
1174
|
-
d(this, "roundFunction", this.RULE("roundFunction", () => {
|
|
1175
|
-
this.CONSUME(re), this.CONSUME(U), this.SUBRULE(this.expression), this.CONSUME(w);
|
|
1176
|
-
}));
|
|
1177
|
-
// REGEX function
|
|
1178
|
-
d(this, "regexFunction", this.RULE("regexFunction", () => {
|
|
1179
|
-
this.CONSUME(ie), this.CONSUME(U), this.SUBRULE(this.expression, { LABEL: "textExpr" }), this.CONSUME(N), this.SUBRULE2(this.expression, { LABEL: "patternExpr" }), this.OPTION(() => {
|
|
1180
|
-
this.CONSUME2(N), this.SUBRULE3(this.expression, { LABEL: "flagsExpr" });
|
|
1181
|
-
}), this.CONSUME(w);
|
|
1182
|
-
}));
|
|
1183
|
-
// Argument list
|
|
1184
|
-
d(this, "argumentList", this.RULE("argumentList", () => {
|
|
1185
|
-
this.SUBRULE(this.expression), this.MANY(() => {
|
|
1186
|
-
this.CONSUME(N), this.SUBRULE2(this.expression);
|
|
1187
|
-
});
|
|
1188
|
-
}));
|
|
1189
|
-
d(this, "primaryExpression", this.RULE("primaryExpression", () => {
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
additiveExpression = this.RULE("additiveExpression", () => {
|
|
1113
|
+
this.SUBRULE(this.multiplicativeExpression), this.MANY(() => {
|
|
1114
|
+
this.OR([{ ALT: () => this.CONSUME(ut) }, { ALT: () => this.CONSUME(ct) }]), this.SUBRULE2(this.multiplicativeExpression);
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
multiplicativeExpression = this.RULE("multiplicativeExpression", () => {
|
|
1118
|
+
this.SUBRULE(this.unaryExpression), this.MANY(() => {
|
|
1119
|
+
this.OR([{ ALT: () => this.CONSUME(pt) }, { ALT: () => this.CONSUME(de) }]), this.SUBRULE2(this.unaryExpression);
|
|
1120
|
+
});
|
|
1121
|
+
});
|
|
1122
|
+
unaryExpression = this.RULE("unaryExpression", () => {
|
|
1123
|
+
this.OPTION(() => {
|
|
1190
1124
|
this.OR([
|
|
1191
|
-
{
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
}
|
|
1195
|
-
},
|
|
1196
|
-
{ ALT: () => this.SUBRULE(this.functionCall) },
|
|
1197
|
-
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1198
|
-
{ ALT: () => this.CONSUME(b) },
|
|
1199
|
-
{ ALT: () => this.SUBRULE(this.iri) }
|
|
1125
|
+
{ ALT: () => this.CONSUME(Ee) },
|
|
1126
|
+
{ ALT: () => this.CONSUME(ut) },
|
|
1127
|
+
{ ALT: () => this.CONSUME(ct) }
|
|
1200
1128
|
]);
|
|
1201
|
-
}));
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1129
|
+
}), this.SUBRULE(this.primaryExpression);
|
|
1130
|
+
});
|
|
1131
|
+
// Function calls
|
|
1132
|
+
functionCall = this.RULE("functionCall", () => {
|
|
1133
|
+
this.OR([
|
|
1134
|
+
// Built-in functions
|
|
1135
|
+
{ ALT: () => this.SUBRULE(this.concatFunction) },
|
|
1136
|
+
{ ALT: () => this.SUBRULE(this.strFunction) },
|
|
1137
|
+
{ ALT: () => this.SUBRULE(this.ifFunction) },
|
|
1138
|
+
{ ALT: () => this.SUBRULE(this.iriFunction) },
|
|
1139
|
+
{ ALT: () => this.SUBRULE(this.skolemFunction) },
|
|
1140
|
+
{ ALT: () => this.SUBRULE(this.roundFunction) },
|
|
1141
|
+
{ ALT: () => this.SUBRULE(this.regexFunction) },
|
|
1142
|
+
// Generic function call (IRI followed by arguments)
|
|
1143
|
+
{
|
|
1144
|
+
ALT: () => {
|
|
1145
|
+
this.SUBRULE(this.iri), this.CONSUME(L), this.OPTION(() => {
|
|
1146
|
+
this.SUBRULE(this.argumentList);
|
|
1147
|
+
}), this.CONSUME(U);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
]);
|
|
1151
|
+
});
|
|
1152
|
+
// CONCAT function
|
|
1153
|
+
concatFunction = this.RULE("concatFunction", () => {
|
|
1154
|
+
this.CONSUME(Yt), this.CONSUME(L), this.SUBRULE(this.argumentList), this.CONSUME(U);
|
|
1155
|
+
});
|
|
1156
|
+
// STR function
|
|
1157
|
+
strFunction = this.RULE("strFunction", () => {
|
|
1158
|
+
this.CONSUME(Zt), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(U);
|
|
1159
|
+
});
|
|
1160
|
+
// IF function
|
|
1161
|
+
ifFunction = this.RULE("ifFunction", () => {
|
|
1162
|
+
this.CONSUME(Jt), this.CONSUME(L), this.SUBRULE(this.expression, { LABEL: "condition" }), this.CONSUME(S), this.SUBRULE2(this.expression, { LABEL: "thenExpr" }), this.CONSUME2(S), this.SUBRULE3(this.expression, { LABEL: "elseExpr" }), this.CONSUME(U);
|
|
1163
|
+
});
|
|
1164
|
+
// IRI function
|
|
1165
|
+
iriFunction = this.RULE("iriFunction", () => {
|
|
1166
|
+
this.CONSUME(te), this.CONSUME(L), this.SUBRULE(this.expression, { LABEL: "iriExpr" }), this.OPTION(() => {
|
|
1167
|
+
this.CONSUME(S), this.SUBRULE2(this.expression, { LABEL: "baseIri" });
|
|
1168
|
+
}), this.CONSUME(U);
|
|
1169
|
+
});
|
|
1170
|
+
// SKOLEM function
|
|
1171
|
+
skolemFunction = this.RULE("skolemFunction", () => {
|
|
1172
|
+
this.CONSUME(lt), this.CONSUME(L), this.SUBRULE(this.argumentList), this.CONSUME(U);
|
|
1173
|
+
});
|
|
1174
|
+
// ROUND function
|
|
1175
|
+
roundFunction = this.RULE("roundFunction", () => {
|
|
1176
|
+
this.CONSUME(ee), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(U);
|
|
1177
|
+
});
|
|
1178
|
+
// REGEX function
|
|
1179
|
+
regexFunction = this.RULE("regexFunction", () => {
|
|
1180
|
+
this.CONSUME(re), this.CONSUME(L), this.SUBRULE(this.expression, { LABEL: "textExpr" }), this.CONSUME(S), this.SUBRULE2(this.expression, { LABEL: "patternExpr" }), this.OPTION(() => {
|
|
1181
|
+
this.CONSUME2(S), this.SUBRULE3(this.expression, { LABEL: "flagsExpr" });
|
|
1182
|
+
}), this.CONSUME(U);
|
|
1183
|
+
});
|
|
1184
|
+
// Argument list
|
|
1185
|
+
argumentList = this.RULE("argumentList", () => {
|
|
1186
|
+
this.SUBRULE(this.expression), this.MANY(() => {
|
|
1187
|
+
this.CONSUME(S), this.SUBRULE2(this.expression);
|
|
1188
|
+
});
|
|
1189
|
+
});
|
|
1190
|
+
primaryExpression = this.RULE("primaryExpression", () => {
|
|
1191
|
+
this.OR([
|
|
1192
|
+
{
|
|
1193
|
+
ALT: () => {
|
|
1194
|
+
this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(U);
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
{ ALT: () => this.SUBRULE(this.functionCall) },
|
|
1198
|
+
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1199
|
+
{ ALT: () => this.CONSUME(N) },
|
|
1200
|
+
{ ALT: () => this.SUBRULE(this.iri) }
|
|
1201
|
+
]);
|
|
1202
|
+
});
|
|
1210
1203
|
}
|
|
1211
|
-
let
|
|
1212
|
-
function
|
|
1213
|
-
return
|
|
1204
|
+
let Ri;
|
|
1205
|
+
function xe() {
|
|
1206
|
+
return Ri ??= new Oe();
|
|
1214
1207
|
}
|
|
1215
|
-
function
|
|
1216
|
-
const r =
|
|
1208
|
+
function lr(e, t) {
|
|
1209
|
+
const r = Re(t);
|
|
1217
1210
|
if (r) throw new Error(r.message);
|
|
1218
|
-
const i =
|
|
1211
|
+
const i = Ne(t);
|
|
1219
1212
|
if (i.errors.length > 0)
|
|
1220
|
-
throw new Error(`Lexer errors: ${i.errors.map((
|
|
1221
|
-
const s =
|
|
1213
|
+
throw new Error(`Lexer errors: ${i.errors.map((a) => a.message).join(", ")}`);
|
|
1214
|
+
const s = be(t, i.tokens);
|
|
1222
1215
|
if (s) throw new Error(s.message);
|
|
1223
1216
|
e.input = i.tokens;
|
|
1224
|
-
const
|
|
1217
|
+
const o = e.rule();
|
|
1225
1218
|
if (e.errors.length > 0)
|
|
1226
|
-
throw new Error(`Parser errors: ${e.errors.map((
|
|
1227
|
-
return
|
|
1219
|
+
throw new Error(`Parser errors: ${e.errors.map((a) => a.message).join(", ")}`);
|
|
1220
|
+
return o;
|
|
1228
1221
|
}
|
|
1229
|
-
function
|
|
1230
|
-
return
|
|
1222
|
+
function ur(e) {
|
|
1223
|
+
return lr(xe(), e);
|
|
1231
1224
|
}
|
|
1232
|
-
function
|
|
1225
|
+
function Es(e) {
|
|
1233
1226
|
try {
|
|
1234
|
-
return
|
|
1227
|
+
return ur(e), { valid: !0 };
|
|
1235
1228
|
} catch (t) {
|
|
1236
1229
|
return {
|
|
1237
1230
|
valid: !1,
|
|
@@ -1239,137 +1232,136 @@ function ys(e) {
|
|
|
1239
1232
|
};
|
|
1240
1233
|
}
|
|
1241
1234
|
}
|
|
1242
|
-
class
|
|
1235
|
+
class bi extends Oe {
|
|
1243
1236
|
constructor() {
|
|
1244
|
-
super({ selfAnalysis: !1 });
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
// Grounding substitutes the grouping variables as well, and an aggregate
|
|
1256
|
-
// over the whole store comes back with a bare 'ON', so both are accepted.
|
|
1257
|
-
d(this, "expandedOnClause", this.OVERRIDE_RULE("onClause", () => {
|
|
1258
|
-
this.CONSUME(At), this.MANY(() => {
|
|
1259
|
-
this.variableOrGroundedTarget();
|
|
1260
|
-
});
|
|
1261
|
-
}));
|
|
1262
|
-
// BindAtom := 'BIND' '(' Expression 'AS' (variable | GroundedAsTarget) ')'
|
|
1263
|
-
d(this, "expandedBindAtom", this.OVERRIDE_RULE("bindAtom", () => {
|
|
1264
|
-
this.CONSUME(z), this.CONSUME(U), this.SUBRULE(this.expression), this.CONSUME(K), this.variableOrGroundedTarget(), this.CONSUME(w);
|
|
1265
|
-
}));
|
|
1266
|
-
// Aggregate := 'AGGREGATE' '(' AtomList? OnClause? AggregateBind* ')'
|
|
1267
|
-
// atomList is optional so engine-emitted atom-free forms parse; empty
|
|
1268
|
-
// `AGGREGATE()` / `AGGREGATE(ON ?x)` are rejected after parse (visitor).
|
|
1269
|
-
d(this, "expandedAggregate", this.OVERRIDE_RULE("aggregate", () => {
|
|
1270
|
-
this.CONSUME(wt), this.CONSUME(U), this.OPTION(() => {
|
|
1271
|
-
this.SUBRULE(this.atomList);
|
|
1272
|
-
}), this.OPTION2(() => {
|
|
1273
|
-
this.SUBRULE(this.onClause);
|
|
1274
|
-
}), this.MANY(() => {
|
|
1275
|
-
this.SUBRULE(this.aggregateBind);
|
|
1276
|
-
}), this.CONSUME(w);
|
|
1277
|
-
}));
|
|
1278
|
-
// AggregateBind := 'BIND'? (AggregateFunction | Expression) 'AS' (variable | GroundedAsTarget)
|
|
1279
|
-
d(this, "expandedAggregateBind", this.OVERRIDE_RULE("aggregateBind", () => {
|
|
1280
|
-
this.OPTION(() => {
|
|
1281
|
-
this.CONSUME(z);
|
|
1282
|
-
}), this.OR2([{ ALT: () => this.SUBRULE(this.aggregateFunction) }, { ALT: () => this.SUBRULE(this.expression) }]), this.CONSUME(K), this.variableOrGroundedTarget();
|
|
1283
|
-
}));
|
|
1284
|
-
// Grounding substitutes SKOLEM outputs into expression positions as blank
|
|
1285
|
-
// nodes, so the expanded grammar accepts them as primary expressions.
|
|
1286
|
-
d(this, "expandedPrimaryExpression", this.OVERRIDE_RULE("primaryExpression", () => {
|
|
1287
|
-
this.OR([
|
|
1288
|
-
{
|
|
1289
|
-
ALT: () => {
|
|
1290
|
-
this.CONSUME(U), this.SUBRULE(this.expression), this.CONSUME(w);
|
|
1291
|
-
}
|
|
1292
|
-
},
|
|
1293
|
-
{ ALT: () => this.SUBRULE(this.functionCall) },
|
|
1294
|
-
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1295
|
-
{ ALT: () => this.CONSUME(b) },
|
|
1296
|
-
{ ALT: () => this.CONSUME(et) },
|
|
1297
|
-
{ ALT: () => this.SUBRULE(this.iri) }
|
|
1298
|
-
]);
|
|
1299
|
-
}));
|
|
1300
|
-
this.performSelfAnalysis();
|
|
1301
|
-
}
|
|
1237
|
+
super({ selfAnalysis: !1 }), this.performSelfAnalysis();
|
|
1238
|
+
}
|
|
1239
|
+
// `term` cannot be used directly as the alternative to a variable: its own
|
|
1240
|
+
// first alternative is VARIABLE, which would make the enclosing OR ambiguous.
|
|
1241
|
+
groundedAsTarget = this.RULE("groundedAsTarget", () => {
|
|
1242
|
+
this.OR([
|
|
1243
|
+
{ ALT: () => this.SUBRULE(this.iri) },
|
|
1244
|
+
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1245
|
+
{ ALT: () => this.CONSUME(J) }
|
|
1246
|
+
]);
|
|
1247
|
+
});
|
|
1302
1248
|
// Each rule below records this once, so the default occurrence index is unambiguous.
|
|
1303
1249
|
variableOrGroundedTarget() {
|
|
1304
|
-
this.OR([{ ALT: () => this.CONSUME(
|
|
1305
|
-
}
|
|
1250
|
+
this.OR([{ ALT: () => this.CONSUME(N) }, { ALT: () => this.SUBRULE(this.groundedAsTarget) }]);
|
|
1251
|
+
}
|
|
1252
|
+
// OnClause := 'ON' (variable | GroundedAsTarget)*
|
|
1253
|
+
// Grounding substitutes the grouping variables as well, and an aggregate
|
|
1254
|
+
// over the whole store comes back with a bare 'ON', so both are accepted.
|
|
1255
|
+
expandedOnClause = this.OVERRIDE_RULE("onClause", () => {
|
|
1256
|
+
this.CONSUME(Ut), this.MANY(() => {
|
|
1257
|
+
this.variableOrGroundedTarget();
|
|
1258
|
+
});
|
|
1259
|
+
});
|
|
1260
|
+
// BindAtom := 'BIND' '(' Expression 'AS' (variable | GroundedAsTarget) ')'
|
|
1261
|
+
expandedBindAtom = this.OVERRIDE_RULE("bindAtom", () => {
|
|
1262
|
+
this.CONSUME(Q), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(z), this.variableOrGroundedTarget(), this.CONSUME(U);
|
|
1263
|
+
});
|
|
1264
|
+
// Aggregate := 'AGGREGATE' '(' AtomList? OnClause? AggregateBind* ')'
|
|
1265
|
+
// atomList is optional so engine-emitted atom-free forms parse; empty
|
|
1266
|
+
// `AGGREGATE()` / `AGGREGATE(ON ?x)` are rejected after parse (visitor).
|
|
1267
|
+
expandedAggregate = this.OVERRIDE_RULE("aggregate", () => {
|
|
1268
|
+
this.CONSUME(Lt), this.CONSUME(L), this.OPTION(() => {
|
|
1269
|
+
this.SUBRULE(this.atomList);
|
|
1270
|
+
}), this.OPTION2(() => {
|
|
1271
|
+
this.SUBRULE(this.onClause);
|
|
1272
|
+
}), this.MANY(() => {
|
|
1273
|
+
this.SUBRULE(this.aggregateBind);
|
|
1274
|
+
}), this.CONSUME(U);
|
|
1275
|
+
});
|
|
1276
|
+
// AggregateBind := 'BIND'? (AggregateFunction | Expression) 'AS' (variable | GroundedAsTarget)
|
|
1277
|
+
expandedAggregateBind = this.OVERRIDE_RULE("aggregateBind", () => {
|
|
1278
|
+
this.OPTION(() => {
|
|
1279
|
+
this.CONSUME(Q);
|
|
1280
|
+
}), this.OR2([{ ALT: () => this.SUBRULE(this.aggregateFunction) }, { ALT: () => this.SUBRULE(this.expression) }]), this.CONSUME(z), this.variableOrGroundedTarget();
|
|
1281
|
+
});
|
|
1282
|
+
// Grounding substitutes SKOLEM outputs into expression positions as blank
|
|
1283
|
+
// nodes, so the expanded grammar accepts them as primary expressions.
|
|
1284
|
+
expandedPrimaryExpression = this.OVERRIDE_RULE("primaryExpression", () => {
|
|
1285
|
+
this.OR([
|
|
1286
|
+
{
|
|
1287
|
+
ALT: () => {
|
|
1288
|
+
this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(U);
|
|
1289
|
+
}
|
|
1290
|
+
},
|
|
1291
|
+
{ ALT: () => this.SUBRULE(this.functionCall) },
|
|
1292
|
+
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1293
|
+
{ ALT: () => this.CONSUME(N) },
|
|
1294
|
+
{ ALT: () => this.CONSUME(J) },
|
|
1295
|
+
{ ALT: () => this.SUBRULE(this.iri) }
|
|
1296
|
+
]);
|
|
1297
|
+
});
|
|
1306
1298
|
}
|
|
1307
|
-
let
|
|
1308
|
-
function
|
|
1309
|
-
return
|
|
1299
|
+
let Oi;
|
|
1300
|
+
function xi() {
|
|
1301
|
+
return Oi ??= new bi();
|
|
1310
1302
|
}
|
|
1311
|
-
function
|
|
1312
|
-
return
|
|
1303
|
+
function vi(e) {
|
|
1304
|
+
return lr(xi(), e);
|
|
1313
1305
|
}
|
|
1314
|
-
function
|
|
1315
|
-
|
|
1316
|
-
const t = e.body.filter((s) => s.type !== "negation"), r =
|
|
1317
|
-
(s) => p(s).with({ type:
|
|
1318
|
-
) : t, { query: i } =
|
|
1306
|
+
function Ci(e) {
|
|
1307
|
+
ir(e.body);
|
|
1308
|
+
const t = e.body.filter((s) => s.type !== "negation"), r = We(e.body) ? t.filter(
|
|
1309
|
+
(s) => p(s).with({ type: l.union("triple", "property", "class") }, () => !0).otherwise(() => !1)
|
|
1310
|
+
) : t, { query: i } = fi(r);
|
|
1319
1311
|
return `${i}
|
|
1320
1312
|
LIMIT 1`;
|
|
1321
1313
|
}
|
|
1322
|
-
function
|
|
1323
|
-
return p(e).with({ type: "variable" }, (t) => `?${t.name}`).with({ type: "iri", value: "a" }, () => "rdf:type").with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", language:
|
|
1314
|
+
function fs(e) {
|
|
1315
|
+
return p(e).with({ type: "variable" }, (t) => `?${t.name}`).with({ type: "iri", value: "a" }, () => "rdf:type").with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", language: l.string }, (t) => `"${t.value}"@${t.language}`).with({ type: "literal", datatype: l.string }, (t) => `"${t.value}"^^${er(t.datatype)}`).with({ type: "literal" }, (t) => `"${t.value}"`).with({ type: "blank" }, (t) => `_:${t.label}`).exhaustive();
|
|
1324
1316
|
}
|
|
1325
|
-
function
|
|
1317
|
+
function Ii(e) {
|
|
1326
1318
|
const t = e.head[0];
|
|
1327
1319
|
return t ? p(t).with({ type: "triple" }, (r) => ({
|
|
1328
|
-
subject:
|
|
1329
|
-
predicate:
|
|
1330
|
-
object:
|
|
1320
|
+
subject: G(r.subject),
|
|
1321
|
+
predicate: G(r.predicate),
|
|
1322
|
+
object: G(r.object)
|
|
1331
1323
|
})).with({ type: "property" }, (r) => ({
|
|
1332
|
-
subject:
|
|
1324
|
+
subject: G(r.subject),
|
|
1333
1325
|
predicate: r.predicate,
|
|
1334
|
-
object:
|
|
1326
|
+
object: G(r.object)
|
|
1335
1327
|
})).with({ type: "class" }, (r) => ({
|
|
1336
|
-
subject:
|
|
1328
|
+
subject: G(r.instance),
|
|
1337
1329
|
predicate: "rdf:type",
|
|
1338
1330
|
object: r.className
|
|
1339
1331
|
})).with({ type: "general" }, () => null).exhaustive() : null;
|
|
1340
1332
|
}
|
|
1341
|
-
function
|
|
1342
|
-
return p(e).with({ type: "variable" }, (t) => `:test_${t.name}`).with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", datatype:
|
|
1333
|
+
function G(e) {
|
|
1334
|
+
return p(e).with({ type: "variable" }, (t) => `:test_${t.name}`).with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", datatype: l.string }, (t) => `"${t.value}"^^${t.datatype}`).with({ type: "literal" }, (t) => `"${t.value}"`).with({ type: "blank" }, (t) => `_:${t.label}`).exhaustive();
|
|
1343
1335
|
}
|
|
1344
|
-
const
|
|
1345
|
-
results:
|
|
1346
|
-
bindings:
|
|
1336
|
+
const Mi = j.object({
|
|
1337
|
+
results: j.object({
|
|
1338
|
+
bindings: j.array(j.unknown())
|
|
1347
1339
|
})
|
|
1348
|
-
}),
|
|
1349
|
-
boolean:
|
|
1340
|
+
}), Bi = j.object({
|
|
1341
|
+
boolean: j.boolean()
|
|
1350
1342
|
});
|
|
1351
|
-
async function
|
|
1352
|
-
if (
|
|
1343
|
+
async function gs(e, t, r, i, s) {
|
|
1344
|
+
if (We(e.body) && !s)
|
|
1353
1345
|
return {
|
|
1354
1346
|
verified: !1,
|
|
1355
1347
|
error: "Rules containing SKOLEM require a concrete test triple for inference verification"
|
|
1356
1348
|
};
|
|
1357
1349
|
try {
|
|
1358
|
-
const
|
|
1359
|
-
if (!
|
|
1350
|
+
const a = s || Ii(e);
|
|
1351
|
+
if (!a)
|
|
1360
1352
|
return {
|
|
1361
1353
|
verified: !1,
|
|
1362
1354
|
error: "Could not generate test triple from rule head"
|
|
1363
1355
|
};
|
|
1364
|
-
const
|
|
1365
|
-
if (
|
|
1356
|
+
const u = Ci(e), f = await Fi(u, t, r, i);
|
|
1357
|
+
if (f)
|
|
1366
1358
|
return {
|
|
1367
1359
|
verified: !1,
|
|
1368
|
-
testTriple:
|
|
1369
|
-
candidateQuery:
|
|
1370
|
-
error:
|
|
1360
|
+
testTriple: a,
|
|
1361
|
+
candidateQuery: u,
|
|
1362
|
+
error: f
|
|
1371
1363
|
};
|
|
1372
|
-
const y =
|
|
1364
|
+
const y = Pi(a), m = new URL(`datastores/${r}/sparql`, t), h = await fetch(m.toString(), {
|
|
1373
1365
|
method: "POST",
|
|
1374
1366
|
headers: {
|
|
1375
1367
|
Authorization: i,
|
|
@@ -1381,22 +1373,22 @@ async function Us(e, t, r, i, s) {
|
|
|
1381
1373
|
if (!h.ok)
|
|
1382
1374
|
throw new Error(`SPARQL query failed: ${h.status} - ${await h.text()}`);
|
|
1383
1375
|
return {
|
|
1384
|
-
verified:
|
|
1385
|
-
testTriple:
|
|
1376
|
+
verified: Bi.parse(await h.json()).boolean,
|
|
1377
|
+
testTriple: a,
|
|
1386
1378
|
sparqlQuery: y,
|
|
1387
|
-
candidateQuery:
|
|
1379
|
+
candidateQuery: u
|
|
1388
1380
|
};
|
|
1389
|
-
} catch (
|
|
1381
|
+
} catch (a) {
|
|
1390
1382
|
return {
|
|
1391
1383
|
verified: !1,
|
|
1392
1384
|
testTriple: s,
|
|
1393
|
-
error:
|
|
1385
|
+
error: a instanceof Error ? a.message : "Unknown error during inference verification"
|
|
1394
1386
|
};
|
|
1395
1387
|
}
|
|
1396
1388
|
}
|
|
1397
|
-
async function
|
|
1389
|
+
async function Fi(e, t, r, i) {
|
|
1398
1390
|
try {
|
|
1399
|
-
const s = new URL(`datastores/${r}/sparql`, t),
|
|
1391
|
+
const s = new URL(`datastores/${r}/sparql`, t), o = await fetch(s.toString(), {
|
|
1400
1392
|
method: "POST",
|
|
1401
1393
|
headers: {
|
|
1402
1394
|
Authorization: i,
|
|
@@ -1405,21 +1397,21 @@ async function $i(e, t, r, i) {
|
|
|
1405
1397
|
},
|
|
1406
1398
|
body: e
|
|
1407
1399
|
});
|
|
1408
|
-
if (!
|
|
1409
|
-
let
|
|
1400
|
+
if (!o.ok) {
|
|
1401
|
+
let u = "";
|
|
1410
1402
|
try {
|
|
1411
|
-
|
|
1403
|
+
u = await o.text();
|
|
1412
1404
|
} catch {
|
|
1413
1405
|
}
|
|
1414
|
-
const
|
|
1415
|
-
return `Candidate query failed: ${
|
|
1406
|
+
const f = u || o.statusText;
|
|
1407
|
+
return `Candidate query failed: ${o.status}${f ? ` - ${f}` : ""}`;
|
|
1416
1408
|
}
|
|
1417
|
-
return
|
|
1409
|
+
return Mi.parse(await o.json()).results.bindings.length > 0 ? void 0 : "No candidate variable bindings found for rule body - rule cannot fire";
|
|
1418
1410
|
} catch (s) {
|
|
1419
1411
|
return `Candidate query failed: ${s instanceof Error ? s.message : "Unknown error"}`;
|
|
1420
1412
|
}
|
|
1421
1413
|
}
|
|
1422
|
-
function
|
|
1414
|
+
function Pi(e) {
|
|
1423
1415
|
return `
|
|
1424
1416
|
ASK WHERE {
|
|
1425
1417
|
${e.subject} ${e.predicate} ${e.object} .
|
|
@@ -1429,8 +1421,8 @@ function Di(e) {
|
|
|
1429
1421
|
}
|
|
1430
1422
|
`.trim();
|
|
1431
1423
|
}
|
|
1432
|
-
function
|
|
1433
|
-
return p(e).with({ verified: !0 }, () => "Inference verification succeeded").with({ error:
|
|
1424
|
+
function ms(e) {
|
|
1425
|
+
return p(e).with({ verified: !0 }, () => "Inference verification succeeded").with({ error: l.string }, (t) => t.error).with({ testTriple: l.nullish }, () => "Could not determine what triple should be inferred by this rule").with({ testTriple: l.not(l.nullish) }, (t) => {
|
|
1434
1426
|
const { subject: r, predicate: i, object: s } = t.testTriple;
|
|
1435
1427
|
return `Expected inference was not produced:
|
|
1436
1428
|
|
|
@@ -1449,48 +1441,48 @@ To debug:
|
|
|
1449
1441
|
4. Test rule components individually`;
|
|
1450
1442
|
}).exhaustive();
|
|
1451
1443
|
}
|
|
1452
|
-
const
|
|
1453
|
-
function
|
|
1444
|
+
const ki = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
|
|
1445
|
+
function cr() {
|
|
1454
1446
|
return { classes: [], predicates: [] };
|
|
1455
1447
|
}
|
|
1456
|
-
function
|
|
1448
|
+
function gt(e) {
|
|
1457
1449
|
return {
|
|
1458
1450
|
classes: e.flatMap(({ classes: t }) => t),
|
|
1459
1451
|
predicates: e.flatMap(({ predicates: t }) => t)
|
|
1460
1452
|
};
|
|
1461
1453
|
}
|
|
1462
|
-
function
|
|
1463
|
-
return e === "a" || e === "rdf:type" || e ===
|
|
1454
|
+
function $i(e) {
|
|
1455
|
+
return e === "a" || e === "rdf:type" || e === ki;
|
|
1464
1456
|
}
|
|
1465
|
-
function
|
|
1466
|
-
const t =
|
|
1457
|
+
function pr(e) {
|
|
1458
|
+
const t = Ye(e);
|
|
1467
1459
|
if (t)
|
|
1468
1460
|
return {
|
|
1469
1461
|
classes: [{ term: t.className, graph: t.graph }],
|
|
1470
1462
|
predicates: []
|
|
1471
1463
|
};
|
|
1472
|
-
const r =
|
|
1473
|
-
return r &&
|
|
1464
|
+
const r = Ze(e);
|
|
1465
|
+
return r && !$i(r.predicate) ? {
|
|
1474
1466
|
classes: [],
|
|
1475
1467
|
predicates: [{ term: r.predicate, graph: r.graph }]
|
|
1476
|
-
} :
|
|
1468
|
+
} : cr();
|
|
1477
1469
|
}
|
|
1478
|
-
function
|
|
1479
|
-
return p(e).with({ type:
|
|
1470
|
+
function Ct(e) {
|
|
1471
|
+
return p(e).with({ type: l.union("triple", "property", "class", "general") }, pr).with(
|
|
1480
1472
|
{ type: "negation" },
|
|
1481
|
-
({ formulas: t }) =>
|
|
1473
|
+
({ formulas: t }) => gt(t.map(Ct))
|
|
1482
1474
|
).with(
|
|
1483
1475
|
{ type: "aggregate" },
|
|
1484
|
-
({ atoms: t }) =>
|
|
1485
|
-
).with({ type:
|
|
1476
|
+
({ atoms: t }) => gt(t.map(Ct))
|
|
1477
|
+
).with({ type: l.union("filter", "bind", "skolem") }, cr).exhaustive();
|
|
1486
1478
|
}
|
|
1487
|
-
function
|
|
1479
|
+
function Di(e) {
|
|
1488
1480
|
return {
|
|
1489
|
-
head:
|
|
1490
|
-
body:
|
|
1481
|
+
head: gt(e.head.map(pr)),
|
|
1482
|
+
body: gt(e.body.map(Ct))
|
|
1491
1483
|
};
|
|
1492
1484
|
}
|
|
1493
|
-
const
|
|
1485
|
+
const Gi = [
|
|
1494
1486
|
n.expression,
|
|
1495
1487
|
n.conditionalOrExpression,
|
|
1496
1488
|
n.conditionalAndExpression,
|
|
@@ -1530,10 +1522,10 @@ const ji = [
|
|
|
1530
1522
|
n.builtInUcase,
|
|
1531
1523
|
n.builtInLcase,
|
|
1532
1524
|
n.builtInEncode_for_uri
|
|
1533
|
-
],
|
|
1525
|
+
], _i = {
|
|
1534
1526
|
name: "builtInCall",
|
|
1535
1527
|
impl: ({ OR: e, SUBRULE: t }) => () => e(n.builtInCallList(t).slice(0, -2))
|
|
1536
|
-
},
|
|
1528
|
+
}, Vi = F.create(Gi).addMany(n.builtInContains, n.builtInStrstarts, n.builtInStrends, n.builtInStrbefore, n.builtInStrafter, n.builtInYear, n.builtInMonth, n.builtInDay, n.builtInHours, n.builtInMinutes, n.builtInSeconds, n.builtInTimezone, n.builtInTz, n.builtInNow, n.builtInUuid, n.builtInStruuid, n.builtInMd5, n.builtInSha1, n.builtInSha256, n.builtInSha384, n.builtInSha512, n.builtInCoalesce, n.builtInIf, n.builtInStrlang, n.builtInStrdt, n.builtInSameterm, n.builtInIsiri, n.builtInIsuri, n.builtInIsblank, n.builtInIsliteral, n.builtInIsnumeric, n.regexExpression, n.substringExpression, n.strReplaceExpression, n.aggregateCount, n.aggregateSum, n.aggregateMin, n.aggregateMax, n.aggregateAvg, n.aggregateSample, n.aggregateGroup_concat, n.aggregate, n.iri, n.prefixedName, n.argList, n.string).addRule(_i), ji = [
|
|
1537
1529
|
n.objectList,
|
|
1538
1530
|
n.object,
|
|
1539
1531
|
n.graphNode,
|
|
@@ -1559,7 +1551,7 @@ const ji = [
|
|
|
1559
1551
|
n.numericLiteralUnsigned,
|
|
1560
1552
|
n.numericLiteralPositive,
|
|
1561
1553
|
n.numericLiteralNegative
|
|
1562
|
-
],
|
|
1554
|
+
], hr = F.create(ji), qi = F.create([
|
|
1563
1555
|
n.triplesBlock,
|
|
1564
1556
|
n.triplesSameSubjectPath,
|
|
1565
1557
|
// VarOrTerm is included in the required ObjectList rule
|
|
@@ -1570,7 +1562,7 @@ const ji = [
|
|
|
1570
1562
|
n.verbPath,
|
|
1571
1563
|
n.verbSimple,
|
|
1572
1564
|
n.objectListPath
|
|
1573
|
-
]).merge(
|
|
1565
|
+
]).merge(hr, []).addMany(
|
|
1574
1566
|
n.path,
|
|
1575
1567
|
n.pathAlternative,
|
|
1576
1568
|
n.pathSequence,
|
|
@@ -1585,13 +1577,13 @@ const ji = [
|
|
|
1585
1577
|
n.graphNodePath,
|
|
1586
1578
|
n.collectionPath,
|
|
1587
1579
|
n.blankNodePropertyListPath
|
|
1588
|
-
),
|
|
1580
|
+
), Xi = [
|
|
1589
1581
|
n.subSelect,
|
|
1590
1582
|
n.selectClause,
|
|
1591
1583
|
n.whereClause,
|
|
1592
1584
|
n.solutionModifier,
|
|
1593
1585
|
n.valuesClause
|
|
1594
|
-
],
|
|
1586
|
+
], dr = F.create(Xi).merge(Vi, []).patchRule(n.builtInCall).addMany(n.existsFunc, n.notExistsFunc, n.groupGraphPattern, n.groupGraphPatternSub).merge(qi, []).addMany(
|
|
1595
1587
|
n.graphPatternNotTriples,
|
|
1596
1588
|
n.groupOrUnionGraphPattern,
|
|
1597
1589
|
n.optionalGraphPattern,
|
|
@@ -1617,7 +1609,7 @@ const ji = [
|
|
|
1617
1609
|
n.orderCondition,
|
|
1618
1610
|
n.limitClause,
|
|
1619
1611
|
n.offsetClause
|
|
1620
|
-
),
|
|
1612
|
+
), Hi = [
|
|
1621
1613
|
n.triplesTemplate,
|
|
1622
1614
|
n.triplesSameSubject,
|
|
1623
1615
|
n.varOrTerm,
|
|
@@ -1645,7 +1637,7 @@ const ji = [
|
|
|
1645
1637
|
n.collection,
|
|
1646
1638
|
n.blankNodePropertyList,
|
|
1647
1639
|
n.graphNode
|
|
1648
|
-
],
|
|
1640
|
+
], Er = F.create(Hi), Qi = [
|
|
1649
1641
|
n.queryUnit,
|
|
1650
1642
|
n.query,
|
|
1651
1643
|
n.prologue,
|
|
@@ -1656,7 +1648,7 @@ const ji = [
|
|
|
1656
1648
|
n.valuesClause,
|
|
1657
1649
|
n.baseDecl,
|
|
1658
1650
|
n.prefixDecl
|
|
1659
|
-
],
|
|
1651
|
+
], zi = F.create(Qi).merge(dr, []).addRule(n.datasetClause).addRule(n.datasetClauseStar).addRule(n.defaultGraphClause).addRule(n.namedGraphClause).addRule(n.sourceSelector).addRule(n.constructTemplate).merge(Er, []).addRule(n.constructTriples), Ki = {
|
|
1660
1652
|
name: "update1",
|
|
1661
1653
|
impl: ({ SUBRULE: e, OR: t }) => () => t([
|
|
1662
1654
|
{ ALT: () => e(n.load) },
|
|
@@ -1671,7 +1663,7 @@ const ji = [
|
|
|
1671
1663
|
{ ALT: () => e(n.deleteWhere) }
|
|
1672
1664
|
]),
|
|
1673
1665
|
gImpl: n.update1.gImpl
|
|
1674
|
-
},
|
|
1666
|
+
}, Wi = [
|
|
1675
1667
|
n.updateUnit,
|
|
1676
1668
|
n.update,
|
|
1677
1669
|
n.prologue,
|
|
@@ -1695,36 +1687,36 @@ const ji = [
|
|
|
1695
1687
|
n.graphOrDefault,
|
|
1696
1688
|
n.quadData,
|
|
1697
1689
|
n.quads
|
|
1698
|
-
],
|
|
1699
|
-
class
|
|
1690
|
+
], Yi = F.create(Wi).addRule(Ki).merge(Er, []).addRule(n.quadPattern).addRule(n.quadsNotTriples), Zi = F.create(Yi).patchRule(n.update1).addMany(n.modify, n.deleteClause, n.insertClause, n.usingClause, n.defaultGraphClause, n.namedGraphClause, n.sourceSelector, n.usingClauseStar, n.groupGraphPattern).merge(hr, []).merge(dr, []), Ji = F.create(zi).merge(Zi, []).addRule(n.queryOrUpdate);
|
|
1691
|
+
class fr extends xr {
|
|
1700
1692
|
constructor(t = {}) {
|
|
1701
|
-
const r =
|
|
1693
|
+
const r = Ji.build({
|
|
1702
1694
|
...t,
|
|
1703
|
-
tokenVocabulary:
|
|
1704
|
-
queryPreProcessor:
|
|
1695
|
+
tokenVocabulary: Qe.sparql11LexerBuilder.tokenVocabulary,
|
|
1696
|
+
queryPreProcessor: vr
|
|
1705
1697
|
});
|
|
1706
1698
|
super(r, t.defaultContext);
|
|
1707
1699
|
}
|
|
1708
1700
|
}
|
|
1709
|
-
let
|
|
1710
|
-
function
|
|
1701
|
+
let mt;
|
|
1702
|
+
function tn(e) {
|
|
1711
1703
|
return e.type === "query";
|
|
1712
1704
|
}
|
|
1713
|
-
function
|
|
1705
|
+
function gr(e) {
|
|
1714
1706
|
return e.type === "update";
|
|
1715
1707
|
}
|
|
1716
|
-
function
|
|
1708
|
+
function mr(e) {
|
|
1717
1709
|
return e.replace(/\s+EXPLICIT\s+(TRUE|FALSE)\b/gi, "");
|
|
1718
1710
|
}
|
|
1719
|
-
function
|
|
1720
|
-
|
|
1711
|
+
function en(e) {
|
|
1712
|
+
mt ??= new fr();
|
|
1721
1713
|
try {
|
|
1722
|
-
const t =
|
|
1723
|
-
return
|
|
1714
|
+
const t = mt.parse(mr(e));
|
|
1715
|
+
return gr(t) ? {
|
|
1724
1716
|
valid: !0,
|
|
1725
1717
|
queryType: "update",
|
|
1726
1718
|
isReadOnly: !1
|
|
1727
|
-
} :
|
|
1719
|
+
} : tn(t) ? {
|
|
1728
1720
|
valid: !0,
|
|
1729
1721
|
queryType: t.subType,
|
|
1730
1722
|
isReadOnly: !0
|
|
@@ -1739,19 +1731,19 @@ function sn(e) {
|
|
|
1739
1731
|
};
|
|
1740
1732
|
}
|
|
1741
1733
|
}
|
|
1742
|
-
function
|
|
1743
|
-
const t =
|
|
1734
|
+
function ys(e) {
|
|
1735
|
+
const t = en(e);
|
|
1744
1736
|
return t.valid ? t.isReadOnly ? { allowed: !0, queryType: t.queryType } : {
|
|
1745
1737
|
allowed: !1,
|
|
1746
1738
|
error: "UPDATE operations not allowed. Only SELECT, CONSTRUCT, DESCRIBE, and ASK queries are permitted.",
|
|
1747
1739
|
queryType: t.queryType
|
|
1748
1740
|
} : { allowed: !1, error: t.error };
|
|
1749
1741
|
}
|
|
1750
|
-
const
|
|
1742
|
+
const rn = /* @__PURE__ */ new Set([
|
|
1751
1743
|
"insertdata",
|
|
1752
1744
|
"deletedata",
|
|
1753
1745
|
"modify"
|
|
1754
|
-
]),
|
|
1746
|
+
]), nn = {
|
|
1755
1747
|
insertdata: "INSERT DATA",
|
|
1756
1748
|
deletedata: "DELETE DATA",
|
|
1757
1749
|
deletewhere: "DELETE WHERE",
|
|
@@ -1764,189 +1756,189 @@ const an = /* @__PURE__ */ new Set([
|
|
|
1764
1756
|
move: "MOVE",
|
|
1765
1757
|
copy: "COPY"
|
|
1766
1758
|
};
|
|
1767
|
-
function
|
|
1768
|
-
return
|
|
1759
|
+
function Ge(e) {
|
|
1760
|
+
return rn.has(e);
|
|
1769
1761
|
}
|
|
1770
|
-
function
|
|
1762
|
+
function _e(e) {
|
|
1771
1763
|
return e.type === "term" && e.subType === "variable";
|
|
1772
1764
|
}
|
|
1773
|
-
function
|
|
1774
|
-
return
|
|
1765
|
+
function sn(e) {
|
|
1766
|
+
return _e(e.subject) && e.predicate.subType === "variable" && _e(e.object);
|
|
1775
1767
|
}
|
|
1776
|
-
function
|
|
1768
|
+
function an(e) {
|
|
1777
1769
|
for (const t of e) {
|
|
1778
1770
|
const r = t.type === "graph" ? t.triples.triples : t.triples;
|
|
1779
1771
|
for (const i of r)
|
|
1780
|
-
if (i.type === "triple" &&
|
|
1772
|
+
if (i.type === "triple" && sn(i)) return !0;
|
|
1781
1773
|
}
|
|
1782
1774
|
return !1;
|
|
1783
1775
|
}
|
|
1784
|
-
function
|
|
1785
|
-
return e.delete.length > 0 &&
|
|
1776
|
+
function on(e) {
|
|
1777
|
+
return e.delete.length > 0 && an(e.delete);
|
|
1786
1778
|
}
|
|
1787
|
-
function
|
|
1788
|
-
|
|
1779
|
+
function Ls(e) {
|
|
1780
|
+
mt ??= new fr();
|
|
1789
1781
|
let t;
|
|
1790
1782
|
try {
|
|
1791
|
-
t =
|
|
1792
|
-
} catch (
|
|
1783
|
+
t = mt.parse(mr(e));
|
|
1784
|
+
} catch (a) {
|
|
1793
1785
|
return {
|
|
1794
1786
|
allowed: !1,
|
|
1795
|
-
error:
|
|
1787
|
+
error: a instanceof Error ? a.message : "Failed to parse SPARQL update"
|
|
1796
1788
|
};
|
|
1797
1789
|
}
|
|
1798
|
-
if (!
|
|
1790
|
+
if (!gr(t))
|
|
1799
1791
|
return {
|
|
1800
1792
|
allowed: !1,
|
|
1801
1793
|
error: "Expected a SPARQL UPDATE statement, not a query."
|
|
1802
1794
|
};
|
|
1803
1795
|
const r = [];
|
|
1804
|
-
for (const
|
|
1805
|
-
|
|
1796
|
+
for (const a of t.updates)
|
|
1797
|
+
a.operation && r.push(a.operation);
|
|
1806
1798
|
if (r.length === 0)
|
|
1807
1799
|
return { allowed: !1, error: "Empty SPARQL update -- no operations found." };
|
|
1808
|
-
const i = r.filter((
|
|
1800
|
+
const i = r.filter((a) => !Ge(a.subType));
|
|
1809
1801
|
if (i.length > 0) {
|
|
1810
|
-
const
|
|
1802
|
+
const a = i.map((f) => f.subType);
|
|
1811
1803
|
return {
|
|
1812
1804
|
allowed: !1,
|
|
1813
|
-
error: `Blocked operations: ${i.map((
|
|
1814
|
-
blockedOperations:
|
|
1805
|
+
error: `Blocked operations: ${i.map((f) => nn[f.subType]).join(", ")}. Only INSERT DATA, DELETE DATA, and DELETE/INSERT WHERE are permitted.`,
|
|
1806
|
+
blockedOperations: a
|
|
1815
1807
|
};
|
|
1816
1808
|
}
|
|
1817
1809
|
return r.filter(
|
|
1818
|
-
(
|
|
1810
|
+
(a) => a.subType === "modify" && on(a)
|
|
1819
1811
|
).length > 0 ? {
|
|
1820
1812
|
allowed: !1,
|
|
1821
1813
|
error: "Unscoped DELETE patterns (all-variable triples) are not permitted.",
|
|
1822
1814
|
blockedOperations: ["modify"]
|
|
1823
|
-
} : { allowed: !0, operationTypes: r.map((
|
|
1815
|
+
} : { allowed: !0, operationTypes: r.map((a) => a.subType).filter(Ge) };
|
|
1824
1816
|
}
|
|
1825
|
-
async function
|
|
1826
|
-
const { endpointUrl: t, datastoreName: r, authorization: i } = e, s = new URL(`datastores/${r}/connections`, t),
|
|
1817
|
+
async function ln(e) {
|
|
1818
|
+
const { endpointUrl: t, datastoreName: r, authorization: i } = e, s = new URL(`datastores/${r}/connections`, t), o = await fetch(s.toString(), {
|
|
1827
1819
|
method: "POST",
|
|
1828
1820
|
headers: {
|
|
1829
1821
|
Authorization: i
|
|
1830
1822
|
}
|
|
1831
1823
|
});
|
|
1832
|
-
if (!
|
|
1833
|
-
const
|
|
1834
|
-
throw new Error(`Failed to create connection: ${
|
|
1824
|
+
if (!o.ok) {
|
|
1825
|
+
const u = await o.text();
|
|
1826
|
+
throw new Error(`Failed to create connection: ${o.status} - ${u}`);
|
|
1835
1827
|
}
|
|
1836
|
-
const
|
|
1837
|
-
if (!
|
|
1828
|
+
const a = o.headers.get("Location");
|
|
1829
|
+
if (!a)
|
|
1838
1830
|
throw new Error("Connection creation response missing Location header");
|
|
1839
|
-
return
|
|
1831
|
+
return a.split("/").pop();
|
|
1840
1832
|
}
|
|
1841
|
-
async function
|
|
1842
|
-
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e,
|
|
1843
|
-
|
|
1844
|
-
const
|
|
1833
|
+
async function un(e) {
|
|
1834
|
+
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e, o = new URL(`datastores/${r}/connections/${i}/transaction`, t);
|
|
1835
|
+
o.searchParams.set("operation", "begin-read-write-transaction");
|
|
1836
|
+
const a = await fetch(o.toString(), {
|
|
1845
1837
|
method: "PATCH",
|
|
1846
1838
|
headers: {
|
|
1847
1839
|
Authorization: s
|
|
1848
1840
|
}
|
|
1849
1841
|
});
|
|
1850
|
-
if (!
|
|
1851
|
-
const
|
|
1852
|
-
throw new Error(`Failed to begin transaction: ${
|
|
1842
|
+
if (!a.ok) {
|
|
1843
|
+
const u = await a.text();
|
|
1844
|
+
throw new Error(`Failed to begin transaction: ${a.status} - ${u}`);
|
|
1853
1845
|
}
|
|
1854
1846
|
}
|
|
1855
|
-
async function
|
|
1856
|
-
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e,
|
|
1857
|
-
|
|
1858
|
-
const
|
|
1847
|
+
async function cn(e) {
|
|
1848
|
+
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e, o = new URL(`datastores/${r}/connections/${i}/transaction`, t);
|
|
1849
|
+
o.searchParams.set("operation", "commit-transaction");
|
|
1850
|
+
const a = await fetch(o.toString(), {
|
|
1859
1851
|
method: "PATCH",
|
|
1860
1852
|
headers: {
|
|
1861
1853
|
Authorization: s
|
|
1862
1854
|
}
|
|
1863
1855
|
});
|
|
1864
|
-
if (!
|
|
1865
|
-
const
|
|
1866
|
-
throw new Error(`Failed to commit transaction: ${
|
|
1856
|
+
if (!a.ok) {
|
|
1857
|
+
const u = await a.text();
|
|
1858
|
+
throw new Error(`Failed to commit transaction: ${a.status} - ${u}`);
|
|
1867
1859
|
}
|
|
1868
1860
|
}
|
|
1869
|
-
async function
|
|
1870
|
-
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e,
|
|
1871
|
-
|
|
1872
|
-
const
|
|
1861
|
+
async function pn(e) {
|
|
1862
|
+
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e, o = new URL(`datastores/${r}/connections/${i}/transaction`, t);
|
|
1863
|
+
o.searchParams.set("operation", "rollback-transaction");
|
|
1864
|
+
const a = await fetch(o.toString(), {
|
|
1873
1865
|
method: "PATCH",
|
|
1874
1866
|
headers: {
|
|
1875
1867
|
Authorization: s
|
|
1876
1868
|
}
|
|
1877
1869
|
});
|
|
1878
|
-
if (!
|
|
1879
|
-
const
|
|
1880
|
-
throw new Error(`Failed to rollback transaction: ${
|
|
1870
|
+
if (!a.ok) {
|
|
1871
|
+
const u = await a.text();
|
|
1872
|
+
throw new Error(`Failed to rollback transaction: ${a.status} - ${u}`);
|
|
1881
1873
|
}
|
|
1882
1874
|
}
|
|
1883
|
-
async function
|
|
1884
|
-
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e,
|
|
1875
|
+
async function hn(e) {
|
|
1876
|
+
const { endpointUrl: t, datastoreName: r, connectionId: i, authorization: s } = e, o = new URL(`datastores/${r}/connections/${i}`, t), a = await fetch(o.toString(), {
|
|
1885
1877
|
method: "DELETE",
|
|
1886
1878
|
headers: {
|
|
1887
1879
|
Authorization: s
|
|
1888
1880
|
}
|
|
1889
1881
|
});
|
|
1890
|
-
if (!
|
|
1891
|
-
const
|
|
1892
|
-
throw new Error(`Failed to delete connection: ${
|
|
1882
|
+
if (!a.ok) {
|
|
1883
|
+
const u = await a.text();
|
|
1884
|
+
throw new Error(`Failed to delete connection: ${a.status} - ${u}`);
|
|
1893
1885
|
}
|
|
1894
1886
|
}
|
|
1895
|
-
async function
|
|
1896
|
-
const r = await
|
|
1887
|
+
async function Us(e, t) {
|
|
1888
|
+
const r = await ln(e);
|
|
1897
1889
|
try {
|
|
1898
|
-
await
|
|
1890
|
+
await un({ ...e, connectionId: r });
|
|
1899
1891
|
const i = await t(r);
|
|
1900
|
-
return await
|
|
1892
|
+
return await cn({ ...e, connectionId: r }), i;
|
|
1901
1893
|
} catch (i) {
|
|
1902
1894
|
try {
|
|
1903
|
-
await
|
|
1895
|
+
await pn({ ...e, connectionId: r });
|
|
1904
1896
|
} catch (s) {
|
|
1905
1897
|
console.error("Failed to rollback transaction:", s);
|
|
1906
1898
|
}
|
|
1907
1899
|
throw i;
|
|
1908
1900
|
} finally {
|
|
1909
1901
|
try {
|
|
1910
|
-
await
|
|
1902
|
+
await hn({ ...e, connectionId: r });
|
|
1911
1903
|
} catch (i) {
|
|
1912
1904
|
console.error("Failed to delete connection:", i);
|
|
1913
1905
|
}
|
|
1914
1906
|
}
|
|
1915
1907
|
}
|
|
1916
|
-
function
|
|
1908
|
+
function St(e) {
|
|
1917
1909
|
return e.type === "variable" ? `?${e.name}` : void 0;
|
|
1918
1910
|
}
|
|
1919
|
-
function
|
|
1911
|
+
function ws(e) {
|
|
1920
1912
|
const t = /* @__PURE__ */ new Map();
|
|
1921
|
-
function r(
|
|
1922
|
-
let
|
|
1923
|
-
return
|
|
1924
|
-
}
|
|
1925
|
-
function i(
|
|
1926
|
-
const { atom:
|
|
1927
|
-
if (
|
|
1928
|
-
const
|
|
1929
|
-
if (
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1913
|
+
function r(o) {
|
|
1914
|
+
let a = t.get(o);
|
|
1915
|
+
return a || (a = { variable: o, predicateEvidence: [] }, t.set(o, a)), a;
|
|
1916
|
+
}
|
|
1917
|
+
function i(o) {
|
|
1918
|
+
const { atom: a, fromBody: u = !1 } = o, f = Ye(a);
|
|
1919
|
+
if (f) {
|
|
1920
|
+
const C = St(f.instance);
|
|
1921
|
+
if (C) {
|
|
1922
|
+
const T = r(C);
|
|
1923
|
+
T.classTerm ??= f.className, u && (T.bodyClassTerm ??= f.className);
|
|
1932
1924
|
}
|
|
1933
1925
|
return;
|
|
1934
1926
|
}
|
|
1935
|
-
const y =
|
|
1927
|
+
const y = Ze(a);
|
|
1936
1928
|
if (!y) return;
|
|
1937
|
-
const
|
|
1938
|
-
|
|
1929
|
+
const m = St(y.subject), h = St(y.object);
|
|
1930
|
+
m && r(m).predicateEvidence.push({ term: y.predicate, position: "domain" }), h && r(h).predicateEvidence.push({ term: y.predicate, position: "range" });
|
|
1939
1931
|
}
|
|
1940
|
-
function s(
|
|
1941
|
-
if (
|
|
1942
|
-
i({ atom:
|
|
1932
|
+
function s(o) {
|
|
1933
|
+
if (Me(o)) {
|
|
1934
|
+
i({ atom: o, fromBody: !0 });
|
|
1943
1935
|
return;
|
|
1944
1936
|
}
|
|
1945
|
-
|
|
1937
|
+
o.type === "aggregate" && o.atoms.filter(Me).forEach((a) => i({ atom: a, fromBody: !0 }));
|
|
1946
1938
|
}
|
|
1947
|
-
return e.head.forEach((
|
|
1939
|
+
return e.head.forEach((o) => i({ atom: o })), e.body.forEach(s), [...t.values()];
|
|
1948
1940
|
}
|
|
1949
|
-
function
|
|
1941
|
+
function As(e, t) {
|
|
1950
1942
|
const r = [];
|
|
1951
1943
|
for (const i of e) {
|
|
1952
1944
|
const s = i.bodyClassTerm ?? i.classTerm;
|
|
@@ -1954,68 +1946,66 @@ function Rs(e, t) {
|
|
|
1954
1946
|
r.push({ variable: i.variable, typeTerm: s, source: "class" });
|
|
1955
1947
|
continue;
|
|
1956
1948
|
}
|
|
1957
|
-
const
|
|
1958
|
-
|
|
1949
|
+
const o = dn(i.predicateEvidence, t);
|
|
1950
|
+
o && r.push({ variable: i.variable, ...o });
|
|
1959
1951
|
}
|
|
1960
1952
|
return r;
|
|
1961
1953
|
}
|
|
1962
|
-
function
|
|
1954
|
+
function dn(e, t) {
|
|
1963
1955
|
for (const { term: r, position: i } of e) {
|
|
1964
|
-
const s = t(r),
|
|
1965
|
-
if (
|
|
1956
|
+
const s = t(r), o = i === "domain" ? s?.domainIncludes[0] : s?.rangeIncludes[0];
|
|
1957
|
+
if (o) return { typeTerm: o, source: i };
|
|
1966
1958
|
}
|
|
1967
1959
|
}
|
|
1968
|
-
const
|
|
1969
|
-
function
|
|
1960
|
+
const En = new Oe({ selfAnalysis: !1 }).getBaseCstVisitorConstructor();
|
|
1961
|
+
function O(e, t) {
|
|
1970
1962
|
if (e === void 0)
|
|
1971
1963
|
throw new Error(t);
|
|
1972
1964
|
return e;
|
|
1973
1965
|
}
|
|
1974
|
-
function
|
|
1975
|
-
var s;
|
|
1966
|
+
function nt(e, t, ...r) {
|
|
1976
1967
|
if (!e)
|
|
1977
1968
|
throw new Error(`Children is undefined when looking for keys: [${r.join(", ")}]`);
|
|
1978
|
-
for (const
|
|
1979
|
-
if (
|
|
1969
|
+
for (const s of r)
|
|
1970
|
+
if (e[s]?.[0]) return t(e[s][0]);
|
|
1980
1971
|
const i = Object.keys(e);
|
|
1981
1972
|
throw new Error(`None of [${r.join(", ")}] found. Available keys: [${i.join(", ")}]`);
|
|
1982
1973
|
}
|
|
1983
|
-
const
|
|
1984
|
-
function
|
|
1974
|
+
const d = (e) => e != null && e.length > 0;
|
|
1975
|
+
function Ve(e) {
|
|
1985
1976
|
return e.flatMap(({ arr: t, op: r }) => (t ?? []).map((i) => ({ offset: i.startOffset, op: r }))).sort((t, r) => t.offset - r.offset).map(({ op: t }) => t);
|
|
1986
1977
|
}
|
|
1987
|
-
function
|
|
1978
|
+
function K(e) {
|
|
1988
1979
|
const t = e.startOffset ?? 0, r = e.endOffset ?? t + e.image.length - 1;
|
|
1989
1980
|
return { start: t, end: r + 1 };
|
|
1990
1981
|
}
|
|
1991
|
-
function
|
|
1982
|
+
function _(e, t, r = e.image) {
|
|
1992
1983
|
return {
|
|
1993
1984
|
token: e,
|
|
1994
1985
|
term: { type: "iri", value: r, prefixed: t }
|
|
1995
1986
|
};
|
|
1996
1987
|
}
|
|
1997
|
-
function
|
|
1988
|
+
function je(e) {
|
|
1998
1989
|
return p(e).returnType().with(
|
|
1999
|
-
{ IRI_REF:
|
|
2000
|
-
({ IRI_REF: t }) =>
|
|
2001
|
-
).with({ PREFIXED_NAME:
|
|
2002
|
-
{ INTERNAL_FUNCTION:
|
|
2003
|
-
({ INTERNAL_FUNCTION: t }) =>
|
|
1990
|
+
{ IRI_REF: l.when(d) },
|
|
1991
|
+
({ IRI_REF: t }) => _(t[0], !1, t[0].image.slice(1, -1))
|
|
1992
|
+
).with({ PREFIXED_NAME: l.when(d) }, ({ PREFIXED_NAME: t }) => _(t[0], !0)).with({ PREFIX_ONLY: l.when(d) }, ({ PREFIX_ONLY: t }) => _(t[0], !0)).with({ IDENTIFIER: l.when(d) }, ({ IDENTIFIER: t }) => _(t[0], !1)).with({ DEFAULT_NS_IRI: l.when(d) }, ({ DEFAULT_NS_IRI: t }) => _(t[0], !0)).with(
|
|
1993
|
+
{ INTERNAL_FUNCTION: l.when(d) },
|
|
1994
|
+
({ INTERNAL_FUNCTION: t }) => _(t[0], !1)
|
|
2004
1995
|
).otherwise(() => {
|
|
2005
1996
|
throw new Error("Unknown IRI type");
|
|
2006
1997
|
});
|
|
2007
1998
|
}
|
|
2008
|
-
function
|
|
2009
|
-
const r =
|
|
1999
|
+
function fn(e, t) {
|
|
2000
|
+
const r = K(e);
|
|
2010
2001
|
return {
|
|
2011
2002
|
start: r.start + t,
|
|
2012
2003
|
end: r.end - t
|
|
2013
2004
|
};
|
|
2014
2005
|
}
|
|
2015
|
-
class
|
|
2006
|
+
class gn extends En {
|
|
2016
2007
|
rule(t) {
|
|
2017
|
-
|
|
2018
|
-
const r = this.visit(v(t.ruleHead, "Rule missing head")), i = (s = t.ruleBody) != null && s[0] ? this.visit(t.ruleBody) : [];
|
|
2008
|
+
const r = this.visit(O(t.ruleHead, "Rule missing head")), i = t.ruleBody?.[0] ? this.visit(t.ruleBody) : [];
|
|
2019
2009
|
return { head: r, body: i };
|
|
2020
2010
|
}
|
|
2021
2011
|
ruleHead(t) {
|
|
@@ -2025,7 +2015,7 @@ class Ln extends mn {
|
|
|
2025
2015
|
return t.bodyFormula.map((r) => this.visit(r));
|
|
2026
2016
|
}
|
|
2027
2017
|
bodyFormula(t) {
|
|
2028
|
-
return
|
|
2018
|
+
return nt(
|
|
2029
2019
|
t,
|
|
2030
2020
|
this.visit.bind(this),
|
|
2031
2021
|
"negation",
|
|
@@ -2037,8 +2027,8 @@ class Ln extends mn {
|
|
|
2037
2027
|
);
|
|
2038
2028
|
}
|
|
2039
2029
|
tupleTableAtom(t) {
|
|
2040
|
-
const r =
|
|
2041
|
-
if (
|
|
2030
|
+
const r = nt(t, this.visit.bind(this), "defaultGraphAtom", "generalAtom");
|
|
2031
|
+
if (d(t.graph)) {
|
|
2042
2032
|
const i = this.visit(t.graph[0]);
|
|
2043
2033
|
if (r.type === "triple" || r.type === "property" || r.type === "class")
|
|
2044
2034
|
return { ...r, graph: i };
|
|
@@ -2047,24 +2037,24 @@ class Ln extends mn {
|
|
|
2047
2037
|
return r;
|
|
2048
2038
|
}
|
|
2049
2039
|
graphName(t) {
|
|
2050
|
-
if (
|
|
2040
|
+
if (d(t.VARIABLE))
|
|
2051
2041
|
return { type: "variable", name: t.VARIABLE[0].image.substring(1) };
|
|
2052
|
-
if (
|
|
2042
|
+
if (d(t.iri))
|
|
2053
2043
|
return this.visit(t.iri[0]);
|
|
2054
2044
|
throw new Error("Unknown graph name type");
|
|
2055
2045
|
}
|
|
2056
2046
|
defaultGraphAtom(t) {
|
|
2057
2047
|
const r = t;
|
|
2058
|
-
if (
|
|
2048
|
+
if (d(r.subject) && d(r.predicate) && d(r.object))
|
|
2059
2049
|
return {
|
|
2060
2050
|
type: "triple",
|
|
2061
2051
|
subject: this.visit(r.subject[0]),
|
|
2062
2052
|
predicate: this.visit(r.predicate[0]),
|
|
2063
2053
|
object: this.visit(r.object[0])
|
|
2064
2054
|
};
|
|
2065
|
-
if (
|
|
2055
|
+
if (d(r.predicateOrClass) && d(r.firstTerm)) {
|
|
2066
2056
|
const i = this.extractIriValue(r.predicateOrClass[0]), s = this.visit(r.firstTerm[0]);
|
|
2067
|
-
return
|
|
2057
|
+
return d(r.secondTerm) ? {
|
|
2068
2058
|
type: "property",
|
|
2069
2059
|
predicate: i,
|
|
2070
2060
|
subject: s,
|
|
@@ -2081,7 +2071,7 @@ class Ln extends mn {
|
|
|
2081
2071
|
const r = t;
|
|
2082
2072
|
return {
|
|
2083
2073
|
type: "general",
|
|
2084
|
-
tableName:
|
|
2074
|
+
tableName: d(r.IDENTIFIER) ? r.IDENTIFIER[0].image : d(r.STRING_LITERAL) ? this.unquoteString(r.STRING_LITERAL[0].image) : (() => {
|
|
2085
2075
|
throw new Error("Missing table name");
|
|
2086
2076
|
})(),
|
|
2087
2077
|
terms: r.term.map((s) => this.visit(s))
|
|
@@ -2089,17 +2079,17 @@ class Ln extends mn {
|
|
|
2089
2079
|
}
|
|
2090
2080
|
term(t) {
|
|
2091
2081
|
const r = t;
|
|
2092
|
-
if (
|
|
2093
|
-
if (
|
|
2094
|
-
if (
|
|
2095
|
-
if (
|
|
2082
|
+
if (d(r.VARIABLE)) return { type: "variable", name: r.VARIABLE[0].image.substring(1) };
|
|
2083
|
+
if (d(r.iri)) return this.visit(r.iri[0]);
|
|
2084
|
+
if (d(r.literal)) return this.visit(r.literal[0]);
|
|
2085
|
+
if (d(r.BLANK_NODE)) return { type: "blank", label: r.BLANK_NODE[0].image.substring(2) };
|
|
2096
2086
|
throw new Error("Unknown term type");
|
|
2097
2087
|
}
|
|
2098
2088
|
iri(t) {
|
|
2099
|
-
return
|
|
2089
|
+
return je(t).term;
|
|
2100
2090
|
}
|
|
2101
2091
|
literal(t) {
|
|
2102
|
-
return
|
|
2092
|
+
return nt(
|
|
2103
2093
|
t,
|
|
2104
2094
|
this.visit.bind(this),
|
|
2105
2095
|
"numericLiteral",
|
|
@@ -2109,38 +2099,36 @@ class Ln extends mn {
|
|
|
2109
2099
|
}
|
|
2110
2100
|
numericLiteral(t) {
|
|
2111
2101
|
const r = t;
|
|
2112
|
-
if (
|
|
2113
|
-
if (
|
|
2114
|
-
if (
|
|
2102
|
+
if (d(r.INTEGER)) return this.numericTokenLiteral(r.INTEGER[0], V.integer);
|
|
2103
|
+
if (d(r.DECIMAL)) return this.numericTokenLiteral(r.DECIMAL[0], V.decimal);
|
|
2104
|
+
if (d(r.DOUBLE)) return this.numericTokenLiteral(r.DOUBLE[0], V.double);
|
|
2115
2105
|
throw new Error("Unknown numeric literal type");
|
|
2116
2106
|
}
|
|
2117
2107
|
booleanLiteral(t) {
|
|
2118
2108
|
const r = t;
|
|
2119
|
-
if (
|
|
2120
|
-
if (
|
|
2109
|
+
if (d(r.TRUE)) return { type: "literal", value: "true", datatype: V.boolean };
|
|
2110
|
+
if (d(r.FALSE)) return { type: "literal", value: "false", datatype: V.boolean };
|
|
2121
2111
|
throw new Error("Unknown boolean literal type");
|
|
2122
2112
|
}
|
|
2123
2113
|
stringLiteral(t) {
|
|
2124
|
-
|
|
2125
|
-
const r = (h = t.STRING_LITERAL_LONG) == null ? void 0 : h[0], i = (R = t.STRING_LITERAL) == null ? void 0 : R[0], s = r ?? i;
|
|
2114
|
+
const r = t.STRING_LITERAL_LONG?.[0], i = t.STRING_LITERAL?.[0], s = r ?? i;
|
|
2126
2115
|
if (!s) throw new Error("Unknown string literal format");
|
|
2127
|
-
const
|
|
2116
|
+
const o = r ? this.unquoteTripleString(s.image) : this.unquoteString(s.image), a = K(s), u = t.LANGTAG?.[0], f = t.iri?.[0] ? je(t.iri[0].children) : void 0, y = u ? K(u).end : f ? K(f.token).end : a.end, m = {
|
|
2128
2117
|
type: "literal",
|
|
2129
|
-
value:
|
|
2130
|
-
termSpan: { start:
|
|
2131
|
-
valueSpan:
|
|
2118
|
+
value: o,
|
|
2119
|
+
termSpan: { start: a.start, end: y },
|
|
2120
|
+
valueSpan: fn(s, r ? 3 : 1)
|
|
2132
2121
|
};
|
|
2133
|
-
return
|
|
2122
|
+
return u ? m.language = u.image.substring(1) : f && (m.datatype = f.term.value), m;
|
|
2134
2123
|
}
|
|
2135
2124
|
negation(t) {
|
|
2136
|
-
var s, a, o;
|
|
2137
2125
|
const r = [];
|
|
2138
|
-
if (
|
|
2139
|
-
const
|
|
2140
|
-
r.push(...
|
|
2126
|
+
if (t.existsClause?.[0]) {
|
|
2127
|
+
const s = this.visit(t.existsClause);
|
|
2128
|
+
r.push(...s);
|
|
2141
2129
|
}
|
|
2142
2130
|
const i = [];
|
|
2143
|
-
return
|
|
2131
|
+
return t.bodyFormulaList?.[0] ? i.push(...this.visit(t.bodyFormulaList)) : t.tupleTableAtom?.[0] && i.push(this.visit(t.tupleTableAtom)), {
|
|
2144
2132
|
type: "negation",
|
|
2145
2133
|
formulas: i,
|
|
2146
2134
|
existentialVars: r.length > 0 ? r : void 0
|
|
@@ -2153,7 +2141,7 @@ class Ln extends mn {
|
|
|
2153
2141
|
return t.atom ? t.atom.map((r) => this.visit(r)) : [];
|
|
2154
2142
|
}
|
|
2155
2143
|
atom(t) {
|
|
2156
|
-
return
|
|
2144
|
+
return nt(
|
|
2157
2145
|
t,
|
|
2158
2146
|
(r) => this.visit(r),
|
|
2159
2147
|
"tupleTableAtom",
|
|
@@ -2167,24 +2155,23 @@ class Ln extends mn {
|
|
|
2167
2155
|
filterAtom(t) {
|
|
2168
2156
|
return {
|
|
2169
2157
|
type: "filter",
|
|
2170
|
-
expression: this.visit(
|
|
2158
|
+
expression: this.visit(O(t.expression, "Filter missing expression"))
|
|
2171
2159
|
};
|
|
2172
2160
|
}
|
|
2173
2161
|
bindAtom(t) {
|
|
2174
2162
|
return {
|
|
2175
2163
|
type: "bind",
|
|
2176
|
-
expression: this.visit(
|
|
2164
|
+
expression: this.visit(O(t.expression, "Bind missing expression")),
|
|
2177
2165
|
...this.asTarget(t, "Bind missing variable")
|
|
2178
2166
|
};
|
|
2179
2167
|
}
|
|
2180
2168
|
// The expanded grammar accepts a value where a variable belongs, because the engine
|
|
2181
2169
|
// substitutes the `AS` target when it grounds a rule.
|
|
2182
2170
|
asTarget(t, r) {
|
|
2183
|
-
|
|
2184
|
-
const i = (a = t.VARIABLE) == null ? void 0 : a[0];
|
|
2171
|
+
const i = t.VARIABLE?.[0];
|
|
2185
2172
|
if (i) return { variable: i.image.substring(1) };
|
|
2186
|
-
const s = this.visit(
|
|
2187
|
-
return { variable:
|
|
2173
|
+
const s = this.visit(O(t.groundedAsTarget, r));
|
|
2174
|
+
return { variable: b(s, { stripSimpleLiteralDatatypes: !0 }), groundedTarget: s };
|
|
2188
2175
|
}
|
|
2189
2176
|
// A variable-free `term`, so it visits identically.
|
|
2190
2177
|
groundedAsTarget(t) {
|
|
@@ -2193,28 +2180,26 @@ class Ln extends mn {
|
|
|
2193
2180
|
skolemAtom(t) {
|
|
2194
2181
|
return {
|
|
2195
2182
|
type: "skolem",
|
|
2196
|
-
args: this.visit(
|
|
2183
|
+
args: this.visit(O(t.argumentList, "Skolem missing argument list"))
|
|
2197
2184
|
};
|
|
2198
2185
|
}
|
|
2199
2186
|
aggregate(t) {
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
if (r.length === 0 && !(s != null && s.length))
|
|
2187
|
+
const r = t.atomList?.[0] ? this.visit(t.atomList) : [], i = t.onClause ? this.visit(t.onClause) : void 0, s = t.aggregateBind ? t.aggregateBind.map((o) => this.visit(o)) : void 0;
|
|
2188
|
+
if (r.length === 0 && !s?.length)
|
|
2203
2189
|
throw new Error("AGGREGATE requires at least one atom or binding");
|
|
2204
2190
|
return {
|
|
2205
2191
|
type: "aggregate",
|
|
2206
2192
|
atoms: r,
|
|
2207
|
-
onVars: i
|
|
2208
|
-
groundedOnTargets: i
|
|
2193
|
+
onVars: i?.onVars,
|
|
2194
|
+
groundedOnTargets: i?.groundedOnTargets,
|
|
2209
2195
|
bindings: s
|
|
2210
2196
|
};
|
|
2211
2197
|
}
|
|
2212
2198
|
// The engine grounds every grouping variable or none of them, so listing the
|
|
2213
2199
|
// variables ahead of any substituted values preserves source order in practice.
|
|
2214
2200
|
onClause(t) {
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
(l) => x(l, { stripSimpleLiteralDatatypes: !0 })
|
|
2201
|
+
const r = t.VARIABLE?.map((o) => o.image.substring(1)) ?? [], i = t.groundedAsTarget?.map((o) => this.visit(o)) ?? [], s = i.map(
|
|
2202
|
+
(o) => b(o, { stripSimpleLiteralDatatypes: !0 })
|
|
2218
2203
|
);
|
|
2219
2204
|
return {
|
|
2220
2205
|
onVars: [...r, ...s],
|
|
@@ -2222,73 +2207,70 @@ class Ln extends mn {
|
|
|
2222
2207
|
};
|
|
2223
2208
|
}
|
|
2224
2209
|
aggregateBind(t) {
|
|
2225
|
-
var i;
|
|
2226
2210
|
const r = this.asTarget(t, "AggregateBind missing variable");
|
|
2227
|
-
return
|
|
2228
|
-
expression: this.visit(
|
|
2211
|
+
return t.aggregateFunction?.[0] ? { ...this.visit(t.aggregateFunction), ...r } : {
|
|
2212
|
+
expression: this.visit(O(t.expression, "AggregateBind missing expression")),
|
|
2229
2213
|
...r
|
|
2230
2214
|
};
|
|
2231
2215
|
}
|
|
2232
2216
|
aggregateFunction(t) {
|
|
2233
|
-
return p(t).with({ aggregateFunction1:
|
|
2217
|
+
return p(t).with({ aggregateFunction1: l.when(d) }, (r) => this.visit(r.aggregateFunction1[0])).with({ aggregateFunction2: l.when(d) }, (r) => this.visit(r.aggregateFunction2[0])).otherwise(() => {
|
|
2234
2218
|
throw new Error("Unknown aggregate function arity");
|
|
2235
2219
|
});
|
|
2236
2220
|
}
|
|
2237
2221
|
aggregateFunction1(t) {
|
|
2238
|
-
var i;
|
|
2239
2222
|
return {
|
|
2240
2223
|
function: p(t).when(
|
|
2241
|
-
(
|
|
2224
|
+
(i) => !!i.COUNT_MIN,
|
|
2242
2225
|
() => "COUNT_MIN"
|
|
2243
2226
|
).when(
|
|
2244
|
-
(
|
|
2227
|
+
(i) => !!i.COUNT_MAX,
|
|
2245
2228
|
() => "COUNT_MAX"
|
|
2246
2229
|
).when(
|
|
2247
|
-
(
|
|
2230
|
+
(i) => !!i.COUNT,
|
|
2248
2231
|
() => "COUNT"
|
|
2249
2232
|
).when(
|
|
2250
|
-
(
|
|
2233
|
+
(i) => !!i.MIN,
|
|
2251
2234
|
() => "MIN"
|
|
2252
2235
|
).when(
|
|
2253
|
-
(
|
|
2236
|
+
(i) => !!i.MAX,
|
|
2254
2237
|
() => "MAX"
|
|
2255
2238
|
).when(
|
|
2256
|
-
(
|
|
2239
|
+
(i) => !!i.SUM,
|
|
2257
2240
|
() => "SUM"
|
|
2258
2241
|
).when(
|
|
2259
|
-
(
|
|
2242
|
+
(i) => !!i.MUL,
|
|
2260
2243
|
() => "MUL"
|
|
2261
2244
|
).when(
|
|
2262
|
-
(
|
|
2245
|
+
(i) => !!i.AVG,
|
|
2263
2246
|
() => "AVG"
|
|
2264
2247
|
).otherwise(() => {
|
|
2265
2248
|
throw new Error("Unknown aggregate function");
|
|
2266
2249
|
}),
|
|
2267
|
-
expression: t.STAR ? "*" :
|
|
2250
|
+
expression: t.STAR ? "*" : t.expression?.[0] ? this.visit(t.expression[0]) : { type: "term", term: { type: "literal", value: "", datatype: "xsd:string" } },
|
|
2268
2251
|
...t.DISTINCT && { distinct: !0 }
|
|
2269
2252
|
};
|
|
2270
2253
|
}
|
|
2271
2254
|
aggregateFunction2(t) {
|
|
2272
|
-
var i, s;
|
|
2273
2255
|
return {
|
|
2274
2256
|
function: p(t).when(
|
|
2275
|
-
(
|
|
2257
|
+
(i) => !!i.MIN_ARGMIN,
|
|
2276
2258
|
() => "MIN_ARGMIN"
|
|
2277
2259
|
).when(
|
|
2278
|
-
(
|
|
2260
|
+
(i) => !!i.MAX_ARGMIN,
|
|
2279
2261
|
() => "MAX_ARGMIN"
|
|
2280
2262
|
).when(
|
|
2281
|
-
(
|
|
2263
|
+
(i) => !!i.MIN_ARGMAX,
|
|
2282
2264
|
() => "MIN_ARGMAX"
|
|
2283
2265
|
).when(
|
|
2284
|
-
(
|
|
2266
|
+
(i) => !!i.MAX_ARGMAX,
|
|
2285
2267
|
() => "MAX_ARGMAX"
|
|
2286
2268
|
).otherwise(() => {
|
|
2287
2269
|
throw new Error("Unknown aggregate function");
|
|
2288
2270
|
}),
|
|
2289
|
-
expression: this.visit(
|
|
2271
|
+
expression: this.visit(O(t.firstExpr?.[0], "AggregateFunction2 missing first expression")),
|
|
2290
2272
|
secondExpression: this.visit(
|
|
2291
|
-
|
|
2273
|
+
O(t.secondExpr?.[0], "AggregateFunction2 missing second expression")
|
|
2292
2274
|
),
|
|
2293
2275
|
...t.DISTINCT && { distinct: !0 }
|
|
2294
2276
|
};
|
|
@@ -2319,33 +2301,32 @@ class Ln extends mn {
|
|
|
2319
2301
|
);
|
|
2320
2302
|
}
|
|
2321
2303
|
relationalExpression(t) {
|
|
2322
|
-
var i;
|
|
2323
2304
|
const r = this.visit(t.additiveExpression);
|
|
2324
2305
|
if (t.IN) {
|
|
2325
|
-
const
|
|
2306
|
+
const i = !!t.NOT, s = t.argumentList?.[0], o = s ? this.visit(s) : [];
|
|
2326
2307
|
return {
|
|
2327
2308
|
type: "in",
|
|
2328
|
-
negated:
|
|
2309
|
+
negated: i,
|
|
2329
2310
|
expression: r,
|
|
2330
2311
|
list: o
|
|
2331
2312
|
};
|
|
2332
2313
|
}
|
|
2333
2314
|
return t.additiveExpression.length > 1 ? {
|
|
2334
2315
|
type: "binary",
|
|
2335
|
-
operator: p(t).with({ EQUALS:
|
|
2316
|
+
operator: p(t).with({ EQUALS: l.when(Boolean) }, () => "=").with({ NOT_EQUALS: l.when(Boolean) }, () => "!=").with({ LESS_THAN: l.when(Boolean) }, () => "<").with({ GREATER_THAN: l.when(Boolean) }, () => ">").with({ LESS_THAN_OR_EQUAL: l.when(Boolean) }, () => "<=").with({ GREATER_THAN_OR_EQUAL: l.when(Boolean) }, () => ">=").otherwise(() => "="),
|
|
2336
2317
|
left: r,
|
|
2337
2318
|
right: t.additiveExpression[1] ? this.visit(t.additiveExpression[1]) : r
|
|
2338
2319
|
} : r;
|
|
2339
2320
|
}
|
|
2340
2321
|
additiveExpression(t) {
|
|
2341
|
-
const r =
|
|
2322
|
+
const r = Ve([
|
|
2342
2323
|
{ arr: t.PLUS, op: "+" },
|
|
2343
2324
|
{ arr: t.MINUS, op: "-" }
|
|
2344
2325
|
]);
|
|
2345
2326
|
return t.multiplicativeExpression.slice(1).reduce(
|
|
2346
|
-
(i, s,
|
|
2327
|
+
(i, s, o) => ({
|
|
2347
2328
|
type: "binary",
|
|
2348
|
-
operator: r[
|
|
2329
|
+
operator: r[o] ?? "+",
|
|
2349
2330
|
left: i,
|
|
2350
2331
|
right: this.visit(s)
|
|
2351
2332
|
}),
|
|
@@ -2353,14 +2334,14 @@ class Ln extends mn {
|
|
|
2353
2334
|
);
|
|
2354
2335
|
}
|
|
2355
2336
|
multiplicativeExpression(t) {
|
|
2356
|
-
const r =
|
|
2337
|
+
const r = Ve([
|
|
2357
2338
|
{ arr: t.STAR, op: "*" },
|
|
2358
2339
|
{ arr: t.SLASH, op: "/" }
|
|
2359
2340
|
]);
|
|
2360
2341
|
return t.unaryExpression.slice(1).reduce(
|
|
2361
|
-
(i, s,
|
|
2342
|
+
(i, s, o) => ({
|
|
2362
2343
|
type: "binary",
|
|
2363
|
-
operator: r[
|
|
2344
|
+
operator: r[o] ?? "*",
|
|
2364
2345
|
left: i,
|
|
2365
2346
|
right: this.visit(s)
|
|
2366
2347
|
}),
|
|
@@ -2369,21 +2350,21 @@ class Ln extends mn {
|
|
|
2369
2350
|
}
|
|
2370
2351
|
unaryExpression(t) {
|
|
2371
2352
|
return p(t).with(
|
|
2372
|
-
{ EXCLAMATION:
|
|
2353
|
+
{ EXCLAMATION: l.when(Boolean) },
|
|
2373
2354
|
() => ({
|
|
2374
2355
|
type: "unary",
|
|
2375
2356
|
operator: "!",
|
|
2376
2357
|
operand: this.visit(t.primaryExpression)
|
|
2377
2358
|
})
|
|
2378
2359
|
).with(
|
|
2379
|
-
{ PLUS:
|
|
2360
|
+
{ PLUS: l.when(Boolean) },
|
|
2380
2361
|
() => ({
|
|
2381
2362
|
type: "unary",
|
|
2382
2363
|
operator: "+",
|
|
2383
2364
|
operand: this.visit(t.primaryExpression)
|
|
2384
2365
|
})
|
|
2385
2366
|
).with(
|
|
2386
|
-
{ MINUS:
|
|
2367
|
+
{ MINUS: l.when(Boolean) },
|
|
2387
2368
|
() => ({
|
|
2388
2369
|
type: "unary",
|
|
2389
2370
|
operator: "-",
|
|
@@ -2392,10 +2373,9 @@ class Ln extends mn {
|
|
|
2392
2373
|
).otherwise(() => this.visit(t.primaryExpression));
|
|
2393
2374
|
}
|
|
2394
2375
|
functionCall(t) {
|
|
2395
|
-
return p(t).with({ concatFunction:
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
return { type: "function", name: s, args: a };
|
|
2376
|
+
return p(t).with({ concatFunction: l.when(d) }, (r) => this.visit(r.concatFunction[0])).with({ strFunction: l.when(d) }, (r) => this.visit(r.strFunction[0])).with({ ifFunction: l.when(d) }, (r) => this.visit(r.ifFunction[0])).with({ iriFunction: l.when(d) }, (r) => this.visit(r.iriFunction[0])).with({ skolemFunction: l.when(d) }, (r) => this.visit(r.skolemFunction[0])).with({ roundFunction: l.when(d) }, (r) => this.visit(r.roundFunction[0])).with({ regexFunction: l.when(d) }, (r) => this.visit(r.regexFunction[0])).with({ iri: l.when(d), LPAREN: l.when(d) }, (r) => {
|
|
2377
|
+
const i = r.iri[0] ? this.visit(r.iri[0]) : null, s = i && typeof i == "object" && "type" in i && i.type === "iri" && "value" in i ? String(i.value) : "unknown", o = r.argumentList?.[0] ? this.visit(r.argumentList[0]) : [];
|
|
2378
|
+
return { type: "function", name: s, args: o };
|
|
2399
2379
|
}).otherwise(() => {
|
|
2400
2380
|
throw new Error("Unknown function call type");
|
|
2401
2381
|
});
|
|
@@ -2444,12 +2424,11 @@ class Ln extends mn {
|
|
|
2444
2424
|
};
|
|
2445
2425
|
}
|
|
2446
2426
|
regexFunction(t) {
|
|
2447
|
-
var i;
|
|
2448
2427
|
const r = [
|
|
2449
|
-
this.visit(
|
|
2450
|
-
this.visit(
|
|
2428
|
+
this.visit(O(t.textExpr, "REGEX missing text expression")),
|
|
2429
|
+
this.visit(O(t.patternExpr, "REGEX missing pattern expression"))
|
|
2451
2430
|
];
|
|
2452
|
-
return
|
|
2431
|
+
return t.flagsExpr?.[0] && r.push(this.visit(t.flagsExpr)), {
|
|
2453
2432
|
type: "function",
|
|
2454
2433
|
name: "REGEX",
|
|
2455
2434
|
args: r
|
|
@@ -2459,13 +2438,13 @@ class Ln extends mn {
|
|
|
2459
2438
|
return t.expression.map((r) => this.visit(r));
|
|
2460
2439
|
}
|
|
2461
2440
|
primaryExpression(t) {
|
|
2462
|
-
return p(t).with({ expression:
|
|
2441
|
+
return p(t).with({ expression: l.when(d) }, (r) => this.visit(r.expression[0])).with({ functionCall: l.when(d) }, (r) => this.visit(r.functionCall[0])).with({ literal: l.when(d) }, (r) => ({ type: "term", term: this.visit(r.literal[0]) })).with({ VARIABLE: l.when(d) }, (r) => ({
|
|
2463
2442
|
type: "term",
|
|
2464
2443
|
term: { type: "variable", name: r.VARIABLE[0].image.substring(1) }
|
|
2465
|
-
})).with({ BLANK_NODE:
|
|
2444
|
+
})).with({ BLANK_NODE: l.when(d) }, (r) => ({
|
|
2466
2445
|
type: "term",
|
|
2467
2446
|
term: { type: "blank", label: r.BLANK_NODE[0].image.substring(2) }
|
|
2468
|
-
})).with({ iri:
|
|
2447
|
+
})).with({ iri: l.when(d) }, (r) => ({ type: "term", term: this.visit(r.iri[0]) })).otherwise(() => {
|
|
2469
2448
|
throw new Error("Unknown primary expression type");
|
|
2470
2449
|
});
|
|
2471
2450
|
}
|
|
@@ -2473,7 +2452,7 @@ class Ln extends mn {
|
|
|
2473
2452
|
return this.visit(t).value;
|
|
2474
2453
|
}
|
|
2475
2454
|
numericTokenLiteral(t, r) {
|
|
2476
|
-
const i =
|
|
2455
|
+
const i = K(t);
|
|
2477
2456
|
return {
|
|
2478
2457
|
type: "literal",
|
|
2479
2458
|
value: t.image,
|
|
@@ -2489,382 +2468,378 @@ class Ln extends mn {
|
|
|
2489
2468
|
return t.substring(3, t.length - 3).replace(/\\(.)/g, "$1");
|
|
2490
2469
|
}
|
|
2491
2470
|
}
|
|
2492
|
-
let
|
|
2493
|
-
function
|
|
2494
|
-
return
|
|
2471
|
+
let mn;
|
|
2472
|
+
function ve() {
|
|
2473
|
+
return mn ??= new gn();
|
|
2495
2474
|
}
|
|
2496
|
-
function
|
|
2475
|
+
function I(e, t) {
|
|
2497
2476
|
t.forEach((r) => e.add(r));
|
|
2498
2477
|
}
|
|
2499
|
-
function
|
|
2478
|
+
function B(e, t, r) {
|
|
2500
2479
|
t.forEach((i) => {
|
|
2501
2480
|
e.has(i) || r.add(i);
|
|
2502
2481
|
});
|
|
2503
2482
|
}
|
|
2504
|
-
function
|
|
2505
|
-
p(e).with({ type:
|
|
2506
|
-
|
|
2483
|
+
function yt(e, t) {
|
|
2484
|
+
p(e).with({ type: l.union("triple", "property", "class", "general") }, (r) => {
|
|
2485
|
+
I(t, rt(r));
|
|
2507
2486
|
}).with({ type: "filter" }, (r) => {
|
|
2508
|
-
|
|
2487
|
+
I(t, w(r.expression));
|
|
2509
2488
|
}).with({ type: "bind" }, (r) => {
|
|
2510
|
-
|
|
2489
|
+
I(t, w(r.expression)), t.add(r.variable);
|
|
2511
2490
|
}).with({ type: "skolem" }, (r) => {
|
|
2512
|
-
r.args.forEach((i) =>
|
|
2491
|
+
r.args.forEach((i) => I(t, w(i)));
|
|
2513
2492
|
}).with({ type: "negation" }, (r) => {
|
|
2514
|
-
var s;
|
|
2515
2493
|
const i = /* @__PURE__ */ new Set();
|
|
2516
|
-
r.formulas.forEach((
|
|
2494
|
+
r.formulas.forEach((s) => yt(s, i)), r.existentialVars?.forEach((s) => i.delete(s)), I(t, [...i]);
|
|
2517
2495
|
}).with({ type: "aggregate" }, (r) => {
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
t.add(a.variable), a.expression !== "*" && M(t, T(a.expression)), a.secondExpression && M(t, T(a.secondExpression));
|
|
2496
|
+
r.atoms.forEach((i) => yt(i, t)), r.onVars?.forEach((i) => t.add(i)), r.bindings?.forEach((i) => {
|
|
2497
|
+
t.add(i.variable), i.expression !== "*" && I(t, w(i.expression)), i.secondExpression && I(t, w(i.secondExpression));
|
|
2521
2498
|
});
|
|
2522
2499
|
}).exhaustive();
|
|
2523
2500
|
}
|
|
2524
|
-
function
|
|
2525
|
-
p(e).with({ type:
|
|
2526
|
-
|
|
2501
|
+
function yr(e, t) {
|
|
2502
|
+
p(e).with({ type: l.union("triple", "property", "class", "general") }, (r) => {
|
|
2503
|
+
I(t, rt(r));
|
|
2527
2504
|
}).with({ type: "skolem" }, (r) => {
|
|
2528
|
-
const i =
|
|
2505
|
+
const i = Kr(r);
|
|
2529
2506
|
i && t.add(i);
|
|
2530
|
-
}).with({ type:
|
|
2507
|
+
}).with({ type: l.union("bind", "filter", "negation", "aggregate") }, () => {
|
|
2531
2508
|
}).exhaustive();
|
|
2532
2509
|
}
|
|
2533
|
-
function
|
|
2534
|
-
|
|
2510
|
+
function yn(e, t, r, i) {
|
|
2511
|
+
B(r, w(t), i), r.add(e);
|
|
2535
2512
|
}
|
|
2536
|
-
function
|
|
2537
|
-
var o;
|
|
2513
|
+
function Lr(e, t, r) {
|
|
2538
2514
|
const i = /* @__PURE__ */ new Set();
|
|
2539
|
-
e.atoms.forEach((
|
|
2515
|
+
e.atoms.forEach((a) => yr(a, i));
|
|
2540
2516
|
const s = e.onVars ?? [];
|
|
2541
|
-
s.forEach((
|
|
2542
|
-
t.has(
|
|
2543
|
-
}), e.atoms.forEach((
|
|
2544
|
-
const
|
|
2545
|
-
e.atoms.forEach((
|
|
2546
|
-
|
|
2547
|
-
}),
|
|
2548
|
-
|
|
2517
|
+
s.forEach((a) => {
|
|
2518
|
+
t.has(a) && i.add(a);
|
|
2519
|
+
}), e.atoms.forEach((a) => wr(a, i, r));
|
|
2520
|
+
const o = /* @__PURE__ */ new Set();
|
|
2521
|
+
e.atoms.forEach((a) => yt(a, o)), s.forEach((a) => {
|
|
2522
|
+
o.has(a) && i.has(a) ? t.add(a) : r.add(a);
|
|
2523
|
+
}), e.bindings?.forEach((a) => {
|
|
2524
|
+
a.expression !== "*" && B(i, w(a.expression), r), a.secondExpression && B(i, w(a.secondExpression), r), t.add(a.variable);
|
|
2549
2525
|
});
|
|
2550
2526
|
}
|
|
2551
|
-
function
|
|
2527
|
+
function Ur(e, t, r) {
|
|
2552
2528
|
const i = new Set(t);
|
|
2553
|
-
|
|
2554
|
-
p(s).with({ type: "aggregate" }, (
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
Ut(a, o), F(i, [...o], r);
|
|
2529
|
+
I(i, e.existentialVars ?? []), e.formulas.forEach((s) => {
|
|
2530
|
+
p(s).with({ type: "aggregate" }, (o) => {
|
|
2531
|
+
B(i, o.onVars ?? [], r), B(i, o.bindings?.map(({ variable: a }) => a) ?? [], r), Lr(o, i, r);
|
|
2532
|
+
}).with({ type: "negation" }, (o) => {
|
|
2533
|
+
Ur(o, i, r);
|
|
2534
|
+
}).otherwise((o) => {
|
|
2535
|
+
const a = /* @__PURE__ */ new Set();
|
|
2536
|
+
yt(o, a), B(i, [...a], r);
|
|
2562
2537
|
});
|
|
2563
2538
|
});
|
|
2564
2539
|
}
|
|
2565
|
-
function
|
|
2566
|
-
p(e).with({ type:
|
|
2540
|
+
function wr(e, t, r) {
|
|
2541
|
+
p(e).with({ type: l.union("triple", "property", "class", "general") }, () => {
|
|
2567
2542
|
}).with({ type: "filter" }, (i) => {
|
|
2568
|
-
|
|
2543
|
+
B(t, w(i.expression), r);
|
|
2569
2544
|
}).with({ type: "bind" }, (i) => {
|
|
2570
|
-
|
|
2545
|
+
yn(i.variable, i.expression, t, r);
|
|
2571
2546
|
}).with({ type: "skolem" }, (i) => {
|
|
2572
|
-
i.args.slice(0, -1).forEach((s) =>
|
|
2547
|
+
i.args.slice(0, -1).forEach((s) => B(t, w(s), r));
|
|
2573
2548
|
}).with({ type: "negation" }, (i) => {
|
|
2574
|
-
wr(i, t, r);
|
|
2575
|
-
}).with({ type: "aggregate" }, (i) => {
|
|
2576
2549
|
Ur(i, t, r);
|
|
2550
|
+
}).with({ type: "aggregate" }, (i) => {
|
|
2551
|
+
Lr(i, t, r);
|
|
2577
2552
|
}).exhaustive();
|
|
2578
2553
|
}
|
|
2579
|
-
function
|
|
2554
|
+
function Ln(e) {
|
|
2580
2555
|
const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
2581
|
-
return e.body.forEach((i) =>
|
|
2556
|
+
return e.body.forEach((i) => yr(i, t)), e.body.forEach((i) => wr(i, t, r)), e.head.forEach((i) => B(t, rt(i), r)), [...r].sort();
|
|
2582
2557
|
}
|
|
2583
|
-
function
|
|
2558
|
+
function Ar(e, t) {
|
|
2584
2559
|
const r = t(e);
|
|
2585
|
-
return { ...
|
|
2560
|
+
return { ...ve().visit(r), raw: e };
|
|
2586
2561
|
}
|
|
2587
|
-
function
|
|
2588
|
-
return
|
|
2562
|
+
function qe(e) {
|
|
2563
|
+
return Ar(e, ur);
|
|
2589
2564
|
}
|
|
2590
|
-
function
|
|
2591
|
-
return { ...
|
|
2565
|
+
function Ts(e) {
|
|
2566
|
+
return { ...Ar(e, vi), grounded: !0 };
|
|
2592
2567
|
}
|
|
2593
|
-
function
|
|
2568
|
+
function q(e) {
|
|
2594
2569
|
return e !== void 0 && Number.isFinite(e) ? e : void 0;
|
|
2595
2570
|
}
|
|
2596
|
-
function
|
|
2597
|
-
const t =
|
|
2571
|
+
function Un(e) {
|
|
2572
|
+
const t = q(e.startOffset), r = q(e.endOffset);
|
|
2598
2573
|
return { offset: t, endOffset: r === void 0 ? void 0 : r + 1 };
|
|
2599
2574
|
}
|
|
2600
|
-
function
|
|
2601
|
-
const t =
|
|
2575
|
+
function Tr(e) {
|
|
2576
|
+
const t = Re(e);
|
|
2602
2577
|
if (t) return { ok: !1, issues: [t] };
|
|
2603
|
-
const r =
|
|
2578
|
+
const r = Ne(e);
|
|
2604
2579
|
if (r.errors.length > 0)
|
|
2605
2580
|
return {
|
|
2606
2581
|
ok: !1,
|
|
2607
|
-
issues: r.errors.map((
|
|
2608
|
-
message:
|
|
2609
|
-
line:
|
|
2610
|
-
column:
|
|
2611
|
-
offset:
|
|
2612
|
-
endOffset:
|
|
2582
|
+
issues: r.errors.map((a) => ({
|
|
2583
|
+
message: a.message,
|
|
2584
|
+
line: q(a.line),
|
|
2585
|
+
column: q(a.column),
|
|
2586
|
+
offset: a.offset,
|
|
2587
|
+
endOffset: a.offset + a.length
|
|
2613
2588
|
}))
|
|
2614
2589
|
};
|
|
2615
|
-
const i =
|
|
2590
|
+
const i = be(e, r.tokens);
|
|
2616
2591
|
if (i) return { ok: !1, issues: [i] };
|
|
2617
|
-
const s =
|
|
2592
|
+
const s = xe();
|
|
2618
2593
|
s.input = r.tokens;
|
|
2619
|
-
const
|
|
2594
|
+
const o = s.rule();
|
|
2620
2595
|
if (s.errors.length > 0)
|
|
2621
2596
|
return {
|
|
2622
2597
|
ok: !1,
|
|
2623
|
-
issues: s.errors.map((
|
|
2624
|
-
message:
|
|
2625
|
-
line:
|
|
2626
|
-
column:
|
|
2627
|
-
...
|
|
2598
|
+
issues: s.errors.map((a) => ({
|
|
2599
|
+
message: a.message,
|
|
2600
|
+
line: q(a.token.startLine),
|
|
2601
|
+
column: q(a.token.startColumn),
|
|
2602
|
+
...Un(a.token)
|
|
2628
2603
|
}))
|
|
2629
2604
|
};
|
|
2630
2605
|
try {
|
|
2631
|
-
return { ok: !0, rule: { ...
|
|
2632
|
-
} catch (
|
|
2606
|
+
return { ok: !0, rule: { ...ve().visit(o), raw: e } };
|
|
2607
|
+
} catch (a) {
|
|
2633
2608
|
return {
|
|
2634
2609
|
ok: !1,
|
|
2635
|
-
issues: [{ message:
|
|
2610
|
+
issues: [{ message: a instanceof Error ? a.message : "Invalid Datalog rule" }]
|
|
2636
2611
|
};
|
|
2637
2612
|
}
|
|
2638
2613
|
}
|
|
2639
|
-
function
|
|
2640
|
-
const t =
|
|
2641
|
-
return t.ok ? { ok: !0, vocabulary:
|
|
2614
|
+
function Ss(e) {
|
|
2615
|
+
const t = Tr(e);
|
|
2616
|
+
return t.ok ? { ok: !0, vocabulary: Di(t.rule) } : t;
|
|
2642
2617
|
}
|
|
2643
|
-
function
|
|
2644
|
-
if (
|
|
2645
|
-
const t =
|
|
2646
|
-
if (t.errors.length > 0 ||
|
|
2647
|
-
const r =
|
|
2618
|
+
function wn(e) {
|
|
2619
|
+
if (Re(e)) return;
|
|
2620
|
+
const t = Ne(e);
|
|
2621
|
+
if (t.errors.length > 0 || be(e, t.tokens)) return;
|
|
2622
|
+
const r = xe();
|
|
2648
2623
|
r.input = t.tokens;
|
|
2649
2624
|
const i = r.term();
|
|
2650
2625
|
if (!(r.errors.length > 0 || !r.atEndOfInput))
|
|
2651
|
-
return
|
|
2626
|
+
return ve().visit(i);
|
|
2652
2627
|
}
|
|
2653
|
-
function
|
|
2654
|
-
const t =
|
|
2628
|
+
function Xe(e) {
|
|
2629
|
+
const t = wn(e), r = t?.type === "iri" && !t.prefixed && !Ke(t.value);
|
|
2655
2630
|
return t && !r ? t : void 0;
|
|
2656
2631
|
}
|
|
2657
|
-
function
|
|
2658
|
-
const r =
|
|
2632
|
+
function Ns(e, t) {
|
|
2633
|
+
const r = Xe(e), i = Xe(t);
|
|
2659
2634
|
if (!(!r || !i))
|
|
2660
|
-
return
|
|
2635
|
+
return Je(r, i);
|
|
2661
2636
|
}
|
|
2662
|
-
function
|
|
2663
|
-
const t =
|
|
2637
|
+
function Rs(e) {
|
|
2638
|
+
const t = Tr(e);
|
|
2664
2639
|
if (!t.ok)
|
|
2665
2640
|
return {
|
|
2666
2641
|
valid: !1,
|
|
2667
2642
|
error: t.issues.map(({ message: s }) => s).join("; ") || "Invalid Datalog rule"
|
|
2668
2643
|
};
|
|
2669
|
-
const r =
|
|
2644
|
+
const r = Ln(t.rule);
|
|
2670
2645
|
return r.length === 0 ? { valid: !0 } : {
|
|
2671
2646
|
valid: !1,
|
|
2672
2647
|
error: `Unbound variables ${r.map((s) => `?${s}`).join(", ")}. Bind each variable with a body atom, BIND, AGGREGATE, or SKOLEM, or declare negation-local variables with NOT EXIST ?variable IN (...). AGGREGATE ON variables must also occur in the aggregate body.`
|
|
2673
2648
|
};
|
|
2674
2649
|
}
|
|
2675
|
-
function
|
|
2650
|
+
function bs(e, t) {
|
|
2676
2651
|
try {
|
|
2677
|
-
const r =
|
|
2678
|
-
return r.head.length !== i.head.length ? !1 :
|
|
2652
|
+
const r = qe(e), i = qe(t);
|
|
2653
|
+
return r.head.length !== i.head.length ? !1 : He(e) === He(t);
|
|
2679
2654
|
} catch {
|
|
2680
2655
|
return !1;
|
|
2681
2656
|
}
|
|
2682
2657
|
}
|
|
2683
|
-
function
|
|
2658
|
+
function He(e) {
|
|
2684
2659
|
return e.replace(/\s+/g, " ").replace(/\s*([(),[\]])\s*/g, "$1").replace(/\s*:-\s*/g, ":-").trim();
|
|
2685
2660
|
}
|
|
2686
2661
|
export {
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2662
|
+
Lt as AGGREGATE,
|
|
2663
|
+
pe as AND,
|
|
2664
|
+
z as AS,
|
|
2665
|
+
nr as AT,
|
|
2666
|
+
qt as AVG,
|
|
2667
|
+
Q as BIND,
|
|
2668
|
+
J as BLANK_NODE,
|
|
2669
|
+
En as BaseDatalogVisitor,
|
|
2670
|
+
sr as COLON,
|
|
2671
|
+
S as COMMA,
|
|
2672
|
+
Li as COMMENT,
|
|
2673
|
+
Yt as CONCAT,
|
|
2674
|
+
Dt as COUNT,
|
|
2675
|
+
Ht as COUNT_MAX,
|
|
2676
|
+
Xt as COUNT_MIN,
|
|
2677
|
+
we as DECIMAL,
|
|
2678
|
+
Le as DEFAULT_NS_IRI,
|
|
2679
|
+
ot as DISTINCT,
|
|
2680
|
+
fe as DOT,
|
|
2681
|
+
Ae as DOUBLE,
|
|
2682
|
+
gn as DatalogAstBuilder,
|
|
2683
|
+
Oe as DatalogParser,
|
|
2684
|
+
se as EQUALS,
|
|
2685
|
+
Ee as EXCLAMATION,
|
|
2686
|
+
kt as EXISTS,
|
|
2687
|
+
bi as ExpandedDatalogParser,
|
|
2688
|
+
ne as FALSE,
|
|
2689
|
+
$t as FILTER,
|
|
2690
|
+
ue as GREATER_THAN,
|
|
2691
|
+
ce as GREATER_THAN_OR_EQUAL,
|
|
2692
|
+
Et as HAT,
|
|
2693
|
+
tt as IDENTIFIER,
|
|
2694
|
+
Jt as IF,
|
|
2695
|
+
W as IN,
|
|
2696
|
+
Ue as INTEGER,
|
|
2697
|
+
me as INTERNAL_FUNCTION,
|
|
2698
|
+
te as IRI,
|
|
2699
|
+
ge as IRI_REF,
|
|
2700
|
+
Se as LANGTAG,
|
|
2701
|
+
ht as LBRACKET,
|
|
2702
|
+
oe as LESS_THAN,
|
|
2703
|
+
le as LESS_THAN_OR_EQUAL,
|
|
2704
|
+
L as LPAREN,
|
|
2705
|
+
_t as MAX,
|
|
2706
|
+
Wt as MAX_ARGMAX,
|
|
2707
|
+
zt as MAX_ARGMIN,
|
|
2708
|
+
Gt as MIN,
|
|
2709
|
+
ct as MINUS,
|
|
2710
|
+
Kt as MIN_ARGMAX,
|
|
2711
|
+
Qt as MIN_ARGMIN,
|
|
2712
|
+
jt as MUL,
|
|
2713
|
+
at as NOT,
|
|
2714
|
+
ae as NOT_EQUALS,
|
|
2715
|
+
Ut as ON,
|
|
2716
|
+
he as OR,
|
|
2717
|
+
ut as PLUS,
|
|
2718
|
+
it as PREFIXED_NAME,
|
|
2719
|
+
wt as PREFIX_ONLY,
|
|
2720
|
+
dt as RBRACKET,
|
|
2721
|
+
re as REGEX,
|
|
2722
|
+
ee as ROUND,
|
|
2723
|
+
U as RPAREN,
|
|
2724
|
+
Pt as RULE_ARROW,
|
|
2725
|
+
lt as SKOLEM,
|
|
2726
|
+
de as SLASH,
|
|
2727
|
+
pt as STAR,
|
|
2728
|
+
Zt as STR,
|
|
2729
|
+
ft as STRING_LITERAL,
|
|
2730
|
+
Te as STRING_LITERAL_LONG,
|
|
2731
|
+
Vt as SUM,
|
|
2732
|
+
ie as TRUE,
|
|
2733
|
+
N as VARIABLE,
|
|
2734
|
+
Ui as WHITESPACE,
|
|
2735
|
+
or as allTokens,
|
|
2736
|
+
bs as areRulesEquivalent,
|
|
2737
|
+
ir as assertNoGroundedTargets,
|
|
2738
|
+
ve as astBuilder,
|
|
2739
|
+
os as atomToDatalogText,
|
|
2740
|
+
un as beginTransaction,
|
|
2741
|
+
Zr as binaryOperandNeedsParentheses,
|
|
2742
|
+
Ti as booleanLiteralTokenTypes,
|
|
2743
|
+
Ai as builtinFunctionTokenTypes,
|
|
2744
|
+
He as canonicalRuleText,
|
|
2745
|
+
Ye as classAssertionFromAtom,
|
|
2746
|
+
ws as collectVariableTypeEvidence,
|
|
2747
|
+
cn as commitTransaction,
|
|
2748
|
+
ln as createConnection,
|
|
2749
|
+
fi as datalogBodyToSparqlSelect,
|
|
2750
|
+
er as datatypeToTermText,
|
|
2751
|
+
hn as deleteConnection,
|
|
2752
|
+
hs as delimiterTokenTypes,
|
|
2753
|
+
xi as expandedParserInstance,
|
|
2754
|
+
ms as explainInferenceFailure,
|
|
2755
|
+
X as expressionToDatalogParts,
|
|
2756
|
+
ls as expressionToDatalogText,
|
|
2757
|
+
Ss as extractRuleVocabulary,
|
|
2758
|
+
Di as extractRuleVocabularyFromAst,
|
|
2759
|
+
pr as extractRuleVocabularyFromAtom,
|
|
2760
|
+
ss as extractVariables,
|
|
2761
|
+
Ot as formulaContainsSkolem,
|
|
2762
|
+
Qn as getAggregateFunction,
|
|
2763
|
+
qn as getAtomType,
|
|
2764
|
+
Hn as getExpressionType,
|
|
2765
|
+
as as getRelatedVariables,
|
|
2766
|
+
Xn as getTermType,
|
|
2767
|
+
Mr as getVariablesFromAtom,
|
|
2768
|
+
Br as getVariablesFromAtomIncludingGraph,
|
|
2769
|
+
Jn as invertComparisonOperator,
|
|
2770
|
+
ze as iriBodyCharClass,
|
|
2771
|
+
cs as iriTokenTypes,
|
|
2772
|
+
$n as isAggregateFormula,
|
|
2773
|
+
ts as isBareNumericLiteral,
|
|
2774
|
+
Gn as isBinaryExpression,
|
|
2775
|
+
kn as isBindFormula,
|
|
2776
|
+
Bn as isBlankNodeTerm,
|
|
2777
|
+
tr as isBooleanLiteral,
|
|
2778
|
+
Cn as isClassAtom,
|
|
2779
|
+
Zn as isComparisonOperator,
|
|
2780
|
+
Me as isDatalogAtom,
|
|
2781
|
+
qr as isDateLiteral,
|
|
2782
|
+
Xr as isDateTimeLiteral,
|
|
2783
|
+
Pn as isFilterFormula,
|
|
2784
|
+
Ke as isFullIri,
|
|
2785
|
+
jn as isFunctionCallExpression,
|
|
2786
|
+
In as isGeneralAtom,
|
|
2787
|
+
Mn as isIriTerm,
|
|
2788
|
+
Z as isLiteralTerm,
|
|
2789
|
+
Kn as isLogicalOperator,
|
|
2790
|
+
Fn as isNegationFormula,
|
|
2791
|
+
H as isNumericLiteral,
|
|
2792
|
+
es as isNumericLiteralTerm,
|
|
2793
|
+
zn as isNumericOperator,
|
|
2794
|
+
Nt as isNumericRdfValue,
|
|
2795
|
+
vn as isPropertyAtom,
|
|
2796
|
+
Wn as isQueryableTermIri,
|
|
2797
|
+
ys as isReadOnlySparqlQuery,
|
|
2798
|
+
Dn as isSkolemFormula,
|
|
2799
|
+
Vn as isTermExpression,
|
|
2800
|
+
xn as isTripleAtom,
|
|
2801
|
+
_n as isUnaryExpression,
|
|
2802
|
+
v as isVariableTerm,
|
|
2803
|
+
et as isXsdDatatype,
|
|
2804
|
+
wi as keywordTokenTypes,
|
|
2805
|
+
ns as literalSetComparisonFromExpression,
|
|
2806
|
+
rs as literalToDisplayText,
|
|
2807
|
+
us as numericLiteralTokenTypes,
|
|
2808
|
+
ps as operatorTokenTypes,
|
|
2809
|
+
Yn as parseBooleanLiteral,
|
|
2810
|
+
qe as parseDatalogRule,
|
|
2811
|
+
Tr as parseDatalogRuleWithIssues,
|
|
2812
|
+
wn as parseDatalogTermText,
|
|
2813
|
+
Ts as parseGroundedDatalogRule,
|
|
2814
|
+
vi as parseGroundedRule,
|
|
2815
|
+
ur as parseRule,
|
|
2816
|
+
lr as parseRuleWith,
|
|
2817
|
+
xe as parserInstance,
|
|
2818
|
+
Vr as plainDecimalText,
|
|
2819
|
+
We as positiveBodyContainsSkolem,
|
|
2820
|
+
Ze as propertyAssertionFromAtom,
|
|
2821
|
+
As as resolveVariableTypes,
|
|
2822
|
+
pn as rollbackTransaction,
|
|
2823
|
+
Hr as simpleComparisonFromExpression,
|
|
2824
|
+
is as simpleComparisonFromFilter,
|
|
2825
|
+
Kr as skolemMintedVariable,
|
|
2826
|
+
Si as stringLiteralTokenTypes,
|
|
2827
|
+
Ns as termTextsEqual,
|
|
2828
|
+
b as termToDatalogText,
|
|
2829
|
+
fs as termToSparql,
|
|
2830
|
+
ds as termTokenTypes,
|
|
2831
|
+
Je as termsEqual,
|
|
2832
|
+
Ne as tokenizeDatalog,
|
|
2833
|
+
Jr as unaryOperandNeedsParentheses,
|
|
2834
|
+
D as unwrapTermExpression,
|
|
2835
|
+
Ls as validateDataManipulationUpdate,
|
|
2836
|
+
Rs as validateDatalogRule,
|
|
2837
|
+
Es as validateRuleSyntax,
|
|
2838
|
+
en as validateSparqlQuery,
|
|
2839
|
+
zr as variableNameFromTermExpression,
|
|
2840
|
+
rt as variableNamesFromAtom,
|
|
2841
|
+
w as variableNamesFromExpression,
|
|
2842
|
+
gs as verifyRuleInference,
|
|
2843
|
+
Us as withTransaction,
|
|
2844
|
+
V as xsdDatatypes
|
|
2870
2845
|
};
|