eyeling 1.7.12 → 1.7.13

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 (2) hide show
  1. package/eyeling.js +175 -33
  2. package/package.json +1 -1
package/eyeling.js CHANGED
@@ -117,7 +117,8 @@ function __resolveBrowserUrl(ref) {
117
117
  if (!ref) return ref;
118
118
  // If already absolute, keep as-is.
119
119
  if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(ref)) return ref;
120
- const base = (typeof document !== 'undefined' && document.baseURI) || (typeof location !== 'undefined' && location.href) || '';
120
+ const base =
121
+ (typeof document !== 'undefined' && document.baseURI) || (typeof location !== 'undefined' && location.href) || '';
121
122
  try {
122
123
  return new URL(ref, base).toString();
123
124
  } catch {
@@ -131,7 +132,10 @@ function __fetchHttpTextSyncBrowser(url) {
131
132
  const xhr = new XMLHttpRequest();
132
133
  xhr.open('GET', url, false); // synchronous
133
134
  try {
134
- xhr.setRequestHeader('Accept', 'text/n3, text/turtle, application/n-triples, application/n-quads, text/plain;q=0.1, */*;q=0.01');
135
+ xhr.setRequestHeader(
136
+ 'Accept',
137
+ 'text/n3, text/turtle, application/n-triples, application/n-quads, text/plain;q=0.1, */*;q=0.01',
138
+ );
135
139
  } catch {
136
140
  // Some environments restrict setting headers (ignore).
137
141
  }
@@ -461,7 +465,21 @@ function utcIsoDateTimeStringFromEpochSeconds(sec) {
461
465
  const s2 = d.getUTCSeconds();
462
466
  const ms2 = d.getUTCMilliseconds();
463
467
  const msPart = ms2 ? '.' + String(ms2).padStart(3, '0') : '';
464
- return pad(year, 4) + '-' + pad(month) + '-' + pad(day) + 'T' + pad(hour) + ':' + pad(min) + ':' + pad(s2) + msPart + '+00:00';
468
+ return (
469
+ pad(year, 4) +
470
+ '-' +
471
+ pad(month) +
472
+ '-' +
473
+ pad(day) +
474
+ 'T' +
475
+ pad(hour) +
476
+ ':' +
477
+ pad(min) +
478
+ ':' +
479
+ pad(s2) +
480
+ msPart +
481
+ '+00:00'
482
+ );
465
483
  }
466
484
 
467
485
  function getNowLex() {
@@ -499,7 +517,9 @@ function deterministicSkolemIdFromKey(key) {
499
517
  const hex = [h1, h2, h3, h4].map((h) => h.toString(16).padStart(8, '0')).join(''); // 32 hex chars
500
518
 
501
519
  // Format like a UUID: 8-4-4-4-12
502
- return hex.slice(0, 8) + '-' + hex.slice(8, 12) + '-' + hex.slice(12, 16) + '-' + hex.slice(16, 20) + '-' + hex.slice(20);
520
+ return (
521
+ hex.slice(0, 8) + '-' + hex.slice(8, 12) + '-' + hex.slice(12, 16) + '-' + hex.slice(16, 20) + '-' + hex.slice(20)
522
+ );
503
523
  }
504
524
 
505
525
  let runLocalTimeCache = null;
@@ -1904,7 +1924,12 @@ function liftBlankRuleVars(premise, conclusion) {
1904
1924
  }
1905
1925
  if (t instanceof GraphTerm) {
1906
1926
  const triples = t.triples.map(
1907
- (tr) => new Triple(convertTerm(tr.s, mapping, counter), convertTerm(tr.p, mapping, counter), convertTerm(tr.o, mapping, counter)),
1927
+ (tr) =>
1928
+ new Triple(
1929
+ convertTerm(tr.s, mapping, counter),
1930
+ convertTerm(tr.p, mapping, counter),
1931
+ convertTerm(tr.o, mapping, counter),
1932
+ ),
1908
1933
  );
1909
1934
  return new GraphTerm(triples);
1910
1935
  }
@@ -1912,7 +1937,11 @@ function liftBlankRuleVars(premise, conclusion) {
1912
1937
  }
1913
1938
 
1914
1939
  function convertTriple(tr, mapping, counter) {
1915
- return new Triple(convertTerm(tr.s, mapping, counter), convertTerm(tr.p, mapping, counter), convertTerm(tr.o, mapping, counter));
1940
+ return new Triple(
1941
+ convertTerm(tr.s, mapping, counter),
1942
+ convertTerm(tr.p, mapping, counter),
1943
+ convertTerm(tr.o, mapping, counter),
1944
+ );
1916
1945
  }
1917
1946
 
1918
1947
  const mapping = {};
@@ -1961,7 +1990,9 @@ function skolemizeTermForHeadBlanks(t, headBlankLabels, mapping, skCounter, firi
1961
1990
  }
1962
1991
 
1963
1992
  if (t instanceof ListTerm) {
1964
- return new ListTerm(t.elems.map((e) => skolemizeTermForHeadBlanks(e, headBlankLabels, mapping, skCounter, firingKey, globalMap)));
1993
+ return new ListTerm(
1994
+ t.elems.map((e) => skolemizeTermForHeadBlanks(e, headBlankLabels, mapping, skCounter, firingKey, globalMap)),
1995
+ );
1965
1996
  }
1966
1997
 
1967
1998
  if (t instanceof OpenListTerm) {
@@ -1973,7 +2004,9 @@ function skolemizeTermForHeadBlanks(t, headBlankLabels, mapping, skCounter, firi
1973
2004
 
1974
2005
  if (t instanceof GraphTerm) {
1975
2006
  return new GraphTerm(
1976
- t.triples.map((tr) => skolemizeTripleForHeadBlanks(tr, headBlankLabels, mapping, skCounter, firingKey, globalMap)),
2007
+ t.triples.map((tr) =>
2008
+ skolemizeTripleForHeadBlanks(tr, headBlankLabels, mapping, skCounter, firingKey, globalMap),
2009
+ ),
1977
2010
  );
1978
2011
  }
1979
2012
 
@@ -2182,7 +2215,11 @@ function alphaEqTermInGraph(a, b, vmap, bmap) {
2182
2215
  }
2183
2216
 
2184
2217
  function alphaEqTripleInGraph(a, b, vmap, bmap) {
2185
- return alphaEqTermInGraph(a.s, b.s, vmap, bmap) && alphaEqTermInGraph(a.p, b.p, vmap, bmap) && alphaEqTermInGraph(a.o, b.o, vmap, bmap);
2218
+ return (
2219
+ alphaEqTermInGraph(a.s, b.s, vmap, bmap) &&
2220
+ alphaEqTermInGraph(a.p, b.p, vmap, bmap) &&
2221
+ alphaEqTermInGraph(a.o, b.o, vmap, bmap)
2222
+ );
2186
2223
  }
2187
2224
 
2188
2225
  function alphaEqGraphTriples(xs, ys) {
@@ -2504,7 +2541,12 @@ function isConstraintBuiltin(tr) {
2504
2541
  }
2505
2542
 
2506
2543
  // log: tests that are purely constraints (no new bindings)
2507
- if (v === LOG_NS + 'forAllIn' || v === LOG_NS + 'notEqualTo' || v === LOG_NS + 'notIncludes') {
2544
+ if (
2545
+ v === LOG_NS + 'forAllIn' ||
2546
+ v === LOG_NS + 'notEqualTo' ||
2547
+ v === LOG_NS + 'notIncludes' ||
2548
+ v === LOG_NS + 'outputString'
2549
+ ) {
2508
2550
  return true;
2509
2551
  }
2510
2552
 
@@ -2717,13 +2759,19 @@ function unifyGraphTriples(xs, ys, subst) {
2717
2759
  }
2718
2760
 
2719
2761
  function unifyTerm(a, b, subst) {
2720
- return unifyTermWithOptions(a, b, subst, { boolValueEq: true, intDecimalEq: false });
2762
+ return unifyTermWithOptions(a, b, subst, {
2763
+ boolValueEq: true,
2764
+ intDecimalEq: false,
2765
+ });
2721
2766
  }
2722
2767
 
2723
2768
  function unifyTermListAppend(a, b, subst) {
2724
2769
  // Keep list:append behavior: allow integer<->decimal exact equality,
2725
2770
  // but do NOT add boolean-value equivalence (preserves current semantics).
2726
- return unifyTermWithOptions(a, b, subst, { boolValueEq: false, intDecimalEq: true });
2771
+ return unifyTermWithOptions(a, b, subst, {
2772
+ boolValueEq: false,
2773
+ intDecimalEq: true,
2774
+ });
2727
2775
  }
2728
2776
 
2729
2777
  function unifyTermWithOptions(a, b, subst, opts) {
@@ -3282,7 +3330,8 @@ function isQuotedLexical(lex) {
3282
3330
  // long: """...""" or '''...'''
3283
3331
  if (typeof lex !== 'string') return false;
3284
3332
  const n = lex.length;
3285
- if (n >= 6 && ((lex.startsWith('"""') && lex.endsWith('"""')) || (lex.startsWith("'''") && lex.endsWith("'''")))) return true;
3333
+ if (n >= 6 && ((lex.startsWith('"""') && lex.endsWith('"""')) || (lex.startsWith("'''") && lex.endsWith("'''"))))
3334
+ return true;
3286
3335
  if (n >= 2) {
3287
3336
  const a = lex[0];
3288
3337
  const b = lex[n - 1];
@@ -3562,7 +3611,13 @@ function parseIso8601DurationToSeconds(s) {
3562
3611
  }
3563
3612
 
3564
3613
  const totalDays =
3565
- years * 365.2425 + months * 30.436875 + weeks * 7.0 + days + hours / 24.0 + minutes / (24.0 * 60.0) + seconds / (24.0 * 3600.0);
3614
+ years * 365.2425 +
3615
+ months * 30.436875 +
3616
+ weeks * 7.0 +
3617
+ days +
3618
+ hours / 24.0 +
3619
+ minutes / (24.0 * 60.0) +
3620
+ seconds / (24.0 * 3600.0);
3566
3621
 
3567
3622
  return totalDays * 86400.0;
3568
3623
  }
@@ -5557,7 +5612,11 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
5557
5612
 
5558
5613
  const scopeFacts = g.s.triples.slice();
5559
5614
  ensureFactIndexes(scopeFacts);
5560
- Object.defineProperty(scopeFacts, '__scopedSnapshot', { value: scopeFacts, enumerable: false, writable: true });
5615
+ Object.defineProperty(scopeFacts, '__scopedSnapshot', {
5616
+ value: scopeFacts,
5617
+ enumerable: false,
5618
+ writable: true,
5619
+ });
5561
5620
 
5562
5621
  const visited2 = [];
5563
5622
  // Start from the incoming substitution so bindings flow outward.
@@ -5575,7 +5634,11 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
5575
5634
 
5576
5635
  const scopeFacts = g.s.triples.slice();
5577
5636
  ensureFactIndexes(scopeFacts);
5578
- Object.defineProperty(scopeFacts, '__scopedSnapshot', { value: scopeFacts, enumerable: false, writable: true });
5637
+ Object.defineProperty(scopeFacts, '__scopedSnapshot', {
5638
+ value: scopeFacts,
5639
+ enumerable: false,
5640
+ writable: true,
5641
+ });
5579
5642
 
5580
5643
  const visited2 = [];
5581
5644
  const sols = proveGoals(Array.from(g.o.triples), { ...subst }, scopeFacts, [], depth + 1, visited2, varGen);
@@ -5608,7 +5671,11 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
5608
5671
  if (g.o instanceof GraphTerm) {
5609
5672
  scopeFacts = g.o.triples.slice();
5610
5673
  ensureFactIndexes(scopeFacts);
5611
- Object.defineProperty(scopeFacts, '__scopedSnapshot', { value: scopeFacts, enumerable: false, writable: true });
5674
+ Object.defineProperty(scopeFacts, '__scopedSnapshot', {
5675
+ value: scopeFacts,
5676
+ enumerable: false,
5677
+ writable: true,
5678
+ });
5612
5679
  scopeBackRules = [];
5613
5680
  } else {
5614
5681
  scopeFacts = facts.__scopedSnapshot || null;
@@ -5621,7 +5688,15 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
5621
5688
  }
5622
5689
 
5623
5690
  const visited2 = [];
5624
- const sols = proveGoals(Array.from(clauseTerm.triples), {}, scopeFacts, scopeBackRules, depth + 1, visited2, varGen);
5691
+ const sols = proveGoals(
5692
+ Array.from(clauseTerm.triples),
5693
+ {},
5694
+ scopeFacts,
5695
+ scopeBackRules,
5696
+ depth + 1,
5697
+ visited2,
5698
+ varGen,
5699
+ );
5625
5700
 
5626
5701
  const collected = sols.map((sBody) => applySubstTerm(valueTempl, sBody));
5627
5702
  const collectedList = new ListTerm(collected);
@@ -5642,7 +5717,11 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
5642
5717
  if (g.o instanceof GraphTerm) {
5643
5718
  scopeFacts = g.o.triples.slice();
5644
5719
  ensureFactIndexes(scopeFacts);
5645
- Object.defineProperty(scopeFacts, '__scopedSnapshot', { value: scopeFacts, enumerable: false, writable: true });
5720
+ Object.defineProperty(scopeFacts, '__scopedSnapshot', {
5721
+ value: scopeFacts,
5722
+ enumerable: false,
5723
+ writable: true,
5724
+ });
5646
5725
  scopeBackRules = [];
5647
5726
  } else {
5648
5727
  scopeFacts = facts.__scopedSnapshot || null;
@@ -5650,11 +5729,27 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
5650
5729
  }
5651
5730
 
5652
5731
  const visited1 = [];
5653
- const sols1 = proveGoals(Array.from(whereClause.triples), {}, scopeFacts, scopeBackRules, depth + 1, visited1, varGen);
5732
+ const sols1 = proveGoals(
5733
+ Array.from(whereClause.triples),
5734
+ {},
5735
+ scopeFacts,
5736
+ scopeBackRules,
5737
+ depth + 1,
5738
+ visited1,
5739
+ varGen,
5740
+ );
5654
5741
 
5655
5742
  for (const s1 of sols1) {
5656
5743
  const visited2 = [];
5657
- const sols2 = proveGoals(Array.from(thenClause.triples), s1, scopeFacts, scopeBackRules, depth + 1, visited2, varGen);
5744
+ const sols2 = proveGoals(
5745
+ Array.from(thenClause.triples),
5746
+ s1,
5747
+ scopeFacts,
5748
+ scopeBackRules,
5749
+ depth + 1,
5750
+ visited2,
5751
+ varGen,
5752
+ );
5658
5753
  if (!sols2.length) return [];
5659
5754
  }
5660
5755
  return [{ ...subst }];
@@ -6170,7 +6265,12 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen) {
6170
6265
  results.push(gcCompactForGoals(composed, [], answerVars));
6171
6266
  } else {
6172
6267
  const nextSubst = maybeCompactSubst(composed, restGoals, answerVars, state.depth + 1);
6173
- nextStates.push({ goals: restGoals, subst: nextSubst, depth: state.depth + 1, visited: state.visited });
6268
+ nextStates.push({
6269
+ goals: restGoals,
6270
+ subst: nextSubst,
6271
+ depth: state.depth + 1,
6272
+ visited: state.visited,
6273
+ });
6174
6274
  }
6175
6275
  }
6176
6276
  // Push in reverse so the *first* generated alternative is explored first (LIFO stack).
@@ -6195,7 +6295,12 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen) {
6195
6295
  results.push(gcCompactForGoals(composed, [], answerVars));
6196
6296
  } else {
6197
6297
  const nextSubst = maybeCompactSubst(composed, restGoals, answerVars, state.depth + 1);
6198
- nextStates.push({ goals: restGoals, subst: nextSubst, depth: state.depth + 1, visited: state.visited });
6298
+ nextStates.push({
6299
+ goals: restGoals,
6300
+ subst: nextSubst,
6301
+ depth: state.depth + 1,
6302
+ visited: state.visited,
6303
+ });
6199
6304
  }
6200
6305
  }
6201
6306
  for (let i = nextStates.length - 1; i >= 0; i--) stack.push(nextStates[i]);
@@ -6211,7 +6316,12 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen) {
6211
6316
  results.push(gcCompactForGoals(composed, [], answerVars));
6212
6317
  } else {
6213
6318
  const nextSubst = maybeCompactSubst(composed, restGoals, answerVars, state.depth + 1);
6214
- nextStates.push({ goals: restGoals, subst: nextSubst, depth: state.depth + 1, visited: state.visited });
6319
+ nextStates.push({
6320
+ goals: restGoals,
6321
+ subst: nextSubst,
6322
+ depth: state.depth + 1,
6323
+ visited: state.visited,
6324
+ });
6215
6325
  }
6216
6326
  }
6217
6327
  for (let i = nextStates.length - 1; i >= 0; i--) stack.push(nextStates[i]);
@@ -6236,7 +6346,12 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen) {
6236
6346
  if (composed === null) continue;
6237
6347
  const newGoals = body.concat(restGoals);
6238
6348
  const nextSubst = maybeCompactSubst(composed, newGoals, answerVars, state.depth + 1);
6239
- nextStates.push({ goals: newGoals, subst: nextSubst, depth: state.depth + 1, visited: visitedForRules });
6349
+ nextStates.push({
6350
+ goals: newGoals,
6351
+ subst: nextSubst,
6352
+ depth: state.depth + 1,
6353
+ visited: visitedForRules,
6354
+ });
6240
6355
  }
6241
6356
  for (let i = nextStates.length - 1; i >= 0; i--) stack.push(nextStates[i]);
6242
6357
  }
@@ -6278,7 +6393,12 @@ function forwardChain(facts, forwardRules, backRules, onDerived /* optional */)
6278
6393
 
6279
6394
  function setScopedSnapshot(snap) {
6280
6395
  if (!Object.prototype.hasOwnProperty.call(facts, '__scopedSnapshot')) {
6281
- Object.defineProperty(facts, '__scopedSnapshot', { value: snap, enumerable: false, writable: true, configurable: true });
6396
+ Object.defineProperty(facts, '__scopedSnapshot', {
6397
+ value: snap,
6398
+ enumerable: false,
6399
+ writable: true,
6400
+ configurable: true,
6401
+ });
6282
6402
  } else {
6283
6403
  facts.__scopedSnapshot = snap;
6284
6404
  }
@@ -6287,7 +6407,12 @@ function forwardChain(facts, forwardRules, backRules, onDerived /* optional */)
6287
6407
  function makeScopedSnapshot() {
6288
6408
  const snap = facts.slice();
6289
6409
  ensureFactIndexes(snap);
6290
- Object.defineProperty(snap, '__scopedSnapshot', { value: snap, enumerable: false, writable: true, configurable: true });
6410
+ Object.defineProperty(snap, '__scopedSnapshot', {
6411
+ value: snap,
6412
+ enumerable: false,
6413
+ writable: true,
6414
+ configurable: true,
6415
+ });
6291
6416
  return snap;
6292
6417
  }
6293
6418
 
@@ -6321,14 +6446,22 @@ function forwardChain(facts, forwardRules, backRules, onDerived /* optional */)
6321
6446
  const isFwRuleTriple =
6322
6447
  isLogImplies(instantiated.p) &&
6323
6448
  ((instantiated.s instanceof GraphTerm && instantiated.o instanceof GraphTerm) ||
6324
- (instantiated.s instanceof Literal && instantiated.s.value === 'true' && instantiated.o instanceof GraphTerm) ||
6325
- (instantiated.s instanceof GraphTerm && instantiated.o instanceof Literal && instantiated.o.value === 'true'));
6449
+ (instantiated.s instanceof Literal &&
6450
+ instantiated.s.value === 'true' &&
6451
+ instantiated.o instanceof GraphTerm) ||
6452
+ (instantiated.s instanceof GraphTerm &&
6453
+ instantiated.o instanceof Literal &&
6454
+ instantiated.o.value === 'true'));
6326
6455
 
6327
6456
  const isBwRuleTriple =
6328
6457
  isLogImpliedBy(instantiated.p) &&
6329
6458
  ((instantiated.s instanceof GraphTerm && instantiated.o instanceof GraphTerm) ||
6330
- (instantiated.s instanceof GraphTerm && instantiated.o instanceof Literal && instantiated.o.value === 'true') ||
6331
- (instantiated.s instanceof Literal && instantiated.s.value === 'true' && instantiated.o instanceof GraphTerm));
6459
+ (instantiated.s instanceof GraphTerm &&
6460
+ instantiated.o instanceof Literal &&
6461
+ instantiated.o.value === 'true') ||
6462
+ (instantiated.s instanceof Literal &&
6463
+ instantiated.s.value === 'true' &&
6464
+ instantiated.o instanceof GraphTerm));
6332
6465
 
6333
6466
  if (isFwRuleTriple || isBwRuleTriple) {
6334
6467
  if (!hasFactIndexed(facts, instantiated)) {
@@ -6394,14 +6527,23 @@ function forwardChain(facts, forwardRules, backRules, onDerived /* optional */)
6394
6527
  }
6395
6528
 
6396
6529
  // Only skolemize blank nodes that occur explicitly in the rule head
6397
- const inst = skolemizeTripleForHeadBlanks(instantiated, r.headBlankLabels, skMap, skCounter, fireKey, headSkolemCache);
6530
+ const inst = skolemizeTripleForHeadBlanks(
6531
+ instantiated,
6532
+ r.headBlankLabels,
6533
+ skMap,
6534
+ skCounter,
6535
+ fireKey,
6536
+ headSkolemCache,
6537
+ );
6398
6538
 
6399
6539
  if (!isGroundTriple(inst)) continue;
6400
6540
  if (hasFactIndexed(facts, inst)) continue;
6401
6541
 
6402
6542
  factList.push(inst);
6403
6543
  pushFactIndexed(facts, inst);
6404
- const df = new DerivedFact(inst, r, instantiatedPremises.slice(), { ...s });
6544
+ const df = new DerivedFact(inst, r, instantiatedPremises.slice(), {
6545
+ ...s,
6546
+ });
6405
6547
  derivedForward.push(df);
6406
6548
  if (typeof onDerived === 'function') onDerived(df);
6407
6549
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.7.12",
3
+ "version": "1.7.13",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [