eyeling 1.30.6 → 1.32.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/README.md +0 -161
- package/dist/browser/eyeling.browser.js +54 -638
- package/eyeling.js +54 -638
- package/index.d.ts +9 -49
- package/index.js +1 -2
- package/lib/cli.js +4 -11
- package/lib/engine.js +6 -14
- package/lib/lexer.js +2 -6
- package/lib/multisource.js +3 -5
- package/lib/rdfjs.js +39 -1
- package/package.json +4 -2
- package/test/examples.test.js +5 -37
- package/test/run.js +0 -1
- package/examples/input/rdf-surfaces-all-values-from-reverse.trig +0 -18
- package/examples/input/rdf-surfaces-all-values-from.trig +0 -14
- package/examples/input/rdf-surfaces-ancestor.trig +0 -21
- package/examples/input/rdf-surfaces-city.trig +0 -12
- package/examples/input/rdf-surfaces-disjunction-elimination.trig +0 -17
- package/examples/input/rdf-surfaces-disjunction-route-filter.trig +0 -12
- package/examples/input/rdf-surfaces-domain.trig +0 -12
- package/examples/input/rdf-surfaces-explicit-disjunction.trig +0 -23
- package/examples/input/rdf-surfaces-multi-premise.trig +0 -14
- package/examples/input/rdf-surfaces-owl-all-values-from-codex.trig +0 -36
- package/examples/input/rdf-surfaces-property-chain.trig +0 -14
- package/examples/input/rdf-surfaces-range.trig +0 -12
- package/examples/input/rdf-surfaces-rdf12-graph-triple-term.trig +0 -15
- package/examples/input/rdf-surfaces-rdf12-named-graph.trig +0 -14
- package/examples/input/rdf-surfaces-rdf12-triple-term.trig +0 -13
- package/examples/input/rdf-surfaces-rdfs-range-codex.trig +0 -19
- package/examples/input/rdf-surfaces-rdfs-subclass-codex.trig +0 -19
- package/examples/input/rdf-surfaces-strong-negation-access.trig +0 -15
- package/examples/output/rdf-surfaces-all-values-from-reverse.n3 +0 -3
- package/examples/output/rdf-surfaces-all-values-from.n3 +0 -3
- package/examples/output/rdf-surfaces-ancestor.n3 +0 -5
- package/examples/output/rdf-surfaces-city.n3 +0 -3
- package/examples/output/rdf-surfaces-disjunction-elimination.n3 +0 -3
- package/examples/output/rdf-surfaces-disjunction-route-filter.n3 +0 -3
- package/examples/output/rdf-surfaces-domain.n3 +0 -3
- package/examples/output/rdf-surfaces-explicit-disjunction.n3 +0 -3
- package/examples/output/rdf-surfaces-multi-premise.n3 +0 -3
- package/examples/output/rdf-surfaces-owl-all-values-from-codex.n3 +0 -6
- package/examples/output/rdf-surfaces-property-chain.n3 +0 -3
- package/examples/output/rdf-surfaces-range.n3 +0 -3
- package/examples/output/rdf-surfaces-rdf12-graph-triple-term.n3 +0 -3
- package/examples/output/rdf-surfaces-rdf12-named-graph.n3 +0 -3
- package/examples/output/rdf-surfaces-rdf12-triple-term.n3 +0 -3
- package/examples/output/rdf-surfaces-rdfs-range-codex.n3 +0 -3
- package/examples/output/rdf-surfaces-rdfs-subclass-codex.n3 +0 -3
- package/examples/output/rdf-surfaces-strong-negation-access.n3 +0 -4
- package/examples/rdf-surfaces-all-values-from-reverse.n3 +0 -6
- package/examples/rdf-surfaces-all-values-from.n3 +0 -6
- package/examples/rdf-surfaces-ancestor.n3 +0 -6
- package/examples/rdf-surfaces-city.n3 +0 -6
- package/examples/rdf-surfaces-disjunction-elimination.n3 +0 -13
- package/examples/rdf-surfaces-disjunction-route-filter.n3 +0 -24
- package/examples/rdf-surfaces-domain.n3 +0 -6
- package/examples/rdf-surfaces-explicit-disjunction.n3 +0 -16
- package/examples/rdf-surfaces-multi-premise.n3 +0 -6
- package/examples/rdf-surfaces-owl-all-values-from-codex.n3 +0 -10
- package/examples/rdf-surfaces-property-chain.n3 +0 -6
- package/examples/rdf-surfaces-range.n3 +0 -6
- package/examples/rdf-surfaces-rdf12-graph-triple-term.n3 +0 -6
- package/examples/rdf-surfaces-rdf12-named-graph.n3 +0 -6
- package/examples/rdf-surfaces-rdf12-triple-term.n3 +0 -6
- package/examples/rdf-surfaces-rdfs-range-codex.n3 +0 -6
- package/examples/rdf-surfaces-rdfs-subclass-codex.n3 +0 -6
- package/examples/rdf-surfaces-strong-negation-access.n3 +0 -20
- package/lib/rdf_surfaces.js +0 -598
- package/test/rdf_surfaces.test.js +0 -227
|
@@ -6090,7 +6090,7 @@ async function ingestLineBasedRdfSourceToStore(sourceLabel, store, { rdfMode = t
|
|
|
6090
6090
|
}
|
|
6091
6091
|
|
|
6092
6092
|
|
|
6093
|
-
async function runStreamMessagesMode(sourceLabels, { rdfMode,
|
|
6093
|
+
async function runStreamMessagesMode(sourceLabels, { rdfMode, storeName = null, storePath = null, storeClear = false } = {}) {
|
|
6094
6094
|
const ordinarySourceLabels = [];
|
|
6095
6095
|
const messageSourceLabels = [];
|
|
6096
6096
|
|
|
@@ -6128,7 +6128,6 @@ async function runStreamMessagesMode(sourceLabels, { rdfMode, rdfSurfacesMode =
|
|
|
6128
6128
|
keepSourceArtifacts: false,
|
|
6129
6129
|
sourceLocations: false,
|
|
6130
6130
|
rdf: rdfMode,
|
|
6131
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
6132
6131
|
}),
|
|
6133
6132
|
);
|
|
6134
6133
|
} catch (e) {
|
|
@@ -6162,7 +6161,6 @@ async function runStreamMessagesMode(sourceLabels, { rdfMode, rdfSurfacesMode =
|
|
|
6162
6161
|
keepSourceArtifacts: false,
|
|
6163
6162
|
sourceLocations: false,
|
|
6164
6163
|
rdf: false,
|
|
6165
|
-
rdfSurfaces: false,
|
|
6166
6164
|
});
|
|
6167
6165
|
} catch (e) {
|
|
6168
6166
|
if (e && e.name === 'N3SyntaxError') {
|
|
@@ -6217,7 +6215,6 @@ async function main() {
|
|
|
6217
6215
|
` -h, --help Show this help and exit.\n` +
|
|
6218
6216
|
` -p, --proof Enable proof explanations.\n` +
|
|
6219
6217
|
` -r, --rdf Enable RDF/TriG input/output compatibility.\n` +
|
|
6220
|
-
` --rdf-surfaces Enable RDF Surfaces %not[...%] syntax (implies --rdf).\n` +
|
|
6221
6218
|
` --stream-messages Process RDF Message Logs one message at a time under -r.\n` +
|
|
6222
6219
|
` --store <name> Use an optional persistent fact store.\n` +
|
|
6223
6220
|
` --store-clear Clear the named store before this run.\n` +
|
|
@@ -6293,8 +6290,7 @@ async function main() {
|
|
|
6293
6290
|
const showAst = argv.includes('--ast') || argv.includes('-a');
|
|
6294
6291
|
const streamMode = argv.includes('--stream') || argv.includes('-t');
|
|
6295
6292
|
const streamMessagesMode = argv.includes('--stream-messages');
|
|
6296
|
-
const
|
|
6297
|
-
const rdfMode = argv.includes('--rdf') || argv.includes('-r') || rdfSurfacesMode;
|
|
6293
|
+
const rdfMode = argv.includes('--rdf') || argv.includes('-r');
|
|
6298
6294
|
const storeName = argv.__storeName || null;
|
|
6299
6295
|
const storePath = argv.__storePath || null;
|
|
6300
6296
|
const storeClear = argv.includes('--store-clear');
|
|
@@ -6363,7 +6359,7 @@ async function main() {
|
|
|
6363
6359
|
}
|
|
6364
6360
|
|
|
6365
6361
|
if (streamMessagesMode) {
|
|
6366
|
-
await runStreamMessagesMode(sourceLabels, { rdfMode,
|
|
6362
|
+
await runStreamMessagesMode(sourceLabels, { rdfMode, storeName, storePath, storeClear });
|
|
6367
6363
|
return;
|
|
6368
6364
|
}
|
|
6369
6365
|
|
|
@@ -6417,7 +6413,6 @@ async function main() {
|
|
|
6417
6413
|
keepSourceArtifacts: false,
|
|
6418
6414
|
sourceLocations: false,
|
|
6419
6415
|
rdf: rdfMode,
|
|
6420
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
6421
6416
|
}),
|
|
6422
6417
|
);
|
|
6423
6418
|
} catch (e) {
|
|
@@ -6430,7 +6425,7 @@ async function main() {
|
|
|
6430
6425
|
}
|
|
6431
6426
|
|
|
6432
6427
|
const mergedRuleDocument = mergeParsedDocuments(parsedRuleSources);
|
|
6433
|
-
const result = await engine.runStoreBacked(mergedRuleDocument, store, { rdf: rdfMode
|
|
6428
|
+
const result = await engine.runStoreBacked(mergedRuleDocument, store, { rdf: rdfMode });
|
|
6434
6429
|
const outTriples = result.queryMode ? result.queryTriples || [] : (result.derived || []).map((df) => df.fact);
|
|
6435
6430
|
if (result.queryMode) {
|
|
6436
6431
|
const bodyText = engine.prettyPrintQueryTriples(outTriples, result.prefixes);
|
|
@@ -6465,7 +6460,6 @@ async function main() {
|
|
|
6465
6460
|
keepSourceArtifacts: false,
|
|
6466
6461
|
sourceLocations: engine.getProofCommentsEnabled(),
|
|
6467
6462
|
rdf: rdfMode,
|
|
6468
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
6469
6463
|
}),
|
|
6470
6464
|
);
|
|
6471
6465
|
} catch (e) {
|
|
@@ -6566,7 +6560,6 @@ function factsContainOutputStrings(triplesForOutput) {
|
|
|
6566
6560
|
{
|
|
6567
6561
|
proof: engine.getProofCommentsEnabled(),
|
|
6568
6562
|
rdf: rdfMode,
|
|
6569
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
6570
6563
|
store: { name: storeName, clear: storeClear, path: storePath || undefined },
|
|
6571
6564
|
},
|
|
6572
6565
|
);
|
|
@@ -10820,14 +10813,12 @@ function reasonStream(input, opts = {}) {
|
|
|
10820
10813
|
skipUnsupportedRdfJs = false,
|
|
10821
10814
|
builtinModules = null,
|
|
10822
10815
|
rdf = false,
|
|
10823
|
-
rdfSurfaces = false,
|
|
10824
10816
|
sourceLabel = '<input>',
|
|
10825
10817
|
} = opts;
|
|
10826
10818
|
|
|
10827
|
-
const useRdfCompatibility = !!rdf
|
|
10828
|
-
const useRdfSurfaces = !!rdfSurfaces;
|
|
10819
|
+
const useRdfCompatibility = !!rdf;
|
|
10829
10820
|
|
|
10830
|
-
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: useRdfCompatibility,
|
|
10821
|
+
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: useRdfCompatibility, sourceLocations: proof });
|
|
10831
10822
|
const parsedTextInput = (!parsedSourceList && proof && typeof input === 'string')
|
|
10832
10823
|
? parseN3Text(input, {
|
|
10833
10824
|
baseIri: baseIri || '',
|
|
@@ -10835,7 +10826,6 @@ function reasonStream(input, opts = {}) {
|
|
|
10835
10826
|
keepSourceArtifacts: false,
|
|
10836
10827
|
sourceLocations: true,
|
|
10837
10828
|
rdf: useRdfCompatibility,
|
|
10838
|
-
rdfSurfaces: useRdfSurfaces,
|
|
10839
10829
|
})
|
|
10840
10830
|
: null;
|
|
10841
10831
|
const hasInlineN3 = input && typeof input === 'object' && !Array.isArray(input) && typeof input.n3 === 'string';
|
|
@@ -10880,7 +10870,6 @@ function reasonStream(input, opts = {}) {
|
|
|
10880
10870
|
keepSourceArtifacts: false,
|
|
10881
10871
|
sourceLocations: proof,
|
|
10882
10872
|
rdf: useRdfCompatibility,
|
|
10883
|
-
rdfSurfaces: useRdfSurfaces,
|
|
10884
10873
|
});
|
|
10885
10874
|
prefixes = directDoc.prefixes;
|
|
10886
10875
|
triples = directDoc.triples;
|
|
@@ -10992,11 +10981,10 @@ async function __parseRunAsyncInput(input, opts) {
|
|
|
10992
10981
|
baseIri = null,
|
|
10993
10982
|
proof = false,
|
|
10994
10983
|
rdf = false,
|
|
10995
|
-
rdfSurfaces = false,
|
|
10996
10984
|
sourceLabel = '<input>',
|
|
10997
10985
|
} = opts || {};
|
|
10998
10986
|
|
|
10999
|
-
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: !!rdf
|
|
10987
|
+
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: !!rdf, sourceLocations: !!proof });
|
|
11000
10988
|
if (parsedSourceList) return parsedSourceList;
|
|
11001
10989
|
|
|
11002
10990
|
const parsedObject = await normalizeParsedReasonerInputAsync(input);
|
|
@@ -11011,8 +10999,7 @@ async function __parseRunAsyncInput(input, opts) {
|
|
|
11011
10999
|
label: sourceLabel || '<input>',
|
|
11012
11000
|
keepSourceArtifacts: false,
|
|
11013
11001
|
sourceLocations: !!proof,
|
|
11014
|
-
rdf: !!rdf
|
|
11015
|
-
rdfSurfaces: !!rdfSurfaces,
|
|
11002
|
+
rdf: !!rdf,
|
|
11016
11003
|
});
|
|
11017
11004
|
}
|
|
11018
11005
|
|
|
@@ -11088,8 +11075,7 @@ async function __proveGoalsAgainstStore(goals, subst, store, backRules, localFac
|
|
|
11088
11075
|
async function runStoreBacked(input, store, opts = {}) {
|
|
11089
11076
|
const parsed = parseN3SourceList(input, {
|
|
11090
11077
|
baseIri: opts.baseIri || null,
|
|
11091
|
-
rdf: !!opts.rdf
|
|
11092
|
-
rdfSurfaces: !!opts.rdfSurfaces,
|
|
11078
|
+
rdf: !!opts.rdf,
|
|
11093
11079
|
sourceLocations: !!opts.proof,
|
|
11094
11080
|
}) || input;
|
|
11095
11081
|
|
|
@@ -11206,8 +11192,7 @@ async function runAsync(input, opts = {}) {
|
|
|
11206
11192
|
if (!storeConfig) {
|
|
11207
11193
|
const normalizedInput = parseN3SourceList(input, {
|
|
11208
11194
|
baseIri: runOpts.baseIri || null,
|
|
11209
|
-
rdf: !!runOpts.rdf
|
|
11210
|
-
rdfSurfaces: !!runOpts.rdfSurfaces,
|
|
11195
|
+
rdf: !!runOpts.rdf,
|
|
11211
11196
|
sourceLocations: !!runOpts.proof,
|
|
11212
11197
|
}) || (await normalizeReasonerInputAsync(input));
|
|
11213
11198
|
return reasonStream(normalizedInput, runOpts);
|
|
@@ -12457,8 +12442,6 @@ module.exports = { tryParseFastRdfText, parseFastRdfText, parseFastRdfMessageLog
|
|
|
12457
12442
|
|
|
12458
12443
|
'use strict';
|
|
12459
12444
|
|
|
12460
|
-
const { normalizeRdfSurfaces } = require('./rdf_surfaces');
|
|
12461
|
-
|
|
12462
12445
|
class Token {
|
|
12463
12446
|
constructor(typ, value = null, offset = null) {
|
|
12464
12447
|
this.typ = typ;
|
|
@@ -12852,7 +12835,7 @@ function normalizeRdfCompatibility(inputText) {
|
|
|
12852
12835
|
// unless they actually contain RDF 1.2 triple terms, VERSION directives, or a
|
|
12853
12836
|
// plausible top-level TriG named graph block.
|
|
12854
12837
|
const hasTripleTerms = text.includes('<<');
|
|
12855
|
-
const hasVersionDirective = /^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic
|
|
12838
|
+
const hasVersionDirective = /^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic)\1\s*\.?\s*(?:#.*)?$/im.test(text);
|
|
12856
12839
|
const hasMessageVersionDirective = /^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic)-messages\1\s*\.?\s*(?:#.*)?$/im.test(text);
|
|
12857
12840
|
const hasNamedGraphCandidate = /(?:^|[.\r\n])\s*(?:GRAPH\s+)?(?:<[^>\r\n]*>|_:[A-Za-z][A-Za-z0-9_-]*|[A-Za-z][A-Za-z0-9_-]*:[^\s{};,.()[\]]*|:[^\s{};,.()[\]]+)\s*\{/m.test(text);
|
|
12858
12841
|
const hasAnnotationSyntax = /(?:^|\s)~|\{\|/.test(text);
|
|
@@ -13321,7 +13304,7 @@ function normalizeRdfCompatibility(inputText) {
|
|
|
13321
13304
|
}
|
|
13322
13305
|
|
|
13323
13306
|
function stripVersionDirectives(s) {
|
|
13324
|
-
return s.replace(/^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic
|
|
13307
|
+
return s.replace(/^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic)(?:-messages)?\1\s*\.?\s*(?:#.*)?$/gim, '');
|
|
13325
13308
|
}
|
|
13326
13309
|
|
|
13327
13310
|
function skipWsAndComments(s, at) {
|
|
@@ -13799,9 +13782,7 @@ function isNumericLikeIdentifier(word) {
|
|
|
13799
13782
|
|
|
13800
13783
|
function lex(inputText, opts = {}) {
|
|
13801
13784
|
const rdf = !!(opts && opts.rdf);
|
|
13802
|
-
const rdfSurfaces = !!(opts && opts.rdfSurfaces);
|
|
13803
13785
|
if (rdf) inputText = normalizeRdfCompatibility(inputText);
|
|
13804
|
-
if (rdfSurfaces) inputText = normalizeRdfSurfaces(inputText);
|
|
13805
13786
|
// Avoid copying large ASCII/BMP inputs into an Array. Array.from() is
|
|
13806
13787
|
// only needed when the text contains surrogate pairs and we want the old
|
|
13807
13788
|
// code-point iteration behavior for non-BMP characters.
|
|
@@ -14584,10 +14565,9 @@ function parseN3Text(text, opts = {}) {
|
|
|
14584
14565
|
collectUsedPrefixes = false,
|
|
14585
14566
|
sourceLocations = false,
|
|
14586
14567
|
rdf = false,
|
|
14587
|
-
rdfSurfaces = false,
|
|
14588
14568
|
} = opts || {};
|
|
14589
14569
|
|
|
14590
|
-
if (rdf
|
|
14570
|
+
if (rdf) {
|
|
14591
14571
|
const fastDoc = tryParseFastRdfText(text, { baseIri, label });
|
|
14592
14572
|
if (fastDoc) {
|
|
14593
14573
|
if (sourceLocations) annotateParsedSourceLocations(fastDoc, text, label);
|
|
@@ -14596,7 +14576,7 @@ function parseN3Text(text, opts = {}) {
|
|
|
14596
14576
|
}
|
|
14597
14577
|
}
|
|
14598
14578
|
|
|
14599
|
-
const tokens = lex(text, { rdf
|
|
14579
|
+
const tokens = lex(text, { rdf });
|
|
14600
14580
|
const parser = new Parser(tokens);
|
|
14601
14581
|
if (baseIri) parser.prefixes.setBase(baseIri);
|
|
14602
14582
|
const [prefixes, triples, frules, brules, logQueryRules] = parser.parseDocument();
|
|
@@ -14795,8 +14775,7 @@ function parseN3SourceList(input, opts = {}) {
|
|
|
14795
14775
|
collectUsedPrefixes: true,
|
|
14796
14776
|
keepSourceArtifacts: !!opts.keepSourceArtifacts,
|
|
14797
14777
|
sourceLocations: !!opts.sourceLocations,
|
|
14798
|
-
rdf: !!opts.rdf
|
|
14799
|
-
rdfSurfaces: !!opts.rdfSurfaces,
|
|
14778
|
+
rdf: !!opts.rdf,
|
|
14800
14779
|
}),
|
|
14801
14780
|
);
|
|
14802
14781
|
return mergeParsedDocuments(parsed, {
|
|
@@ -16826,607 +16805,6 @@ module.exports = {
|
|
|
16826
16805
|
needsRdf12Version,
|
|
16827
16806
|
};
|
|
16828
16807
|
|
|
16829
|
-
};
|
|
16830
|
-
__modules["lib/rdf_surfaces.js"] = function(require, module, exports){
|
|
16831
|
-
/**
|
|
16832
|
-
* Eyeling Reasoner — RDF Surfaces syntax normalizer
|
|
16833
|
-
*
|
|
16834
|
-
* Implements a small RDF Surfaces text convention inspired by Hayes' BLOGIC
|
|
16835
|
-
* slides: `%not[ ... %]` surface parentheses with explicit blank mark binders
|
|
16836
|
-
* such as `_:x _:y` at the beginning of a surface. The supported fragment
|
|
16837
|
-
* covers slide 32, the slide 33 range shape, both slide 33 allValuesFrom
|
|
16838
|
-
* shapes, and top-level fuse surfaces.
|
|
16839
|
-
*
|
|
16840
|
-
* The normalizer rewrites the supported fragment into ordinary Eyeling N3:
|
|
16841
|
-
* %not[ _:x P(?x) . %not[ Q(?x) . %] %]
|
|
16842
|
-
* becomes:
|
|
16843
|
-
* { P(?x) . } => { Q(?x) . } .
|
|
16844
|
-
*
|
|
16845
|
-
* A top-level negative surface without an inner negative surface becomes an
|
|
16846
|
-
* inference fuse:
|
|
16847
|
-
* %not[ _:x P(?x) . %]
|
|
16848
|
-
* becomes:
|
|
16849
|
-
* { P(?x) . } => false .
|
|
16850
|
-
*/
|
|
16851
|
-
|
|
16852
|
-
'use strict';
|
|
16853
|
-
|
|
16854
|
-
function syntaxError(message, offset = null) {
|
|
16855
|
-
const e = new Error(message);
|
|
16856
|
-
e.name = 'N3SyntaxError';
|
|
16857
|
-
if (typeof offset === 'number') e.offset = offset;
|
|
16858
|
-
return e;
|
|
16859
|
-
}
|
|
16860
|
-
|
|
16861
|
-
function isWs(ch) {
|
|
16862
|
-
return ch != null && /\s/.test(ch);
|
|
16863
|
-
}
|
|
16864
|
-
|
|
16865
|
-
|
|
16866
|
-
function readStringAt(s, at) {
|
|
16867
|
-
const quote = s[at];
|
|
16868
|
-
let i = at;
|
|
16869
|
-
let out = quote;
|
|
16870
|
-
const long = s.startsWith(quote.repeat(3), i);
|
|
16871
|
-
if (long) {
|
|
16872
|
-
out = quote.repeat(3);
|
|
16873
|
-
i += 3;
|
|
16874
|
-
while (i < s.length) {
|
|
16875
|
-
if (s.startsWith(quote.repeat(3), i)) {
|
|
16876
|
-
out += quote.repeat(3);
|
|
16877
|
-
i += 3;
|
|
16878
|
-
return { text: out, end: i };
|
|
16879
|
-
}
|
|
16880
|
-
if (s[i] === '\\' && i + 1 < s.length) {
|
|
16881
|
-
out += s.slice(i, i + 2);
|
|
16882
|
-
i += 2;
|
|
16883
|
-
} else {
|
|
16884
|
-
out += s[i++];
|
|
16885
|
-
}
|
|
16886
|
-
}
|
|
16887
|
-
throw syntaxError('Unterminated string literal inside RDF Surface', at);
|
|
16888
|
-
}
|
|
16889
|
-
|
|
16890
|
-
i += 1;
|
|
16891
|
-
let escaped = false;
|
|
16892
|
-
while (i < s.length) {
|
|
16893
|
-
const ch = s[i++];
|
|
16894
|
-
out += ch;
|
|
16895
|
-
if (escaped) escaped = false;
|
|
16896
|
-
else if (ch === '\\') escaped = true;
|
|
16897
|
-
else if (ch === quote) return { text: out, end: i };
|
|
16898
|
-
}
|
|
16899
|
-
throw syntaxError('Unterminated string literal inside RDF Surface', at);
|
|
16900
|
-
}
|
|
16901
|
-
|
|
16902
|
-
function readIriAt(s, at) {
|
|
16903
|
-
let i = at + 1;
|
|
16904
|
-
let out = '<';
|
|
16905
|
-
while (i < s.length) {
|
|
16906
|
-
const ch = s[i++];
|
|
16907
|
-
out += ch;
|
|
16908
|
-
if (ch === '>') return { text: out, end: i };
|
|
16909
|
-
}
|
|
16910
|
-
throw syntaxError('Unterminated IRI inside RDF Surface', at);
|
|
16911
|
-
}
|
|
16912
|
-
|
|
16913
|
-
function skipWsAndComments(s, at) {
|
|
16914
|
-
let i = at;
|
|
16915
|
-
while (i < s.length) {
|
|
16916
|
-
if (isWs(s[i])) {
|
|
16917
|
-
i += 1;
|
|
16918
|
-
continue;
|
|
16919
|
-
}
|
|
16920
|
-
if (s[i] === '#') {
|
|
16921
|
-
while (i < s.length && s[i] !== '\n' && s[i] !== '\r') i += 1;
|
|
16922
|
-
continue;
|
|
16923
|
-
}
|
|
16924
|
-
break;
|
|
16925
|
-
}
|
|
16926
|
-
return i;
|
|
16927
|
-
}
|
|
16928
|
-
|
|
16929
|
-
function readBareTokenAt(s, at) {
|
|
16930
|
-
const i0 = skipWsAndComments(s, at);
|
|
16931
|
-
if (i0 >= s.length) return null;
|
|
16932
|
-
if (s[i0] === '<') return readIriAt(s, i0);
|
|
16933
|
-
if (s[i0] === '"' || s[i0] === "'") return readStringAt(s, i0);
|
|
16934
|
-
let i = i0;
|
|
16935
|
-
while (i < s.length && !isWs(s[i]) && !'{}[](),;.'.includes(s[i])) i += 1;
|
|
16936
|
-
if (i === i0) return null;
|
|
16937
|
-
return { text: s.slice(i0, i), start: i0, end: i };
|
|
16938
|
-
}
|
|
16939
|
-
|
|
16940
|
-
function readStatementSegment(s) {
|
|
16941
|
-
let i = 0;
|
|
16942
|
-
let depthBrace = 0;
|
|
16943
|
-
let depthBracket = 0;
|
|
16944
|
-
let depthParen = 0;
|
|
16945
|
-
while (i < s.length) {
|
|
16946
|
-
if (s.startsWith('%not[', i) && depthBrace === 0 && depthBracket === 0 && depthParen === 0) {
|
|
16947
|
-
return s.slice(0, i);
|
|
16948
|
-
}
|
|
16949
|
-
const ch = s[i];
|
|
16950
|
-
if (ch === '"' || ch === "'") {
|
|
16951
|
-
i = readStringAt(s, i).end;
|
|
16952
|
-
continue;
|
|
16953
|
-
}
|
|
16954
|
-
if (ch === '<') {
|
|
16955
|
-
i = readIriAt(s, i).end;
|
|
16956
|
-
continue;
|
|
16957
|
-
}
|
|
16958
|
-
if (ch === '#') {
|
|
16959
|
-
while (i < s.length && s[i] !== '\n' && s[i] !== '\r') i += 1;
|
|
16960
|
-
continue;
|
|
16961
|
-
}
|
|
16962
|
-
if (ch === '{') depthBrace += 1;
|
|
16963
|
-
else if (ch === '}' && depthBrace > 0) depthBrace -= 1;
|
|
16964
|
-
else if (ch === '[') depthBracket += 1;
|
|
16965
|
-
else if (ch === ']' && depthBracket > 0) depthBracket -= 1;
|
|
16966
|
-
else if (ch === '(') depthParen += 1;
|
|
16967
|
-
else if (ch === ')' && depthParen > 0) depthParen -= 1;
|
|
16968
|
-
else if (ch === '.' && depthBrace === 0 && depthBracket === 0 && depthParen === 0) return s.slice(0, i);
|
|
16969
|
-
i += 1;
|
|
16970
|
-
}
|
|
16971
|
-
return s;
|
|
16972
|
-
}
|
|
16973
|
-
|
|
16974
|
-
function tokenizeLeadingSegment(segment) {
|
|
16975
|
-
const toks = [];
|
|
16976
|
-
let pos = 0;
|
|
16977
|
-
while (pos < segment.length) {
|
|
16978
|
-
const tok = readBareTokenAt(segment, pos);
|
|
16979
|
-
if (!tok) break;
|
|
16980
|
-
toks.push(tok);
|
|
16981
|
-
pos = tok.end;
|
|
16982
|
-
}
|
|
16983
|
-
return toks;
|
|
16984
|
-
}
|
|
16985
|
-
|
|
16986
|
-
function extractLeadingBinders(raw) {
|
|
16987
|
-
const text = String(raw || '');
|
|
16988
|
-
const contentStart = skipWsAndComments(text, 0);
|
|
16989
|
-
if (contentStart >= text.length) return { binders: [], text };
|
|
16990
|
-
|
|
16991
|
-
// Preferred BLOGIC graffiti style: put newly bound marks on the `%not[`
|
|
16992
|
-
// line and put triples on following non-indented lines, e.g.
|
|
16993
|
-
// `%not[ _:x _:y\n_:x :p _:y .`. Reading that first line directly
|
|
16994
|
-
// avoids guessing from the first triple shape, which matters for RDF 1.2
|
|
16995
|
-
// formula objects and TriG named graph blocks.
|
|
16996
|
-
let lineEnd = text.indexOf('\n', contentStart);
|
|
16997
|
-
if (lineEnd < 0) lineEnd = text.length;
|
|
16998
|
-
let lineText = text.slice(contentStart, lineEnd);
|
|
16999
|
-
let newlineEnd = lineEnd < text.length ? lineEnd + 1 : lineEnd;
|
|
17000
|
-
if (lineText.endsWith('\r')) {
|
|
17001
|
-
lineText = lineText.slice(0, -1);
|
|
17002
|
-
}
|
|
17003
|
-
const lineTrim = lineText.trim();
|
|
17004
|
-
if (/^_:[A-Za-z_][A-Za-z0-9._-]*(?:\s+_:[A-Za-z_][A-Za-z0-9._-]*)*$/.test(lineTrim)) {
|
|
17005
|
-
const binders = lineTrim.split(/\s+/).map((tok) => tok.slice(2));
|
|
17006
|
-
return { binders, text: text.slice(0, contentStart) + text.slice(newlineEnd) };
|
|
17007
|
-
}
|
|
17008
|
-
|
|
17009
|
-
const segment = readStatementSegment(text.slice(contentStart));
|
|
17010
|
-
const toks = tokenizeLeadingSegment(segment);
|
|
17011
|
-
let leadingBlankCount = 0;
|
|
17012
|
-
while (leadingBlankCount < toks.length && /^_:[A-Za-z_][A-Za-z0-9._-]*$/.test(toks[leadingBlankCount].text)) {
|
|
17013
|
-
leadingBlankCount += 1;
|
|
17014
|
-
}
|
|
17015
|
-
|
|
17016
|
-
if (leadingBlankCount === 0) return { binders: [], text };
|
|
17017
|
-
|
|
17018
|
-
let binderCount = 0;
|
|
17019
|
-
if (toks.length >= 3) {
|
|
17020
|
-
// Prefer the longest explicit binder prefix that still leaves at least a
|
|
17021
|
-
// subject, predicate, and object for the first statement. This matches the
|
|
17022
|
-
// BLOGIC slide convention, e.g. `%not[ _:x _:x a :C . ... %]`.
|
|
17023
|
-
binderCount = Math.min(leadingBlankCount, Math.max(0, toks.length - 3));
|
|
17024
|
-
} else {
|
|
17025
|
-
// No own triple before a nested surface: treat the leading marks as binders.
|
|
17026
|
-
binderCount = leadingBlankCount;
|
|
17027
|
-
}
|
|
17028
|
-
|
|
17029
|
-
if (binderCount <= 0) return { binders: [], text };
|
|
17030
|
-
|
|
17031
|
-
const binders = toks.slice(0, binderCount).map((t) => t.text.slice(2));
|
|
17032
|
-
const cut = toks[binderCount - 1].end;
|
|
17033
|
-
return { binders, text: text.slice(0, contentStart) + text.slice(contentStart + cut) };
|
|
17034
|
-
}
|
|
17035
|
-
|
|
17036
|
-
|
|
17037
|
-
function readBalancedCurlyAt(s, at) {
|
|
17038
|
-
if (s[at] !== '{') return null;
|
|
17039
|
-
let i = at;
|
|
17040
|
-
let depth = 0;
|
|
17041
|
-
while (i < s.length) {
|
|
17042
|
-
const ch = s[i];
|
|
17043
|
-
if (ch === '"' || ch === "'") {
|
|
17044
|
-
i = readStringAt(s, i).end;
|
|
17045
|
-
continue;
|
|
17046
|
-
}
|
|
17047
|
-
if (ch === '<') {
|
|
17048
|
-
i = readIriAt(s, i).end;
|
|
17049
|
-
continue;
|
|
17050
|
-
}
|
|
17051
|
-
if (ch === '#') {
|
|
17052
|
-
while (i < s.length && s[i] !== '\n' && s[i] !== '\r') i += 1;
|
|
17053
|
-
continue;
|
|
17054
|
-
}
|
|
17055
|
-
if (ch === '{') depth += 1;
|
|
17056
|
-
else if (ch === '}') {
|
|
17057
|
-
depth -= 1;
|
|
17058
|
-
if (depth === 0) return { text: s.slice(at, i + 1), end: i + 1 };
|
|
17059
|
-
}
|
|
17060
|
-
i += 1;
|
|
17061
|
-
}
|
|
17062
|
-
throw syntaxError('Unterminated named graph block inside RDF Surface', at);
|
|
17063
|
-
}
|
|
17064
|
-
|
|
17065
|
-
function normalizeSurfaceStatement(statement) {
|
|
17066
|
-
const raw = String(statement || '').trim();
|
|
17067
|
-
if (!raw) return raw;
|
|
17068
|
-
|
|
17069
|
-
let i = 0;
|
|
17070
|
-
const first = readBareTokenAt(raw, i);
|
|
17071
|
-
if (first && /^GRAPH$/i.test(first.text)) {
|
|
17072
|
-
i = first.end;
|
|
17073
|
-
}
|
|
17074
|
-
|
|
17075
|
-
const term = readBareTokenAt(raw, i);
|
|
17076
|
-
if (!term) return raw;
|
|
17077
|
-
const afterTerm = skipWsAndComments(raw, term.end);
|
|
17078
|
-
if (raw[afterTerm] !== '{') return raw;
|
|
17079
|
-
|
|
17080
|
-
const block = readBalancedCurlyAt(raw, afterTerm);
|
|
17081
|
-
const afterBlock = skipWsAndComments(raw, block.end);
|
|
17082
|
-
if (afterBlock !== raw.length) return raw;
|
|
17083
|
-
|
|
17084
|
-
return `${term.text} ${LOG_NAME_OF_IRI} ${block.text}`;
|
|
17085
|
-
}
|
|
17086
|
-
|
|
17087
|
-
function splitTopLevelStatements(raw, surfaceOffset = null) {
|
|
17088
|
-
const text = String(raw || '');
|
|
17089
|
-
const out = [];
|
|
17090
|
-
let start = 0;
|
|
17091
|
-
let i = 0;
|
|
17092
|
-
let depthBrace = 0;
|
|
17093
|
-
let depthBracket = 0;
|
|
17094
|
-
let depthParen = 0;
|
|
17095
|
-
|
|
17096
|
-
while (i < text.length) {
|
|
17097
|
-
const ch = text[i];
|
|
17098
|
-
if (ch === '"' || ch === "'") {
|
|
17099
|
-
i = readStringAt(text, i).end;
|
|
17100
|
-
continue;
|
|
17101
|
-
}
|
|
17102
|
-
if (ch === '<') {
|
|
17103
|
-
i = readIriAt(text, i).end;
|
|
17104
|
-
continue;
|
|
17105
|
-
}
|
|
17106
|
-
if (ch === '#') {
|
|
17107
|
-
while (i < text.length && text[i] !== '\n' && text[i] !== '\r') i += 1;
|
|
17108
|
-
continue;
|
|
17109
|
-
}
|
|
17110
|
-
if (ch === '{') depthBrace += 1;
|
|
17111
|
-
else if (ch === '}' && depthBrace > 0) depthBrace -= 1;
|
|
17112
|
-
else if (ch === '[') depthBracket += 1;
|
|
17113
|
-
else if (ch === ']' && depthBracket > 0) depthBracket -= 1;
|
|
17114
|
-
else if (ch === '(') depthParen += 1;
|
|
17115
|
-
else if (ch === ')' && depthParen > 0) depthParen -= 1;
|
|
17116
|
-
else if (ch === '.' && depthBrace === 0 && depthBracket === 0 && depthParen === 0) {
|
|
17117
|
-
const stmt = text.slice(start, i).trim();
|
|
17118
|
-
if (stmt) out.push(normalizeSurfaceStatement(stmt));
|
|
17119
|
-
start = i + 1;
|
|
17120
|
-
}
|
|
17121
|
-
i += 1;
|
|
17122
|
-
}
|
|
17123
|
-
|
|
17124
|
-
const tail = text.slice(start).trim();
|
|
17125
|
-
if (tail) {
|
|
17126
|
-
// A raw binder-only segment is OK; RDF 1.2 TriG named graph blocks are
|
|
17127
|
-
// also OK without a trailing dot. Any other dangling text is most likely a
|
|
17128
|
-
// missing dot in the surface body.
|
|
17129
|
-
const normalizedTail = normalizeSurfaceStatement(tail);
|
|
17130
|
-
if (normalizedTail !== tail) {
|
|
17131
|
-
out.push(normalizedTail);
|
|
17132
|
-
} else if (!/^_:[A-Za-z_][A-Za-z0-9._-]*(?:\s+_:[A-Za-z_][A-Za-z0-9._-]*)*$/.test(tail)) {
|
|
17133
|
-
throw syntaxError('RDF Surface statement is missing a terminating dot', surfaceOffset);
|
|
17134
|
-
}
|
|
17135
|
-
}
|
|
17136
|
-
|
|
17137
|
-
return out;
|
|
17138
|
-
}
|
|
17139
|
-
|
|
17140
|
-
function readSurfaceAt(s, at) {
|
|
17141
|
-
if (!s.startsWith('%not[', at)) return null;
|
|
17142
|
-
let i = at + '%not['.length;
|
|
17143
|
-
let current = '';
|
|
17144
|
-
const segments = [];
|
|
17145
|
-
const children = [];
|
|
17146
|
-
|
|
17147
|
-
while (i < s.length) {
|
|
17148
|
-
if (s.startsWith('%]', i)) {
|
|
17149
|
-
segments.push(current);
|
|
17150
|
-
i += 2;
|
|
17151
|
-
const raw = segments.join('\n');
|
|
17152
|
-
const stripped = extractLeadingBinders(raw);
|
|
17153
|
-
return {
|
|
17154
|
-
type: 'not',
|
|
17155
|
-
start: at,
|
|
17156
|
-
end: i,
|
|
17157
|
-
binders: stripped.binders,
|
|
17158
|
-
statements: splitTopLevelStatements(stripped.text, at),
|
|
17159
|
-
children,
|
|
17160
|
-
};
|
|
17161
|
-
}
|
|
17162
|
-
|
|
17163
|
-
if (s.startsWith('%not[', i)) {
|
|
17164
|
-
segments.push(current);
|
|
17165
|
-
current = '';
|
|
17166
|
-
const child = readSurfaceAt(s, i);
|
|
17167
|
-
children.push(child);
|
|
17168
|
-
i = child.end;
|
|
17169
|
-
continue;
|
|
17170
|
-
}
|
|
17171
|
-
|
|
17172
|
-
const ch = s[i];
|
|
17173
|
-
if (ch === '"' || ch === "'") {
|
|
17174
|
-
const str = readStringAt(s, i);
|
|
17175
|
-
current += str.text;
|
|
17176
|
-
i = str.end;
|
|
17177
|
-
continue;
|
|
17178
|
-
}
|
|
17179
|
-
if (ch === '<') {
|
|
17180
|
-
const iri = readIriAt(s, i);
|
|
17181
|
-
current += iri.text;
|
|
17182
|
-
i = iri.end;
|
|
17183
|
-
continue;
|
|
17184
|
-
}
|
|
17185
|
-
if (ch === '#') {
|
|
17186
|
-
while (i < s.length) {
|
|
17187
|
-
const c = s[i++];
|
|
17188
|
-
current += c;
|
|
17189
|
-
if (c === '\n' || c === '\r') break;
|
|
17190
|
-
}
|
|
17191
|
-
continue;
|
|
17192
|
-
}
|
|
17193
|
-
|
|
17194
|
-
current += ch;
|
|
17195
|
-
i += 1;
|
|
17196
|
-
}
|
|
17197
|
-
|
|
17198
|
-
throw syntaxError('Unterminated RDF Surface, expected %]', at);
|
|
17199
|
-
}
|
|
17200
|
-
|
|
17201
|
-
const LOG_FOR_ALL_IN_IRI = '<http://www.w3.org/2000/10/swap/log#forAllIn>';
|
|
17202
|
-
const LOG_NAME_OF_IRI = '<http://www.w3.org/2000/10/swap/log#nameOf>';
|
|
17203
|
-
|
|
17204
|
-
function rewriteBlankMarksWithMap(statement, labelToVarName) {
|
|
17205
|
-
const map = labelToVarName instanceof Map ? labelToVarName : new Map();
|
|
17206
|
-
let out = '';
|
|
17207
|
-
let i = 0;
|
|
17208
|
-
while (i < statement.length) {
|
|
17209
|
-
const ch = statement[i];
|
|
17210
|
-
if (ch === '"' || ch === "'") {
|
|
17211
|
-
const str = readStringAt(statement, i);
|
|
17212
|
-
out += str.text;
|
|
17213
|
-
i = str.end;
|
|
17214
|
-
continue;
|
|
17215
|
-
}
|
|
17216
|
-
if (ch === '<') {
|
|
17217
|
-
const iri = readIriAt(statement, i);
|
|
17218
|
-
out += iri.text;
|
|
17219
|
-
i = iri.end;
|
|
17220
|
-
continue;
|
|
17221
|
-
}
|
|
17222
|
-
if (ch === '#') {
|
|
17223
|
-
while (i < statement.length) {
|
|
17224
|
-
const c = statement[i++];
|
|
17225
|
-
out += c;
|
|
17226
|
-
if (c === '\n' || c === '\r') break;
|
|
17227
|
-
}
|
|
17228
|
-
continue;
|
|
17229
|
-
}
|
|
17230
|
-
if (statement.startsWith('_:', i)) {
|
|
17231
|
-
let j = i + 2;
|
|
17232
|
-
while (j < statement.length && !isWs(statement[j]) && !'{}[](),;.'.includes(statement[j])) j += 1;
|
|
17233
|
-
const label = statement.slice(i + 2, j);
|
|
17234
|
-
const mapped = label ? map.get(label) : null;
|
|
17235
|
-
if (mapped) {
|
|
17236
|
-
out += `?${mapped}`;
|
|
17237
|
-
i = j;
|
|
17238
|
-
continue;
|
|
17239
|
-
}
|
|
17240
|
-
}
|
|
17241
|
-
out += ch;
|
|
17242
|
-
i += 1;
|
|
17243
|
-
}
|
|
17244
|
-
return out.trim();
|
|
17245
|
-
}
|
|
17246
|
-
|
|
17247
|
-
function formatGraphWithMap(statements, labelMap) {
|
|
17248
|
-
const body = (statements || [])
|
|
17249
|
-
.map((st) => rewriteBlankMarksWithMap(st, labelMap))
|
|
17250
|
-
.filter(Boolean)
|
|
17251
|
-
.map((st) => ` ${st} .`)
|
|
17252
|
-
.join('\n');
|
|
17253
|
-
return body ? `{
|
|
17254
|
-
${body}\n}` : '{ }';
|
|
17255
|
-
}
|
|
17256
|
-
|
|
17257
|
-
function formatGraphFromRewritten(statements) {
|
|
17258
|
-
const body = (statements || [])
|
|
17259
|
-
.map((st) => String(st || '').trim())
|
|
17260
|
-
.filter(Boolean)
|
|
17261
|
-
.map((st) => ` ${st} .`)
|
|
17262
|
-
.join('\n');
|
|
17263
|
-
return body ? `{
|
|
17264
|
-
${body}\n}` : '{ }';
|
|
17265
|
-
}
|
|
17266
|
-
|
|
17267
|
-
function makeVarMap(labels, prefix = '') {
|
|
17268
|
-
const map = new Map();
|
|
17269
|
-
for (const label of labels || []) map.set(label, `${prefix}${label}`);
|
|
17270
|
-
return map;
|
|
17271
|
-
}
|
|
17272
|
-
|
|
17273
|
-
function mergeVarMaps(...maps) {
|
|
17274
|
-
const out = new Map();
|
|
17275
|
-
for (const m of maps) {
|
|
17276
|
-
for (const [k, v] of m.entries()) out.set(k, v);
|
|
17277
|
-
}
|
|
17278
|
-
return out;
|
|
17279
|
-
}
|
|
17280
|
-
|
|
17281
|
-
function slide33ReverseAllValuesFromRule(node, inheritedMap = new Map(), extraPremises = []) {
|
|
17282
|
-
const outerBinders = node.binders || [];
|
|
17283
|
-
const own = node.statements || [];
|
|
17284
|
-
const children = node.children || [];
|
|
17285
|
-
|
|
17286
|
-
if (own.length !== 0 || outerBinders.length === 0 || children.length !== 2) return null;
|
|
17287
|
-
|
|
17288
|
-
let bodyChild = null;
|
|
17289
|
-
let headChild = null;
|
|
17290
|
-
for (const child of children) {
|
|
17291
|
-
const childChildren = child && child.children ? child.children : [];
|
|
17292
|
-
if (childChildren.length === 1) bodyChild = child;
|
|
17293
|
-
else if (childChildren.length === 0) headChild = child;
|
|
17294
|
-
else return null;
|
|
17295
|
-
}
|
|
17296
|
-
|
|
17297
|
-
if (!bodyChild || !headChild) return null;
|
|
17298
|
-
if (!bodyChild.statements || bodyChild.statements.length === 0) return null;
|
|
17299
|
-
if (!headChild.statements || headChild.statements.length === 0) return null;
|
|
17300
|
-
|
|
17301
|
-
const thenChild = bodyChild.children[0];
|
|
17302
|
-
if (!thenChild || (thenChild.children && thenChild.children.length)) return null;
|
|
17303
|
-
if (!thenChild.statements || thenChild.statements.length === 0) return null;
|
|
17304
|
-
|
|
17305
|
-
const outerMap = mergeVarMaps(inheritedMap, makeVarMap(outerBinders));
|
|
17306
|
-
const witnessMap = makeVarMap(bodyChild.binders || [], '__rs_witness_');
|
|
17307
|
-
const localMap = makeVarMap(bodyChild.binders || [], '__rs_');
|
|
17308
|
-
|
|
17309
|
-
const mappedExtra = (extraPremises || [])
|
|
17310
|
-
.map((st) => rewriteBlankMarksWithMap(st, outerMap))
|
|
17311
|
-
.filter(Boolean);
|
|
17312
|
-
const premiseStmts = bodyChild.statements
|
|
17313
|
-
.map((st) => rewriteBlankMarksWithMap(st, mergeVarMaps(outerMap, witnessMap)))
|
|
17314
|
-
.filter(Boolean);
|
|
17315
|
-
|
|
17316
|
-
const whereGraph = formatGraphWithMap(bodyChild.statements, mergeVarMaps(outerMap, localMap));
|
|
17317
|
-
const thenGraph = formatGraphWithMap(thenChild.statements, mergeVarMaps(outerMap, localMap));
|
|
17318
|
-
const forAllLine = `( ${whereGraph} ${thenGraph} ) ${LOG_FOR_ALL_IN_IRI} 1`;
|
|
17319
|
-
|
|
17320
|
-
const premise = formatGraphFromRewritten([...mappedExtra, ...premiseStmts, forAllLine]);
|
|
17321
|
-
const conclusion = formatGraphWithMap(headChild.statements, outerMap);
|
|
17322
|
-
return `${premise} => ${conclusion} .`;
|
|
17323
|
-
}
|
|
17324
|
-
|
|
17325
|
-
|
|
17326
|
-
function translateHeadSurface(node, extraPremises, inheritedMap = new Map()) {
|
|
17327
|
-
const rules = [];
|
|
17328
|
-
const map = inheritedMap instanceof Map ? inheritedMap : new Map();
|
|
17329
|
-
const own = node.statements || [];
|
|
17330
|
-
if (own.length) {
|
|
17331
|
-
rules.push(`${formatGraphWithMap(extraPremises, map)} => ${formatGraphWithMap(own, map)} .`);
|
|
17332
|
-
}
|
|
17333
|
-
for (const child of node.children || []) {
|
|
17334
|
-
rules.push(...translateRuleSurface(child, extraPremises, map));
|
|
17335
|
-
}
|
|
17336
|
-
return rules;
|
|
17337
|
-
}
|
|
17338
|
-
|
|
17339
|
-
function translateRuleSurface(node, extraPremises = [], inheritedMap = new Map()) {
|
|
17340
|
-
const slide33Reverse = slide33ReverseAllValuesFromRule(node, inheritedMap, extraPremises);
|
|
17341
|
-
if (slide33Reverse) return [slide33Reverse];
|
|
17342
|
-
|
|
17343
|
-
const map = mergeVarMaps(inheritedMap, makeVarMap(node.binders || []));
|
|
17344
|
-
const own = node.statements || [];
|
|
17345
|
-
const premise = [...(extraPremises || []), ...own];
|
|
17346
|
-
const children = node.children || [];
|
|
17347
|
-
|
|
17348
|
-
if (children.length === 0) {
|
|
17349
|
-
return own.length ? [`${formatGraphWithMap(premise, map)} => false .`] : [];
|
|
17350
|
-
}
|
|
17351
|
-
|
|
17352
|
-
return children.flatMap((child) => translateHeadSurface(child, premise, map));
|
|
17353
|
-
}
|
|
17354
|
-
|
|
17355
|
-
function translateTopLevelSurface(node) {
|
|
17356
|
-
const map = makeVarMap(node.binders || []);
|
|
17357
|
-
const own = node.statements || [];
|
|
17358
|
-
|
|
17359
|
-
if (!node.children || node.children.length === 0) {
|
|
17360
|
-
return own.length ? [`${formatGraphWithMap(own, map)} => false .`] : [];
|
|
17361
|
-
}
|
|
17362
|
-
|
|
17363
|
-
const slide33Reverse = slide33ReverseAllValuesFromRule(node);
|
|
17364
|
-
if (slide33Reverse) return [slide33Reverse];
|
|
17365
|
-
|
|
17366
|
-
return node.children.flatMap((child) => translateHeadSurface(child, own, map));
|
|
17367
|
-
}
|
|
17368
|
-
|
|
17369
|
-
function normalizeRdfSurfaces(inputText) {
|
|
17370
|
-
const s = String(inputText ?? '');
|
|
17371
|
-
if (!s.includes('%not[')) return s;
|
|
17372
|
-
|
|
17373
|
-
let out = '';
|
|
17374
|
-
const generated = [];
|
|
17375
|
-
let i = 0;
|
|
17376
|
-
let braceDepth = 0;
|
|
17377
|
-
let bracketDepth = 0;
|
|
17378
|
-
let parenDepth = 0;
|
|
17379
|
-
|
|
17380
|
-
while (i < s.length) {
|
|
17381
|
-
if (s.startsWith('%not[', i) && braceDepth === 0 && bracketDepth === 0 && parenDepth === 0) {
|
|
17382
|
-
const surface = readSurfaceAt(s, i);
|
|
17383
|
-
generated.push(...translateTopLevelSurface(surface));
|
|
17384
|
-
i = surface.end;
|
|
17385
|
-
continue;
|
|
17386
|
-
}
|
|
17387
|
-
|
|
17388
|
-
const ch = s[i];
|
|
17389
|
-
if (ch === '"' || ch === "'") {
|
|
17390
|
-
const str = readStringAt(s, i);
|
|
17391
|
-
out += str.text;
|
|
17392
|
-
i = str.end;
|
|
17393
|
-
continue;
|
|
17394
|
-
}
|
|
17395
|
-
if (ch === '<') {
|
|
17396
|
-
const iri = readIriAt(s, i);
|
|
17397
|
-
out += iri.text;
|
|
17398
|
-
i = iri.end;
|
|
17399
|
-
continue;
|
|
17400
|
-
}
|
|
17401
|
-
if (ch === '#') {
|
|
17402
|
-
while (i < s.length) {
|
|
17403
|
-
const c = s[i++];
|
|
17404
|
-
out += c;
|
|
17405
|
-
if (c === '\n' || c === '\r') break;
|
|
17406
|
-
}
|
|
17407
|
-
continue;
|
|
17408
|
-
}
|
|
17409
|
-
|
|
17410
|
-
if (ch === '{') braceDepth += 1;
|
|
17411
|
-
else if (ch === '}' && braceDepth > 0) braceDepth -= 1;
|
|
17412
|
-
else if (ch === '[') bracketDepth += 1;
|
|
17413
|
-
else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1;
|
|
17414
|
-
else if (ch === '(') parenDepth += 1;
|
|
17415
|
-
else if (ch === ')' && parenDepth > 0) parenDepth -= 1;
|
|
17416
|
-
|
|
17417
|
-
out += ch;
|
|
17418
|
-
i += 1;
|
|
17419
|
-
}
|
|
17420
|
-
|
|
17421
|
-
if (generated.length === 0) return out;
|
|
17422
|
-
const sep = out.trim() ? (out.endsWith('\n') ? '\n' : '\n\n') : '';
|
|
17423
|
-
return out + sep + generated.join('\n\n') + '\n';
|
|
17424
|
-
}
|
|
17425
|
-
|
|
17426
|
-
module.exports = {
|
|
17427
|
-
normalizeRdfSurfaces,
|
|
17428
|
-
};
|
|
17429
|
-
|
|
17430
16808
|
};
|
|
17431
16809
|
__modules["lib/rdfjs.js"] = function(require, module, exports){
|
|
17432
16810
|
/**
|
|
@@ -17531,7 +16909,8 @@ function termEquals(self, other) {
|
|
|
17531
16909
|
!!self.datatype &&
|
|
17532
16910
|
typeof self.datatype.equals === 'function' &&
|
|
17533
16911
|
self.datatype.equals(other.datatype) &&
|
|
17534
|
-
self.language === (other.language || '')
|
|
16912
|
+
self.language === (other.language || '') &&
|
|
16913
|
+
(self.direction || '') === (other.direction || '')
|
|
17535
16914
|
);
|
|
17536
16915
|
}
|
|
17537
16916
|
|
|
@@ -17596,6 +16975,7 @@ class Literal {
|
|
|
17596
16975
|
this.termType = 'Literal';
|
|
17597
16976
|
this.value = String(value);
|
|
17598
16977
|
this.language = '';
|
|
16978
|
+
this.direction = '';
|
|
17599
16979
|
this.datatype = null;
|
|
17600
16980
|
|
|
17601
16981
|
if (typeof languageOrDatatype === 'string') {
|
|
@@ -17603,6 +16983,10 @@ class Literal {
|
|
|
17603
16983
|
this.datatype = new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString');
|
|
17604
16984
|
} else if (isRdfJsTerm(languageOrDatatype)) {
|
|
17605
16985
|
this.datatype = languageOrDatatype;
|
|
16986
|
+
} else if (languageOrDatatype && typeof languageOrDatatype === 'object') {
|
|
16987
|
+
this.language = String(languageOrDatatype.language || '');
|
|
16988
|
+
this.direction = languageOrDatatype.direction || '';
|
|
16989
|
+
this.datatype = new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString');
|
|
17606
16990
|
} else {
|
|
17607
16991
|
this.datatype = new NamedNode(XSD_NS + 'string');
|
|
17608
16992
|
}
|
|
@@ -17649,6 +17033,38 @@ const dataFactory = {
|
|
|
17649
17033
|
quad(subject, predicate, object, graph) {
|
|
17650
17034
|
return new Quad(subject, predicate, object, graph || defaultGraphSingleton);
|
|
17651
17035
|
},
|
|
17036
|
+
fromTerm(original) {
|
|
17037
|
+
if (!isRdfJsTerm(original)) throw new TypeError('Expected an RDF/JS term');
|
|
17038
|
+
|
|
17039
|
+
switch (original.termType) {
|
|
17040
|
+
case 'NamedNode':
|
|
17041
|
+
return new NamedNode(original.value);
|
|
17042
|
+
case 'BlankNode':
|
|
17043
|
+
return new BlankNode(original.value);
|
|
17044
|
+
case 'Literal':
|
|
17045
|
+
if (original.language || original.direction) {
|
|
17046
|
+
return new Literal(original.value, { language: original.language || '', direction: original.direction || '' });
|
|
17047
|
+
}
|
|
17048
|
+
return new Literal(original.value, original.datatype ? dataFactory.fromTerm(original.datatype) : undefined);
|
|
17049
|
+
case 'Variable':
|
|
17050
|
+
return new Variable(original.value);
|
|
17051
|
+
case 'DefaultGraph':
|
|
17052
|
+
return defaultGraphSingleton;
|
|
17053
|
+
case 'Quad':
|
|
17054
|
+
return dataFactory.fromQuad(original);
|
|
17055
|
+
default:
|
|
17056
|
+
throw new TypeError(`Unsupported RDF/JS termType ${JSON.stringify(original.termType)}`);
|
|
17057
|
+
}
|
|
17058
|
+
},
|
|
17059
|
+
fromQuad(original) {
|
|
17060
|
+
if (!isRdfJsQuad(original)) throw new TypeError('Expected an RDF/JS Quad');
|
|
17061
|
+
return new Quad(
|
|
17062
|
+
dataFactory.fromTerm(original.subject),
|
|
17063
|
+
dataFactory.fromTerm(original.predicate),
|
|
17064
|
+
dataFactory.fromTerm(original.object),
|
|
17065
|
+
dataFactory.fromTerm(original.graph),
|
|
17066
|
+
);
|
|
17067
|
+
},
|
|
17652
17068
|
};
|
|
17653
17069
|
|
|
17654
17070
|
function getDataFactory(factory) {
|