eyeling 1.30.5 → 1.31.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.
Files changed (60) hide show
  1. package/README.md +0 -157
  2. package/dist/browser/eyeling.browser.js +13 -561
  3. package/eyeling.js +13 -561
  4. package/index.d.ts +0 -4
  5. package/index.js +1 -2
  6. package/lib/cli.js +4 -11
  7. package/lib/engine.js +6 -14
  8. package/lib/lexer.js +0 -4
  9. package/lib/multisource.js +3 -5
  10. package/package.json +3 -6
  11. package/test/examples.test.js +5 -37
  12. package/test/playground.test.js +1 -1
  13. package/test/run.js +60 -0
  14. package/examples/input/rdf-surfaces-all-values-from-reverse.ttl +0 -17
  15. package/examples/input/rdf-surfaces-all-values-from.ttl +0 -13
  16. package/examples/input/rdf-surfaces-ancestor.ttl +0 -20
  17. package/examples/input/rdf-surfaces-city.ttl +0 -11
  18. package/examples/input/rdf-surfaces-disjunction-elimination.ttl +0 -16
  19. package/examples/input/rdf-surfaces-disjunction-route-filter.ttl +0 -11
  20. package/examples/input/rdf-surfaces-domain.ttl +0 -11
  21. package/examples/input/rdf-surfaces-explicit-disjunction.ttl +0 -22
  22. package/examples/input/rdf-surfaces-multi-premise.ttl +0 -13
  23. package/examples/input/rdf-surfaces-owl-all-values-from-codex.ttl +0 -35
  24. package/examples/input/rdf-surfaces-property-chain.ttl +0 -13
  25. package/examples/input/rdf-surfaces-range.ttl +0 -11
  26. package/examples/input/rdf-surfaces-rdfs-range-codex.ttl +0 -18
  27. package/examples/input/rdf-surfaces-rdfs-subclass-codex.ttl +0 -18
  28. package/examples/input/rdf-surfaces-strong-negation-access.ttl +0 -14
  29. package/examples/output/rdf-surfaces-all-values-from-reverse.n3 +0 -3
  30. package/examples/output/rdf-surfaces-all-values-from.n3 +0 -3
  31. package/examples/output/rdf-surfaces-ancestor.n3 +0 -5
  32. package/examples/output/rdf-surfaces-city.n3 +0 -3
  33. package/examples/output/rdf-surfaces-disjunction-elimination.n3 +0 -3
  34. package/examples/output/rdf-surfaces-disjunction-route-filter.n3 +0 -3
  35. package/examples/output/rdf-surfaces-domain.n3 +0 -3
  36. package/examples/output/rdf-surfaces-explicit-disjunction.n3 +0 -3
  37. package/examples/output/rdf-surfaces-multi-premise.n3 +0 -3
  38. package/examples/output/rdf-surfaces-owl-all-values-from-codex.n3 +0 -6
  39. package/examples/output/rdf-surfaces-property-chain.n3 +0 -3
  40. package/examples/output/rdf-surfaces-range.n3 +0 -3
  41. package/examples/output/rdf-surfaces-rdfs-range-codex.n3 +0 -3
  42. package/examples/output/rdf-surfaces-rdfs-subclass-codex.n3 +0 -3
  43. package/examples/output/rdf-surfaces-strong-negation-access.n3 +0 -4
  44. package/examples/rdf-surfaces-all-values-from-reverse.n3 +0 -6
  45. package/examples/rdf-surfaces-all-values-from.n3 +0 -6
  46. package/examples/rdf-surfaces-ancestor.n3 +0 -6
  47. package/examples/rdf-surfaces-city.n3 +0 -6
  48. package/examples/rdf-surfaces-disjunction-elimination.n3 +0 -13
  49. package/examples/rdf-surfaces-disjunction-route-filter.n3 +0 -24
  50. package/examples/rdf-surfaces-domain.n3 +0 -6
  51. package/examples/rdf-surfaces-explicit-disjunction.n3 +0 -16
  52. package/examples/rdf-surfaces-multi-premise.n3 +0 -6
  53. package/examples/rdf-surfaces-owl-all-values-from-codex.n3 +0 -10
  54. package/examples/rdf-surfaces-property-chain.n3 +0 -6
  55. package/examples/rdf-surfaces-range.n3 +0 -6
  56. package/examples/rdf-surfaces-rdfs-range-codex.n3 +0 -6
  57. package/examples/rdf-surfaces-rdfs-subclass-codex.n3 +0 -6
  58. package/examples/rdf-surfaces-strong-negation-access.n3 +0 -20
  59. package/lib/rdf_surfaces.js +0 -524
  60. package/test/rdf_surfaces.test.js +0 -214
package/eyeling.js CHANGED
@@ -6090,7 +6090,7 @@ async function ingestLineBasedRdfSourceToStore(sourceLabel, store, { rdfMode = t
6090
6090
  }
6091
6091
 
6092
6092
 
6093
- async function runStreamMessagesMode(sourceLabels, { rdfMode, rdfSurfacesMode = false, storeName = null, storePath = null, storeClear = false } = {}) {
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 rdfSurfacesMode = argv.includes('--rdf-surfaces');
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, rdfSurfacesMode, storeName, storePath, storeClear });
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, rdfSurfaces: rdfSurfacesMode });
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 || !!rdfSurfaces;
10828
- const useRdfSurfaces = !!rdfSurfaces;
10819
+ const useRdfCompatibility = !!rdf;
10829
10820
 
10830
- const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: useRdfCompatibility, rdfSurfaces: useRdfSurfaces, sourceLocations: proof });
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 || !!rdfSurfaces, rdfSurfaces: !!rdfSurfaces, sourceLocations: !!proof });
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 || !!rdfSurfaces,
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 || !!opts.rdfSurfaces,
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 || !!runOpts.rdfSurfaces,
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;
@@ -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 && !rdfSurfaces) {
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, rdfSurfaces });
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 || !!opts.rdfSurfaces,
14799
- rdfSurfaces: !!opts.rdfSurfaces,
14778
+ rdf: !!opts.rdf,
14800
14779
  }),
14801
14780
  );
14802
14781
  return mergeParsedDocuments(parsed, {
@@ -16826,533 +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
- const segment = readStatementSegment(text.slice(contentStart));
16992
- const toks = tokenizeLeadingSegment(segment);
16993
- let leadingBlankCount = 0;
16994
- while (leadingBlankCount < toks.length && /^_:[A-Za-z_][A-Za-z0-9._-]*$/.test(toks[leadingBlankCount].text)) {
16995
- leadingBlankCount += 1;
16996
- }
16997
-
16998
- if (leadingBlankCount === 0) return { binders: [], text };
16999
-
17000
- let binderCount = 0;
17001
- if (toks.length >= 3) {
17002
- // Prefer the longest explicit binder prefix that still leaves at least a
17003
- // subject, predicate, and object for the first statement. This matches the
17004
- // BLOGIC slide convention, e.g. `%not[ _:x _:x a :C . ... %]`.
17005
- binderCount = Math.min(leadingBlankCount, Math.max(0, toks.length - 3));
17006
- } else {
17007
- // No own triple before a nested surface: treat the leading marks as binders.
17008
- binderCount = leadingBlankCount;
17009
- }
17010
-
17011
- if (binderCount <= 0) return { binders: [], text };
17012
-
17013
- const binders = toks.slice(0, binderCount).map((t) => t.text.slice(2));
17014
- const cut = toks[binderCount - 1].end;
17015
- return { binders, text: text.slice(0, contentStart) + text.slice(contentStart + cut) };
17016
- }
17017
-
17018
- function splitTopLevelStatements(raw, surfaceOffset = null) {
17019
- const text = String(raw || '');
17020
- const out = [];
17021
- let start = 0;
17022
- let i = 0;
17023
- let depthBrace = 0;
17024
- let depthBracket = 0;
17025
- let depthParen = 0;
17026
-
17027
- while (i < text.length) {
17028
- const ch = text[i];
17029
- if (ch === '"' || ch === "'") {
17030
- i = readStringAt(text, i).end;
17031
- continue;
17032
- }
17033
- if (ch === '<') {
17034
- i = readIriAt(text, i).end;
17035
- continue;
17036
- }
17037
- if (ch === '#') {
17038
- while (i < text.length && text[i] !== '\n' && text[i] !== '\r') i += 1;
17039
- continue;
17040
- }
17041
- if (ch === '{') depthBrace += 1;
17042
- else if (ch === '}' && depthBrace > 0) depthBrace -= 1;
17043
- else if (ch === '[') depthBracket += 1;
17044
- else if (ch === ']' && depthBracket > 0) depthBracket -= 1;
17045
- else if (ch === '(') depthParen += 1;
17046
- else if (ch === ')' && depthParen > 0) depthParen -= 1;
17047
- else if (ch === '.' && depthBrace === 0 && depthBracket === 0 && depthParen === 0) {
17048
- const stmt = text.slice(start, i).trim();
17049
- if (stmt) out.push(stmt);
17050
- start = i + 1;
17051
- }
17052
- i += 1;
17053
- }
17054
-
17055
- const tail = text.slice(start).trim();
17056
- if (tail) {
17057
- // A raw binder-only segment is OK; any other dangling text is most likely a
17058
- // missing dot in the surface body.
17059
- if (!/^_:[A-Za-z_][A-Za-z0-9._-]*(?:\s+_:[A-Za-z_][A-Za-z0-9._-]*)*$/.test(tail)) {
17060
- throw syntaxError('RDF Surface statement is missing a terminating dot', surfaceOffset);
17061
- }
17062
- }
17063
-
17064
- return out;
17065
- }
17066
-
17067
- function readSurfaceAt(s, at) {
17068
- if (!s.startsWith('%not[', at)) return null;
17069
- let i = at + '%not['.length;
17070
- let current = '';
17071
- const segments = [];
17072
- const children = [];
17073
-
17074
- while (i < s.length) {
17075
- if (s.startsWith('%]', i)) {
17076
- segments.push(current);
17077
- i += 2;
17078
- const raw = segments.join('\n');
17079
- const stripped = extractLeadingBinders(raw);
17080
- return {
17081
- type: 'not',
17082
- start: at,
17083
- end: i,
17084
- binders: stripped.binders,
17085
- statements: splitTopLevelStatements(stripped.text, at),
17086
- children,
17087
- };
17088
- }
17089
-
17090
- if (s.startsWith('%not[', i)) {
17091
- segments.push(current);
17092
- current = '';
17093
- const child = readSurfaceAt(s, i);
17094
- children.push(child);
17095
- i = child.end;
17096
- continue;
17097
- }
17098
-
17099
- const ch = s[i];
17100
- if (ch === '"' || ch === "'") {
17101
- const str = readStringAt(s, i);
17102
- current += str.text;
17103
- i = str.end;
17104
- continue;
17105
- }
17106
- if (ch === '<') {
17107
- const iri = readIriAt(s, i);
17108
- current += iri.text;
17109
- i = iri.end;
17110
- continue;
17111
- }
17112
- if (ch === '#') {
17113
- while (i < s.length) {
17114
- const c = s[i++];
17115
- current += c;
17116
- if (c === '\n' || c === '\r') break;
17117
- }
17118
- continue;
17119
- }
17120
-
17121
- current += ch;
17122
- i += 1;
17123
- }
17124
-
17125
- throw syntaxError('Unterminated RDF Surface, expected %]', at);
17126
- }
17127
-
17128
- const LOG_FOR_ALL_IN_IRI = '<http://www.w3.org/2000/10/swap/log#forAllIn>';
17129
-
17130
- function rewriteBlankMarksWithMap(statement, labelToVarName) {
17131
- const map = labelToVarName instanceof Map ? labelToVarName : new Map();
17132
- let out = '';
17133
- let i = 0;
17134
- while (i < statement.length) {
17135
- const ch = statement[i];
17136
- if (ch === '"' || ch === "'") {
17137
- const str = readStringAt(statement, i);
17138
- out += str.text;
17139
- i = str.end;
17140
- continue;
17141
- }
17142
- if (ch === '<') {
17143
- const iri = readIriAt(statement, i);
17144
- out += iri.text;
17145
- i = iri.end;
17146
- continue;
17147
- }
17148
- if (ch === '#') {
17149
- while (i < statement.length) {
17150
- const c = statement[i++];
17151
- out += c;
17152
- if (c === '\n' || c === '\r') break;
17153
- }
17154
- continue;
17155
- }
17156
- if (statement.startsWith('_:', i)) {
17157
- let j = i + 2;
17158
- while (j < statement.length && !isWs(statement[j]) && !'{}[](),;.'.includes(statement[j])) j += 1;
17159
- const label = statement.slice(i + 2, j);
17160
- const mapped = label ? map.get(label) : null;
17161
- if (mapped) {
17162
- out += `?${mapped}`;
17163
- i = j;
17164
- continue;
17165
- }
17166
- }
17167
- out += ch;
17168
- i += 1;
17169
- }
17170
- return out.trim();
17171
- }
17172
-
17173
- function formatGraphWithMap(statements, labelMap) {
17174
- const body = (statements || [])
17175
- .map((st) => rewriteBlankMarksWithMap(st, labelMap))
17176
- .filter(Boolean)
17177
- .map((st) => ` ${st} .`)
17178
- .join('\n');
17179
- return body ? `{
17180
- ${body}\n}` : '{ }';
17181
- }
17182
-
17183
- function formatGraphFromRewritten(statements) {
17184
- const body = (statements || [])
17185
- .map((st) => String(st || '').trim())
17186
- .filter(Boolean)
17187
- .map((st) => ` ${st} .`)
17188
- .join('\n');
17189
- return body ? `{
17190
- ${body}\n}` : '{ }';
17191
- }
17192
-
17193
- function makeVarMap(labels, prefix = '') {
17194
- const map = new Map();
17195
- for (const label of labels || []) map.set(label, `${prefix}${label}`);
17196
- return map;
17197
- }
17198
-
17199
- function mergeVarMaps(...maps) {
17200
- const out = new Map();
17201
- for (const m of maps) {
17202
- for (const [k, v] of m.entries()) out.set(k, v);
17203
- }
17204
- return out;
17205
- }
17206
-
17207
- function slide33ReverseAllValuesFromRule(node, inheritedMap = new Map(), extraPremises = []) {
17208
- const outerBinders = node.binders || [];
17209
- const own = node.statements || [];
17210
- const children = node.children || [];
17211
-
17212
- if (own.length !== 0 || outerBinders.length === 0 || children.length !== 2) return null;
17213
-
17214
- let bodyChild = null;
17215
- let headChild = null;
17216
- for (const child of children) {
17217
- const childChildren = child && child.children ? child.children : [];
17218
- if (childChildren.length === 1) bodyChild = child;
17219
- else if (childChildren.length === 0) headChild = child;
17220
- else return null;
17221
- }
17222
-
17223
- if (!bodyChild || !headChild) return null;
17224
- if (!bodyChild.statements || bodyChild.statements.length === 0) return null;
17225
- if (!headChild.statements || headChild.statements.length === 0) return null;
17226
-
17227
- const thenChild = bodyChild.children[0];
17228
- if (!thenChild || (thenChild.children && thenChild.children.length)) return null;
17229
- if (!thenChild.statements || thenChild.statements.length === 0) return null;
17230
-
17231
- const outerMap = mergeVarMaps(inheritedMap, makeVarMap(outerBinders));
17232
- const witnessMap = makeVarMap(bodyChild.binders || [], '__rs_witness_');
17233
- const localMap = makeVarMap(bodyChild.binders || [], '__rs_');
17234
-
17235
- const mappedExtra = (extraPremises || [])
17236
- .map((st) => rewriteBlankMarksWithMap(st, outerMap))
17237
- .filter(Boolean);
17238
- const premiseStmts = bodyChild.statements
17239
- .map((st) => rewriteBlankMarksWithMap(st, mergeVarMaps(outerMap, witnessMap)))
17240
- .filter(Boolean);
17241
-
17242
- const whereGraph = formatGraphWithMap(bodyChild.statements, mergeVarMaps(outerMap, localMap));
17243
- const thenGraph = formatGraphWithMap(thenChild.statements, mergeVarMaps(outerMap, localMap));
17244
- const forAllLine = `( ${whereGraph} ${thenGraph} ) ${LOG_FOR_ALL_IN_IRI} 1`;
17245
-
17246
- const premise = formatGraphFromRewritten([...mappedExtra, ...premiseStmts, forAllLine]);
17247
- const conclusion = formatGraphWithMap(headChild.statements, outerMap);
17248
- return `${premise} => ${conclusion} .`;
17249
- }
17250
-
17251
-
17252
- function translateHeadSurface(node, extraPremises, inheritedMap = new Map()) {
17253
- const rules = [];
17254
- const map = inheritedMap instanceof Map ? inheritedMap : new Map();
17255
- const own = node.statements || [];
17256
- if (own.length) {
17257
- rules.push(`${formatGraphWithMap(extraPremises, map)} => ${formatGraphWithMap(own, map)} .`);
17258
- }
17259
- for (const child of node.children || []) {
17260
- rules.push(...translateRuleSurface(child, extraPremises, map));
17261
- }
17262
- return rules;
17263
- }
17264
-
17265
- function translateRuleSurface(node, extraPremises = [], inheritedMap = new Map()) {
17266
- const slide33Reverse = slide33ReverseAllValuesFromRule(node, inheritedMap, extraPremises);
17267
- if (slide33Reverse) return [slide33Reverse];
17268
-
17269
- const map = mergeVarMaps(inheritedMap, makeVarMap(node.binders || []));
17270
- const own = node.statements || [];
17271
- const premise = [...(extraPremises || []), ...own];
17272
- const children = node.children || [];
17273
-
17274
- if (children.length === 0) {
17275
- return own.length ? [`${formatGraphWithMap(premise, map)} => false .`] : [];
17276
- }
17277
-
17278
- return children.flatMap((child) => translateHeadSurface(child, premise, map));
17279
- }
17280
-
17281
- function translateTopLevelSurface(node) {
17282
- const map = makeVarMap(node.binders || []);
17283
- const own = node.statements || [];
17284
-
17285
- if (!node.children || node.children.length === 0) {
17286
- return own.length ? [`${formatGraphWithMap(own, map)} => false .`] : [];
17287
- }
17288
-
17289
- const slide33Reverse = slide33ReverseAllValuesFromRule(node);
17290
- if (slide33Reverse) return [slide33Reverse];
17291
-
17292
- return node.children.flatMap((child) => translateHeadSurface(child, own, map));
17293
- }
17294
-
17295
- function normalizeRdfSurfaces(inputText) {
17296
- const s = String(inputText ?? '');
17297
- if (!s.includes('%not[')) return s;
17298
-
17299
- let out = '';
17300
- const generated = [];
17301
- let i = 0;
17302
- let braceDepth = 0;
17303
- let bracketDepth = 0;
17304
- let parenDepth = 0;
17305
-
17306
- while (i < s.length) {
17307
- if (s.startsWith('%not[', i) && braceDepth === 0 && bracketDepth === 0 && parenDepth === 0) {
17308
- const surface = readSurfaceAt(s, i);
17309
- generated.push(...translateTopLevelSurface(surface));
17310
- i = surface.end;
17311
- continue;
17312
- }
17313
-
17314
- const ch = s[i];
17315
- if (ch === '"' || ch === "'") {
17316
- const str = readStringAt(s, i);
17317
- out += str.text;
17318
- i = str.end;
17319
- continue;
17320
- }
17321
- if (ch === '<') {
17322
- const iri = readIriAt(s, i);
17323
- out += iri.text;
17324
- i = iri.end;
17325
- continue;
17326
- }
17327
- if (ch === '#') {
17328
- while (i < s.length) {
17329
- const c = s[i++];
17330
- out += c;
17331
- if (c === '\n' || c === '\r') break;
17332
- }
17333
- continue;
17334
- }
17335
-
17336
- if (ch === '{') braceDepth += 1;
17337
- else if (ch === '}' && braceDepth > 0) braceDepth -= 1;
17338
- else if (ch === '[') bracketDepth += 1;
17339
- else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1;
17340
- else if (ch === '(') parenDepth += 1;
17341
- else if (ch === ')' && parenDepth > 0) parenDepth -= 1;
17342
-
17343
- out += ch;
17344
- i += 1;
17345
- }
17346
-
17347
- if (generated.length === 0) return out;
17348
- const sep = out.trim() ? (out.endsWith('\n') ? '\n' : '\n\n') : '';
17349
- return out + sep + generated.join('\n\n') + '\n';
17350
- }
17351
-
17352
- module.exports = {
17353
- normalizeRdfSurfaces,
17354
- };
17355
-
17356
16808
  };
17357
16809
  __modules["lib/rdfjs.js"] = function(require, module, exports){
17358
16810
  /**