@oml/owl 0.19.3 → 0.20.0
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/out/index.d.ts +3 -0
- package/out/index.js +3 -0
- package/out/index.js.map +1 -1
- package/out/owl/owl-abox.d.ts +16 -5
- package/out/owl/owl-abox.js +365 -188
- package/out/owl/owl-abox.js.map +1 -1
- package/out/owl/owl-imports.js +4 -2
- package/out/owl/owl-imports.js.map +1 -1
- package/out/owl/owl-interfaces.d.ts +26 -1
- package/out/owl/owl-mapper.d.ts +2 -0
- package/out/owl/owl-mapper.js +77 -38
- package/out/owl/owl-mapper.js.map +1 -1
- package/out/owl/owl-service.d.ts +4 -0
- package/out/owl/owl-service.js +139 -44
- package/out/owl/owl-service.js.map +1 -1
- package/out/owl/owl-shacl.d.ts +8 -9
- package/out/owl/owl-shacl.js +43 -117
- package/out/owl/owl-shacl.js.map +1 -1
- package/out/owl/owl-sparql-engine.d.ts +6 -0
- package/out/owl/owl-sparql-engine.js +11 -0
- package/out/owl/owl-sparql-engine.js.map +1 -0
- package/out/owl/owl-sparql-oxigraph.d.ts +34 -0
- package/out/owl/owl-sparql-oxigraph.js +436 -0
- package/out/owl/owl-sparql-oxigraph.js.map +1 -0
- package/out/owl/owl-sparql.d.ts +0 -44
- package/out/owl/owl-sparql.js +0 -320
- package/out/owl/owl-sparql.js.map +1 -1
- package/out/owl/owl-store-lean.d.ts +29 -0
- package/out/owl/owl-store-lean.js +445 -0
- package/out/owl/owl-store-lean.js.map +1 -0
- package/out/owl/owl-store.d.ts +11 -1
- package/out/owl/owl-store.js +80 -6
- package/out/owl/owl-store.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/owl/owl-abox.ts +401 -200
- package/src/owl/owl-imports.ts +4 -2
- package/src/owl/owl-interfaces.ts +28 -1
- package/src/owl/owl-mapper.ts +79 -41
- package/src/owl/owl-service.ts +149 -49
- package/src/owl/owl-shacl.ts +55 -132
- package/src/owl/owl-sparql-engine.ts +34 -0
- package/src/owl/owl-sparql-oxigraph.ts +527 -0
- package/src/owl/owl-sparql.ts +3 -366
- package/src/owl/owl-store-lean.ts +438 -0
- package/src/owl/owl-store.ts +86 -7
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
|
+
const XSD_STRING = 'http://www.w3.org/2001/XMLSchema#string';
|
|
3
|
+
const RDF_LANG_STRING = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString';
|
|
4
|
+
export class OxigraphSparqlService {
|
|
5
|
+
constructor(reasoningStore, importGraph, aboxEntailmentCache, reasoningService, resolveOntologyIriForModelUri) {
|
|
6
|
+
this.reasoningStore = reasoningStore;
|
|
7
|
+
this.importGraph = importGraph;
|
|
8
|
+
this.aboxEntailmentCache = aboxEntailmentCache;
|
|
9
|
+
this.reasoningService = reasoningService;
|
|
10
|
+
// Per-query-context Oxigraph store, keyed by the queried model URI. Each store holds only
|
|
11
|
+
// that model's import closure under ontology-IRI graph names, so queries can use
|
|
12
|
+
// use_default_graph_as_union (fast) instead of a huge explicit graph list (which Oxigraph
|
|
13
|
+
// evaluates ~200x slower: 24ms vs 5s for this workspace's closure).
|
|
14
|
+
//
|
|
15
|
+
// `mirrored` records, per closure model, the generation of its data currently in the store and
|
|
16
|
+
// the ontology IRI its graphs live under. On the next query the store is re-synced against the
|
|
17
|
+
// global `modelGen`: only models whose generation advanced (edited/re-chained) are re-loaded,
|
|
18
|
+
// and models that left the closure are cleared — so an edit patches a few graphs instead of
|
|
19
|
+
// rebuilding the whole mirror.
|
|
20
|
+
this.contextStores = new Map();
|
|
21
|
+
this.ontologyIriResolver = resolveOntologyIriForModelUri ?? ((modelUri) => modelUri);
|
|
22
|
+
}
|
|
23
|
+
setOntologyIriResolver(resolver) {
|
|
24
|
+
this.ontologyIriResolver = resolver;
|
|
25
|
+
}
|
|
26
|
+
invalidateFilteredStore(_modelUri) {
|
|
27
|
+
// No-op: the mirror re-syncs against the reasoning store's per-model data generation on
|
|
28
|
+
// every query (see syncStore), so a cached store never needs to be dropped or explicitly
|
|
29
|
+
// flagged when a closure member changes — only the models whose data actually changed are
|
|
30
|
+
// re-loaded. (Kept on the interface for the Comunica engine, which caches differently.)
|
|
31
|
+
}
|
|
32
|
+
removeFilteredStore(modelUri) {
|
|
33
|
+
// A query context that no longer exists — drop its cached store.
|
|
34
|
+
this.contextStores.delete(modelUri);
|
|
35
|
+
}
|
|
36
|
+
targetGraphIris(ontologyIri) {
|
|
37
|
+
return [ontologyIri, `${ontologyIri}__entailments`, `${ontologyIri}__shacl_rules`];
|
|
38
|
+
}
|
|
39
|
+
async query(modelUri, sparql) {
|
|
40
|
+
try {
|
|
41
|
+
const { context, warnings } = await this.prepare(modelUri);
|
|
42
|
+
const result = this.execute(sparql, context);
|
|
43
|
+
const rows = [];
|
|
44
|
+
for (const binding of result) {
|
|
45
|
+
const row = new Map();
|
|
46
|
+
for (const [variable, term] of binding) {
|
|
47
|
+
if (!isQueryValueTerm(term)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
row.set(variable, toQueryTerm(term));
|
|
51
|
+
}
|
|
52
|
+
rows.push(row);
|
|
53
|
+
}
|
|
54
|
+
return { success: true, rows, warnings };
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return { success: false, rows: [], warnings: this.safeMissingWarnings(modelUri), error: messageOf(error) };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async construct(modelUri, sparql) {
|
|
61
|
+
try {
|
|
62
|
+
const { context, warnings } = await this.prepare(modelUri);
|
|
63
|
+
const result = this.execute(sparql, context);
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const quads = [];
|
|
66
|
+
for (const quad of result) {
|
|
67
|
+
const key = `${quad.subject.value}\x00${quad.predicate.value}\x00${quad.object.value}`;
|
|
68
|
+
if (!seen.has(key)) {
|
|
69
|
+
seen.add(key);
|
|
70
|
+
quads.push(quad);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { success: true, quads, warnings };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return { success: false, quads: [], warnings: [], error: messageOf(error) };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async ask(modelUri, sparql) {
|
|
80
|
+
try {
|
|
81
|
+
const { context, warnings } = await this.prepare(modelUri);
|
|
82
|
+
const result = this.execute(sparql, context);
|
|
83
|
+
return { success: true, result: Boolean(result), warnings };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { success: false, result: false, warnings: [], error: messageOf(error) };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async withMaterializedQuads(modelUri, quads, action) {
|
|
90
|
+
// Oxigraph queries read the cached mirror, not the live N3 store, so attaching the quads to
|
|
91
|
+
// the N3 store (as Comunica does) would be invisible here. Instead apply them as a delta
|
|
92
|
+
// directly to the cached context store's shaclRules graph, then remove them afterwards —
|
|
93
|
+
// far cheaper than invalidating and rebuilding the whole closure mirror per SHACL rule.
|
|
94
|
+
if (quads.length === 0) {
|
|
95
|
+
return action();
|
|
96
|
+
}
|
|
97
|
+
await this.ensureModule();
|
|
98
|
+
// Build/refresh the context first so the delta lands on the store the query will read,
|
|
99
|
+
// and so prepare() inside `action` is a cache hit that does not rebuild it without the delta.
|
|
100
|
+
this.ensureFreshEntailments(modelUri);
|
|
101
|
+
const mod = this.oxModule;
|
|
102
|
+
let targetGraph;
|
|
103
|
+
let store;
|
|
104
|
+
try {
|
|
105
|
+
store = this.getOrBuildContext(modelUri).store;
|
|
106
|
+
targetGraph = mod.namedNode(`${this.toOntologyGraphIri(this.resolveOntologyIri(modelUri))}__shacl_rules`);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return action();
|
|
110
|
+
}
|
|
111
|
+
const oxQuads = quads.map((q) => mod.quad(mod.fromTerm(q.subject), mod.fromTerm(q.predicate), mod.fromTerm(q.object), targetGraph));
|
|
112
|
+
for (const q of oxQuads) {
|
|
113
|
+
store.add(q);
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
return await action();
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
for (const q of oxQuads) {
|
|
120
|
+
store.delete(q);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// --- internals -------------------------------------------------------------
|
|
125
|
+
async ensureModule() {
|
|
126
|
+
if (this.oxModule) {
|
|
127
|
+
return this.oxModule;
|
|
128
|
+
}
|
|
129
|
+
if (!this.oxInit) {
|
|
130
|
+
this.oxInit = (async () => {
|
|
131
|
+
const mod = (await import('oxigraph'));
|
|
132
|
+
// In the browser worker the web build must be wasm-initialized before use; the worker
|
|
133
|
+
// entry kicks that off and exposes the promise. Await it here (first query). In Node
|
|
134
|
+
// the build auto-inits and no promise is present.
|
|
135
|
+
const ready = globalThis.__omlOxigraphInit;
|
|
136
|
+
if (ready) {
|
|
137
|
+
await ready;
|
|
138
|
+
}
|
|
139
|
+
this.oxModule = mod;
|
|
140
|
+
})();
|
|
141
|
+
}
|
|
142
|
+
await this.oxInit;
|
|
143
|
+
return this.oxModule;
|
|
144
|
+
}
|
|
145
|
+
async prepare(modelUri) {
|
|
146
|
+
this.ensureFreshEntailments(modelUri);
|
|
147
|
+
await this.ensureModule();
|
|
148
|
+
const context = this.getOrBuildContext(modelUri);
|
|
149
|
+
const warnings = this.composeWarnings(modelUri, context.missingModels);
|
|
150
|
+
return { context, warnings };
|
|
151
|
+
}
|
|
152
|
+
execute(sparql, context) {
|
|
153
|
+
// The context store holds only the closure, so unioning all its graphs reproduces the
|
|
154
|
+
// unionDefaultGraph semantics while keeping GRAPH ?g scoped to the closure.
|
|
155
|
+
const options = { use_default_graph_as_union: true };
|
|
156
|
+
if (context.baseIri) {
|
|
157
|
+
options.base_iri = context.baseIri;
|
|
158
|
+
}
|
|
159
|
+
return context.store.query(sparql, options);
|
|
160
|
+
}
|
|
161
|
+
// Build (or reuse a cached) Oxigraph store containing the queried model's full import
|
|
162
|
+
// closure, with each model's reasoned graphs remapped to ontology-IRI graph names.
|
|
163
|
+
getOrBuildContext(modelUri) {
|
|
164
|
+
const cached = this.contextStores.get(modelUri);
|
|
165
|
+
if (cached) {
|
|
166
|
+
const missingModels = this.syncStore(modelUri, cached);
|
|
167
|
+
return { store: cached.store, missingModels, baseIri: this.resolveBaseIri(modelUri) };
|
|
168
|
+
}
|
|
169
|
+
const mod = this.oxModule;
|
|
170
|
+
const store = new mod.Store();
|
|
171
|
+
const n3store = this.reasoningStore.getStore();
|
|
172
|
+
const allUris = [modelUri, ...this.importGraph.dependenciesOf(modelUri)];
|
|
173
|
+
const seen = new Set();
|
|
174
|
+
const missingModels = [];
|
|
175
|
+
const mirrored = new Map();
|
|
176
|
+
// Serialize the closure as N-Quads (graph as the 4th term) and bulk-load in batches.
|
|
177
|
+
// Per-graph load() calls cross the WASM boundary thousands of times for a large closure;
|
|
178
|
+
// batching collapses that to a handful of parse passes while keeping the in-flight buffer
|
|
179
|
+
// bounded (a single all-at-once buffer OOMs the Node heap on large workspaces).
|
|
180
|
+
const CHUNK_LINES = 100000;
|
|
181
|
+
let buffer = [];
|
|
182
|
+
const flush = () => {
|
|
183
|
+
if (buffer.length === 0) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
store.load(buffer.join('\n'), { format: 'application/n-quads' });
|
|
187
|
+
buffer = [];
|
|
188
|
+
};
|
|
189
|
+
for (const uri of allUris) {
|
|
190
|
+
if (seen.has(uri)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
seen.add(uri);
|
|
194
|
+
let sourceGraphs;
|
|
195
|
+
try {
|
|
196
|
+
sourceGraphs = this.reasoningStore.graphs(uri);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
missingModels.push(uri);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const ontologyIri = this.toOntologyGraphIri(this.resolveOntologyIri(uri));
|
|
203
|
+
mirrored.set(uri, { gen: this.reasoningStore.getModelDataGen(uri), ontologyIri });
|
|
204
|
+
const targets = [
|
|
205
|
+
[sourceGraphs.own, ontologyIri],
|
|
206
|
+
[sourceGraphs.entailments, `${ontologyIri}__entailments`],
|
|
207
|
+
[sourceGraphs.shaclRules, `${ontologyIri}__shacl_rules`],
|
|
208
|
+
];
|
|
209
|
+
for (const [sourceGraph, targetIri] of targets) {
|
|
210
|
+
const quads = n3store.getQuads(null, null, null, sourceGraph);
|
|
211
|
+
if (quads.length === 0) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const graphNT = `<${escapeIri(targetIri)}>`;
|
|
215
|
+
for (const quad of quads) {
|
|
216
|
+
buffer.push(quadToNQuad(quad, graphNT));
|
|
217
|
+
}
|
|
218
|
+
if (buffer.length >= CHUNK_LINES) {
|
|
219
|
+
flush();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
flush();
|
|
224
|
+
this.contextStores.set(modelUri, { store, mirrored });
|
|
225
|
+
return { store, missingModels, baseIri: this.resolveBaseIri(modelUri) };
|
|
226
|
+
}
|
|
227
|
+
// Re-sync a cached store against the current closure + per-model generations: re-load models
|
|
228
|
+
// whose data advanced, clear models that left the closure, leave everything else untouched.
|
|
229
|
+
syncStore(modelUri, entry) {
|
|
230
|
+
const closure = new Set([modelUri, ...this.importGraph.dependenciesOf(modelUri)]);
|
|
231
|
+
const toCheck = new Set([...closure, ...entry.mirrored.keys()]);
|
|
232
|
+
const missingModels = [];
|
|
233
|
+
for (const uri of toCheck) {
|
|
234
|
+
const have = entry.mirrored.get(uri);
|
|
235
|
+
if (!closure.has(uri)) {
|
|
236
|
+
if (have) {
|
|
237
|
+
this.clearModelInStore(entry, uri);
|
|
238
|
+
}
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const curGen = this.reasoningStore.getModelDataGen(uri);
|
|
242
|
+
if (!have || have.gen !== curGen) {
|
|
243
|
+
if (!this.patchModelInStore(entry, uri)) {
|
|
244
|
+
missingModels.push(uri);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return missingModels;
|
|
249
|
+
}
|
|
250
|
+
// Replace one model's graphs in a cached store with its current reasoned quads. Returns false
|
|
251
|
+
// if the model is no longer loaded/resolvable (its graphs are then cleared).
|
|
252
|
+
patchModelInStore(entry, uri) {
|
|
253
|
+
const curGen = this.reasoningStore.getModelDataGen(uri);
|
|
254
|
+
const prev = entry.mirrored.get(uri);
|
|
255
|
+
const graphsToClear = new Set(prev ? this.targetGraphIris(prev.ontologyIri) : []);
|
|
256
|
+
let sourceGraphs;
|
|
257
|
+
let ontologyIri;
|
|
258
|
+
try {
|
|
259
|
+
sourceGraphs = this.reasoningStore.graphs(uri);
|
|
260
|
+
ontologyIri = this.toOntologyGraphIri(this.resolveOntologyIri(uri));
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// Model no longer loaded/resolvable — clear whatever was mirrored and forget it.
|
|
264
|
+
for (const graph of graphsToClear) {
|
|
265
|
+
entry.store.update(`CLEAR SILENT GRAPH <${escapeIri(graph)}>`);
|
|
266
|
+
}
|
|
267
|
+
entry.mirrored.delete(uri);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
for (const graph of this.targetGraphIris(ontologyIri)) {
|
|
271
|
+
graphsToClear.add(graph);
|
|
272
|
+
}
|
|
273
|
+
for (const graph of graphsToClear) {
|
|
274
|
+
entry.store.update(`CLEAR SILENT GRAPH <${escapeIri(graph)}>`);
|
|
275
|
+
}
|
|
276
|
+
const n3store = this.reasoningStore.getStore();
|
|
277
|
+
const targets = [
|
|
278
|
+
[sourceGraphs.own, ontologyIri],
|
|
279
|
+
[sourceGraphs.entailments, `${ontologyIri}__entailments`],
|
|
280
|
+
[sourceGraphs.shaclRules, `${ontologyIri}__shacl_rules`],
|
|
281
|
+
];
|
|
282
|
+
const buffer = [];
|
|
283
|
+
for (const [sourceGraph, targetIri] of targets) {
|
|
284
|
+
const quads = n3store.getQuads(null, null, null, sourceGraph);
|
|
285
|
+
const graphNT = `<${escapeIri(targetIri)}>`;
|
|
286
|
+
for (const quad of quads) {
|
|
287
|
+
buffer.push(quadToNQuad(quad, graphNT));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (buffer.length > 0) {
|
|
291
|
+
entry.store.load(buffer.join('\n'), { format: 'application/n-quads' });
|
|
292
|
+
}
|
|
293
|
+
entry.mirrored.set(uri, { gen: curGen, ontologyIri });
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
clearModelInStore(entry, uri) {
|
|
297
|
+
const have = entry.mirrored.get(uri);
|
|
298
|
+
if (have) {
|
|
299
|
+
for (const graph of this.targetGraphIris(have.ontologyIri)) {
|
|
300
|
+
entry.store.update(`CLEAR SILENT GRAPH <${escapeIri(graph)}>`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
entry.mirrored.delete(uri);
|
|
304
|
+
}
|
|
305
|
+
resolveBaseIri(modelUri) {
|
|
306
|
+
// Mirror the Comunica path: relative IRIs in queries resolve against the model's own graph IRI.
|
|
307
|
+
try {
|
|
308
|
+
return this.reasoningStore.graphs(modelUri).own.value;
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
return modelUri;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
resolveOntologyIri(modelUri) {
|
|
315
|
+
const resolved = this.ontologyIriResolver(modelUri);
|
|
316
|
+
if (!resolved || resolved === modelUri) {
|
|
317
|
+
throw new Error(`Missing ontology IRI mapping for model '${modelUri}'.`);
|
|
318
|
+
}
|
|
319
|
+
return resolved;
|
|
320
|
+
}
|
|
321
|
+
toOntologyGraphIri(iri) {
|
|
322
|
+
return iri.endsWith('#') ? iri.slice(0, -1) : iri;
|
|
323
|
+
}
|
|
324
|
+
ensureFreshEntailments(modelUri) {
|
|
325
|
+
const closure = [modelUri, ...this.importGraph.dependenciesOf(modelUri)];
|
|
326
|
+
// Mirror runInference's own chaining condition: it only (re)chains a model that is dirty,
|
|
327
|
+
// or the query root when its entailments are absent. A non-root dependency that stays
|
|
328
|
+
// 'absent' (runInference never chains it, so its entailment graph is genuinely empty) must
|
|
329
|
+
// NOT be treated as stale here — otherwise every query re-runs inference and invalidates
|
|
330
|
+
// the whole mirror, even though nothing changed.
|
|
331
|
+
const stale = closure.filter((uri) => this.aboxEntailmentCache.isDirty(uri)
|
|
332
|
+
|| (uri === modelUri && this.aboxEntailmentCache.isAbsent(uri)));
|
|
333
|
+
if (stale.length === 0) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
// runInference re-chains the stale models, mutating their entailment graphs in the reasoning
|
|
337
|
+
// store — which bumps those models' data generations. getOrBuildContext's syncStore then
|
|
338
|
+
// re-loads exactly those models into cached mirrors; no explicit invalidation needed here.
|
|
339
|
+
this.reasoningService.runInference(modelUri);
|
|
340
|
+
}
|
|
341
|
+
composeWarnings(modelUri, missingModels) {
|
|
342
|
+
const closureWarnings = [modelUri, ...this.importGraph.dependenciesOf(modelUri)]
|
|
343
|
+
.flatMap((uri) => this.aboxEntailmentCache.getValidationWarnings(uri));
|
|
344
|
+
return [...new Set([...missingModels.map((uri) => `Model not loaded: ${uri}`), ...closureWarnings])];
|
|
345
|
+
}
|
|
346
|
+
safeMissingWarnings(modelUri) {
|
|
347
|
+
try {
|
|
348
|
+
return this.composeWarnings(modelUri, []);
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function isQueryValueTerm(term) {
|
|
356
|
+
return term.termType === 'NamedNode' || term.termType === 'BlankNode' || term.termType === 'Literal';
|
|
357
|
+
}
|
|
358
|
+
function toQueryTerm(term) {
|
|
359
|
+
if (term.termType === 'NamedNode') {
|
|
360
|
+
return { termType: 'NamedNode', value: term.value };
|
|
361
|
+
}
|
|
362
|
+
if (term.termType === 'BlankNode') {
|
|
363
|
+
return { termType: 'BlankNode', value: term.value };
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
termType: 'Literal',
|
|
367
|
+
value: term.value,
|
|
368
|
+
datatype: term.datatype?.value,
|
|
369
|
+
language: term.language,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function messageOf(error) {
|
|
373
|
+
return error instanceof Error ? error.message : String(error);
|
|
374
|
+
}
|
|
375
|
+
// --- N-Triples serialization (fast bulk-load path into Oxigraph) -----------------
|
|
376
|
+
// NOTE: blank nodes are serialized per-graph; a blank node shared across a model's own
|
|
377
|
+
// and entailment graphs would split into distinct nodes on reload. OML reasoning rarely
|
|
378
|
+
// shares blank nodes across these graphs, and the experimental flag documents this limit.
|
|
379
|
+
// N-Quads line: subject predicate object graph . — graphNT is the pre-serialized graph IRI.
|
|
380
|
+
function quadToNQuad(quad, graphNT) {
|
|
381
|
+
return `${termToNT(quad.subject)} ${termToNT(quad.predicate)} ${termToNT(quad.object)} ${graphNT} .`;
|
|
382
|
+
}
|
|
383
|
+
function termToNT(term) {
|
|
384
|
+
switch (term.termType) {
|
|
385
|
+
case 'NamedNode':
|
|
386
|
+
return `<${escapeIri(term.value)}>`;
|
|
387
|
+
case 'BlankNode':
|
|
388
|
+
return `_:${term.value}`;
|
|
389
|
+
case 'Literal': {
|
|
390
|
+
const literal = term;
|
|
391
|
+
const lex = `"${escapeLiteral(literal.value)}"`;
|
|
392
|
+
if (literal.language) {
|
|
393
|
+
return `${lex}@${literal.language}`;
|
|
394
|
+
}
|
|
395
|
+
const dt = literal.datatype?.value;
|
|
396
|
+
if (dt && dt !== XSD_STRING && dt !== RDF_LANG_STRING) {
|
|
397
|
+
return `${lex}^^<${escapeIri(dt)}>`;
|
|
398
|
+
}
|
|
399
|
+
return lex;
|
|
400
|
+
}
|
|
401
|
+
default:
|
|
402
|
+
throw new Error(`Unsupported term type for N-Triples serialization: ${term.termType}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const IRI_DELIMITERS = new Set(['<', '>', '"', '{', '}', '|', '^', '`', '\\']);
|
|
406
|
+
// Control chars (<= 0x20) or the IRIREF delimiters that are illegal unescaped.
|
|
407
|
+
const IRI_NEEDS_ESCAPE = /[\u0000-\u0020<>"{}|^\u0060\\]/;
|
|
408
|
+
function escapeIri(value) {
|
|
409
|
+
// Fast path: the overwhelming majority of OML IRIs contain no character needing escaping.
|
|
410
|
+
// Serializing the full closure runs this millions of times, so skip the char loop when clean.
|
|
411
|
+
if (!IRI_NEEDS_ESCAPE.test(value)) {
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
// N-Triples IRIREF: \uXXXX-escape control chars, space, and the delimiters illegal
|
|
415
|
+
// unescaped. \u escapes round-trip to the same code point, preserving the IRI value.
|
|
416
|
+
let out = '';
|
|
417
|
+
for (const ch of value) {
|
|
418
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
419
|
+
if (code <= 0x20 || IRI_DELIMITERS.has(ch)) {
|
|
420
|
+
out += `\\u${code.toString(16).toUpperCase().padStart(4, '0')}`;
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
out += ch;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return out;
|
|
427
|
+
}
|
|
428
|
+
function escapeLiteral(value) {
|
|
429
|
+
return value
|
|
430
|
+
.replace(/\\/g, '\\\\')
|
|
431
|
+
.replace(/"/g, '\\"')
|
|
432
|
+
.replace(/\n/g, '\\n')
|
|
433
|
+
.replace(/\r/g, '\\r')
|
|
434
|
+
.replace(/\t/g, '\\t');
|
|
435
|
+
}
|
|
436
|
+
//# sourceMappingURL=owl-sparql-oxigraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owl-sparql-oxigraph.js","sourceRoot":"","sources":["../../src/owl/owl-sparql-oxigraph.ts"],"names":[],"mappings":"AAAA,qDAAqD;AA8CrD,MAAM,UAAU,GAAG,yCAA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,qFAAqF;IACrF,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,IAAI,IAAI,IAAI,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACzC,GAAG,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QACpE,CAAC;aAAM,CAAC;YACJ,GAAG,IAAI,EAAE,CAAC;QACd,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAChC,OAAO,KAAK;SACP,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
package/out/owl/owl-sparql.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type * as RDF from '@rdfjs/types';
|
|
2
|
-
import type { NamedNode } from 'n3';
|
|
3
|
-
import type { OwlABoxEntailmentState, OwlImportGraph, OwlInferenceRunner, OwlStore } from './owl-interfaces.js';
|
|
4
2
|
import { deriveSelectQueryFromShacl, type DerivedShaclSelectQuery } from './owl-shacl.js';
|
|
5
3
|
export interface RDFTerm {
|
|
6
4
|
termType: 'NamedNode' | 'Literal' | 'BlankNode';
|
|
@@ -31,45 +29,3 @@ export type SparqlQueryKind = 'select' | 'ask' | 'construct' | 'describe' | 'unk
|
|
|
31
29
|
export declare function detectSparqlKind(sparql: string): SparqlQueryKind;
|
|
32
30
|
export type DerivedShapeSelectQuery = DerivedShaclSelectQuery;
|
|
33
31
|
export declare const deriveSelectQueryFromShape: typeof deriveSelectQueryFromShacl;
|
|
34
|
-
export declare class SparqlService {
|
|
35
|
-
private readonly reasoningStore;
|
|
36
|
-
private readonly importGraph;
|
|
37
|
-
private readonly aboxEntailmentCache;
|
|
38
|
-
private readonly reasoningService;
|
|
39
|
-
private readonly engine;
|
|
40
|
-
private readonly filteredStoreCache;
|
|
41
|
-
private readonly dirtyFilteredStores;
|
|
42
|
-
private ontologyIriResolver;
|
|
43
|
-
constructor(reasoningStore: OwlStore, importGraph: OwlImportGraph, aboxEntailmentCache: OwlABoxEntailmentState, reasoningService: OwlInferenceRunner, resolveOntologyIriForModelUri?: (modelUri: string) => string);
|
|
44
|
-
setOntologyIriResolver(resolver: (modelUri: string) => string): void;
|
|
45
|
-
/**
|
|
46
|
-
* Executes a SPARQL query over the model's reasoned context.
|
|
47
|
-
* Queries must use explicit GRAPH patterns to access data.
|
|
48
|
-
* Available named graphs for a model context are:
|
|
49
|
-
* <modelNamespace> - asserted quads
|
|
50
|
-
* <modelNamespace__entailments> - inferred quads
|
|
51
|
-
* The same pattern applies to all models in the import closure.
|
|
52
|
-
*/
|
|
53
|
-
query(modelUri: string, sparql: string): Promise<QueryResult>;
|
|
54
|
-
/**
|
|
55
|
-
* Executes a SPARQL SELECT query over currently available store state.
|
|
56
|
-
* This method does not trigger inference refresh.
|
|
57
|
-
* The same named-graph contract applies as query(): explicit GRAPH patterns are required.
|
|
58
|
-
*/
|
|
59
|
-
queryRaw(modelUri: string, sparql: string): Promise<QueryResult>;
|
|
60
|
-
construct(modelUri: string, sparql: string): Promise<ConstructResult>;
|
|
61
|
-
ask(modelUri: string, sparql: string): Promise<AskResult>;
|
|
62
|
-
getAvailableGraphs(modelUri: string): NamedNode[];
|
|
63
|
-
invalidateFilteredStore(modelUri: string): void;
|
|
64
|
-
removeFilteredStore(modelUri: string): void;
|
|
65
|
-
private querySelect;
|
|
66
|
-
private ensureFreshEntailments;
|
|
67
|
-
private resolveBaseIri;
|
|
68
|
-
private getQueryContext;
|
|
69
|
-
private toOntologyGraphIri;
|
|
70
|
-
private toRdfTerm;
|
|
71
|
-
private isQueryValueTerm;
|
|
72
|
-
private toMissingModelsWarnings;
|
|
73
|
-
private composeWarnings;
|
|
74
|
-
private getOrCreateFilteredStore;
|
|
75
|
-
}
|