eyeling 1.22.7 → 1.22.8

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.
@@ -6660,14 +6660,44 @@
6660
6660
  }
6661
6661
  }
6662
6662
 
6663
- function collectProtectedNamesFromSubst(subst) {
6663
+ function collectProtectedNamesFromTermViaSubst(term, subst, protectedVars, protectedBlanks, seenVarNames) {
6664
+ if (term instanceof Var) {
6665
+ if (!subst || !Object.prototype.hasOwnProperty.call(subst, term.name)) return;
6666
+ if (seenVarNames.has(term.name)) return;
6667
+ seenVarNames.add(term.name);
6668
+ collectProtectedNamesInTerm(subst[term.name], protectedVars, protectedBlanks);
6669
+ return;
6670
+ }
6671
+
6672
+ if (term instanceof ListTerm) {
6673
+ for (const e of term.elems)
6674
+ collectProtectedNamesFromTermViaSubst(e, subst, protectedVars, protectedBlanks, seenVarNames);
6675
+ return;
6676
+ }
6677
+
6678
+ if (term instanceof OpenListTerm) {
6679
+ for (const e of term.prefix)
6680
+ collectProtectedNamesFromTermViaSubst(e, subst, protectedVars, protectedBlanks, seenVarNames);
6681
+ if (subst && Object.prototype.hasOwnProperty.call(subst, term.tailVar) && !seenVarNames.has(term.tailVar)) {
6682
+ seenVarNames.add(term.tailVar);
6683
+ collectProtectedNamesInTerm(subst[term.tailVar], protectedVars, protectedBlanks);
6684
+ }
6685
+ return;
6686
+ }
6687
+
6688
+ if (term instanceof GraphTerm) {
6689
+ for (const tr of term.triples) {
6690
+ collectProtectedNamesFromTermViaSubst(tr.s, subst, protectedVars, protectedBlanks, seenVarNames);
6691
+ collectProtectedNamesFromTermViaSubst(tr.p, subst, protectedVars, protectedBlanks, seenVarNames);
6692
+ collectProtectedNamesFromTermViaSubst(tr.o, subst, protectedVars, protectedBlanks, seenVarNames);
6693
+ }
6694
+ }
6695
+ }
6696
+
6697
+ function collectProtectedNamesForTerm(term, subst) {
6664
6698
  const protectedVars = new Set();
6665
6699
  const protectedBlanks = new Set();
6666
- if (!subst) return { protectedVars, protectedBlanks };
6667
- for (const k in subst) {
6668
- if (!Object.prototype.hasOwnProperty.call(subst, k)) continue;
6669
- collectProtectedNamesInTerm(subst[k], protectedVars, protectedBlanks);
6670
- }
6700
+ collectProtectedNamesFromTermViaSubst(term, subst, protectedVars, protectedBlanks, new Set());
6671
6701
  return { protectedVars, protectedBlanks };
6672
6702
  }
6673
6703
 
@@ -7629,6 +7659,9 @@
7629
7659
  }
7630
7660
 
7631
7661
  function unifyTermWithOptions(a, b, subst, opts) {
7662
+ const aRaw = a;
7663
+ const bRaw = b;
7664
+
7632
7665
  a = applySubstTerm(a, subst);
7633
7666
  b = applySubstTerm(b, subst);
7634
7667
 
@@ -7736,13 +7769,14 @@
7736
7769
 
7737
7770
  // Graphs
7738
7771
  if (a instanceof GraphTerm && b instanceof GraphTerm) {
7739
- const protectedNames = collectProtectedNamesFromSubst(subst);
7772
+ const protectedNamesA = collectProtectedNamesForTerm(aRaw, subst);
7773
+ const protectedNamesB = collectProtectedNamesForTerm(bRaw, subst);
7740
7774
  if (
7741
7775
  alphaEqGraphTriples(a.triples, b.triples, {
7742
- protectedVarsA: protectedNames.protectedVars,
7743
- protectedVarsB: protectedNames.protectedVars,
7744
- protectedBlanksA: protectedNames.protectedBlanks,
7745
- protectedBlanksB: protectedNames.protectedBlanks,
7776
+ protectedVarsA: protectedNamesA.protectedVars,
7777
+ protectedVarsB: protectedNamesB.protectedVars,
7778
+ protectedBlanksA: protectedNamesA.protectedBlanks,
7779
+ protectedBlanksB: protectedNamesB.protectedBlanks,
7746
7780
  })
7747
7781
  ) {
7748
7782
  return subst;
@@ -8046,6 +8080,9 @@
8046
8080
  }
8047
8081
 
8048
8082
  function unifyTermTrail(a, b) {
8083
+ const aRaw = a;
8084
+ const bRaw = b;
8085
+
8049
8086
  a = applySubstTerm(a, substMut);
8050
8087
  b = applySubstTerm(b, substMut);
8051
8088
 
@@ -8123,24 +8160,25 @@
8123
8160
 
8124
8161
  // Graphs
8125
8162
  if (a instanceof GraphTerm && b instanceof GraphTerm) {
8126
- const protectedNames = collectProtectedNamesFromSubst(substMut);
8163
+ const protectedNamesA = collectProtectedNamesForTerm(aRaw, substMut);
8164
+ const protectedNamesB = collectProtectedNamesForTerm(bRaw, substMut);
8127
8165
  if (
8128
8166
  alphaEqGraphTriples(a.triples, b.triples, {
8129
- protectedVarsA: protectedNames.protectedVars,
8130
- protectedVarsB: protectedNames.protectedVars,
8131
- protectedBlanksA: protectedNames.protectedBlanks,
8132
- protectedBlanksB: protectedNames.protectedBlanks,
8167
+ protectedVarsA: protectedNamesA.protectedVars,
8168
+ protectedVarsB: protectedNamesB.protectedVars,
8169
+ protectedBlanksA: protectedNamesA.protectedBlanks,
8170
+ protectedBlanksB: protectedNamesB.protectedBlanks,
8133
8171
  })
8134
8172
  ) {
8135
8173
  return true;
8136
8174
  }
8137
- // Fallback: reuse allocation-heavy graph unifier rarely hit in typical workloads.
8138
- const delta = unifyGraphTriples(a.triples, b.triples, {});
8139
- if (delta === null) return false;
8175
+ const merged = unifyGraphTriples(a.triples, b.triples, substMut);
8176
+ if (merged === null) return false;
8140
8177
  const mark = trail.length;
8141
- for (const k in delta) {
8142
- if (!Object.prototype.hasOwnProperty.call(delta, k)) continue;
8143
- if (!bindVarTrail(k, delta[k])) {
8178
+ for (const k in merged) {
8179
+ if (!Object.prototype.hasOwnProperty.call(merged, k)) continue;
8180
+ if (Object.prototype.hasOwnProperty.call(substMut, k)) continue;
8181
+ if (!bindVarTrail(k, merged[k])) {
8144
8182
  undoTo(mark);
8145
8183
  return false;
8146
8184
  }
package/eyeling.js CHANGED
@@ -6641,14 +6641,44 @@ function collectProtectedNamesInTerm(t, protectedVars, protectedBlanks) {
6641
6641
  }
6642
6642
  }
6643
6643
 
6644
- function collectProtectedNamesFromSubst(subst) {
6644
+ function collectProtectedNamesFromTermViaSubst(term, subst, protectedVars, protectedBlanks, seenVarNames) {
6645
+ if (term instanceof Var) {
6646
+ if (!subst || !Object.prototype.hasOwnProperty.call(subst, term.name)) return;
6647
+ if (seenVarNames.has(term.name)) return;
6648
+ seenVarNames.add(term.name);
6649
+ collectProtectedNamesInTerm(subst[term.name], protectedVars, protectedBlanks);
6650
+ return;
6651
+ }
6652
+
6653
+ if (term instanceof ListTerm) {
6654
+ for (const e of term.elems)
6655
+ collectProtectedNamesFromTermViaSubst(e, subst, protectedVars, protectedBlanks, seenVarNames);
6656
+ return;
6657
+ }
6658
+
6659
+ if (term instanceof OpenListTerm) {
6660
+ for (const e of term.prefix)
6661
+ collectProtectedNamesFromTermViaSubst(e, subst, protectedVars, protectedBlanks, seenVarNames);
6662
+ if (subst && Object.prototype.hasOwnProperty.call(subst, term.tailVar) && !seenVarNames.has(term.tailVar)) {
6663
+ seenVarNames.add(term.tailVar);
6664
+ collectProtectedNamesInTerm(subst[term.tailVar], protectedVars, protectedBlanks);
6665
+ }
6666
+ return;
6667
+ }
6668
+
6669
+ if (term instanceof GraphTerm) {
6670
+ for (const tr of term.triples) {
6671
+ collectProtectedNamesFromTermViaSubst(tr.s, subst, protectedVars, protectedBlanks, seenVarNames);
6672
+ collectProtectedNamesFromTermViaSubst(tr.p, subst, protectedVars, protectedBlanks, seenVarNames);
6673
+ collectProtectedNamesFromTermViaSubst(tr.o, subst, protectedVars, protectedBlanks, seenVarNames);
6674
+ }
6675
+ }
6676
+ }
6677
+
6678
+ function collectProtectedNamesForTerm(term, subst) {
6645
6679
  const protectedVars = new Set();
6646
6680
  const protectedBlanks = new Set();
6647
- if (!subst) return { protectedVars, protectedBlanks };
6648
- for (const k in subst) {
6649
- if (!Object.prototype.hasOwnProperty.call(subst, k)) continue;
6650
- collectProtectedNamesInTerm(subst[k], protectedVars, protectedBlanks);
6651
- }
6681
+ collectProtectedNamesFromTermViaSubst(term, subst, protectedVars, protectedBlanks, new Set());
6652
6682
  return { protectedVars, protectedBlanks };
6653
6683
  }
6654
6684
 
@@ -7610,6 +7640,9 @@ function unifyTermListAppend(a, b, subst) {
7610
7640
  }
7611
7641
 
7612
7642
  function unifyTermWithOptions(a, b, subst, opts) {
7643
+ const aRaw = a;
7644
+ const bRaw = b;
7645
+
7613
7646
  a = applySubstTerm(a, subst);
7614
7647
  b = applySubstTerm(b, subst);
7615
7648
 
@@ -7717,13 +7750,14 @@ function unifyTermWithOptions(a, b, subst, opts) {
7717
7750
 
7718
7751
  // Graphs
7719
7752
  if (a instanceof GraphTerm && b instanceof GraphTerm) {
7720
- const protectedNames = collectProtectedNamesFromSubst(subst);
7753
+ const protectedNamesA = collectProtectedNamesForTerm(aRaw, subst);
7754
+ const protectedNamesB = collectProtectedNamesForTerm(bRaw, subst);
7721
7755
  if (
7722
7756
  alphaEqGraphTriples(a.triples, b.triples, {
7723
- protectedVarsA: protectedNames.protectedVars,
7724
- protectedVarsB: protectedNames.protectedVars,
7725
- protectedBlanksA: protectedNames.protectedBlanks,
7726
- protectedBlanksB: protectedNames.protectedBlanks,
7757
+ protectedVarsA: protectedNamesA.protectedVars,
7758
+ protectedVarsB: protectedNamesB.protectedVars,
7759
+ protectedBlanksA: protectedNamesA.protectedBlanks,
7760
+ protectedBlanksB: protectedNamesB.protectedBlanks,
7727
7761
  })
7728
7762
  ) {
7729
7763
  return subst;
@@ -8027,6 +8061,9 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
8027
8061
  }
8028
8062
 
8029
8063
  function unifyTermTrail(a, b) {
8064
+ const aRaw = a;
8065
+ const bRaw = b;
8066
+
8030
8067
  a = applySubstTerm(a, substMut);
8031
8068
  b = applySubstTerm(b, substMut);
8032
8069
 
@@ -8104,24 +8141,25 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
8104
8141
 
8105
8142
  // Graphs
8106
8143
  if (a instanceof GraphTerm && b instanceof GraphTerm) {
8107
- const protectedNames = collectProtectedNamesFromSubst(substMut);
8144
+ const protectedNamesA = collectProtectedNamesForTerm(aRaw, substMut);
8145
+ const protectedNamesB = collectProtectedNamesForTerm(bRaw, substMut);
8108
8146
  if (
8109
8147
  alphaEqGraphTriples(a.triples, b.triples, {
8110
- protectedVarsA: protectedNames.protectedVars,
8111
- protectedVarsB: protectedNames.protectedVars,
8112
- protectedBlanksA: protectedNames.protectedBlanks,
8113
- protectedBlanksB: protectedNames.protectedBlanks,
8148
+ protectedVarsA: protectedNamesA.protectedVars,
8149
+ protectedVarsB: protectedNamesB.protectedVars,
8150
+ protectedBlanksA: protectedNamesA.protectedBlanks,
8151
+ protectedBlanksB: protectedNamesB.protectedBlanks,
8114
8152
  })
8115
8153
  ) {
8116
8154
  return true;
8117
8155
  }
8118
- // Fallback: reuse allocation-heavy graph unifier rarely hit in typical workloads.
8119
- const delta = unifyGraphTriples(a.triples, b.triples, {});
8120
- if (delta === null) return false;
8156
+ const merged = unifyGraphTriples(a.triples, b.triples, substMut);
8157
+ if (merged === null) return false;
8121
8158
  const mark = trail.length;
8122
- for (const k in delta) {
8123
- if (!Object.prototype.hasOwnProperty.call(delta, k)) continue;
8124
- if (!bindVarTrail(k, delta[k])) {
8159
+ for (const k in merged) {
8160
+ if (!Object.prototype.hasOwnProperty.call(merged, k)) continue;
8161
+ if (Object.prototype.hasOwnProperty.call(substMut, k)) continue;
8162
+ if (!bindVarTrail(k, merged[k])) {
8125
8163
  undoTo(mark);
8126
8164
  return false;
8127
8165
  }
package/lib/engine.js CHANGED
@@ -846,14 +846,44 @@ function collectProtectedNamesInTerm(t, protectedVars, protectedBlanks) {
846
846
  }
847
847
  }
848
848
 
849
- function collectProtectedNamesFromSubst(subst) {
849
+ function collectProtectedNamesFromTermViaSubst(term, subst, protectedVars, protectedBlanks, seenVarNames) {
850
+ if (term instanceof Var) {
851
+ if (!subst || !Object.prototype.hasOwnProperty.call(subst, term.name)) return;
852
+ if (seenVarNames.has(term.name)) return;
853
+ seenVarNames.add(term.name);
854
+ collectProtectedNamesInTerm(subst[term.name], protectedVars, protectedBlanks);
855
+ return;
856
+ }
857
+
858
+ if (term instanceof ListTerm) {
859
+ for (const e of term.elems)
860
+ collectProtectedNamesFromTermViaSubst(e, subst, protectedVars, protectedBlanks, seenVarNames);
861
+ return;
862
+ }
863
+
864
+ if (term instanceof OpenListTerm) {
865
+ for (const e of term.prefix)
866
+ collectProtectedNamesFromTermViaSubst(e, subst, protectedVars, protectedBlanks, seenVarNames);
867
+ if (subst && Object.prototype.hasOwnProperty.call(subst, term.tailVar) && !seenVarNames.has(term.tailVar)) {
868
+ seenVarNames.add(term.tailVar);
869
+ collectProtectedNamesInTerm(subst[term.tailVar], protectedVars, protectedBlanks);
870
+ }
871
+ return;
872
+ }
873
+
874
+ if (term instanceof GraphTerm) {
875
+ for (const tr of term.triples) {
876
+ collectProtectedNamesFromTermViaSubst(tr.s, subst, protectedVars, protectedBlanks, seenVarNames);
877
+ collectProtectedNamesFromTermViaSubst(tr.p, subst, protectedVars, protectedBlanks, seenVarNames);
878
+ collectProtectedNamesFromTermViaSubst(tr.o, subst, protectedVars, protectedBlanks, seenVarNames);
879
+ }
880
+ }
881
+ }
882
+
883
+ function collectProtectedNamesForTerm(term, subst) {
850
884
  const protectedVars = new Set();
851
885
  const protectedBlanks = new Set();
852
- if (!subst) return { protectedVars, protectedBlanks };
853
- for (const k in subst) {
854
- if (!Object.prototype.hasOwnProperty.call(subst, k)) continue;
855
- collectProtectedNamesInTerm(subst[k], protectedVars, protectedBlanks);
856
- }
886
+ collectProtectedNamesFromTermViaSubst(term, subst, protectedVars, protectedBlanks, new Set());
857
887
  return { protectedVars, protectedBlanks };
858
888
  }
859
889
 
@@ -1815,6 +1845,9 @@ function unifyTermListAppend(a, b, subst) {
1815
1845
  }
1816
1846
 
1817
1847
  function unifyTermWithOptions(a, b, subst, opts) {
1848
+ const aRaw = a;
1849
+ const bRaw = b;
1850
+
1818
1851
  a = applySubstTerm(a, subst);
1819
1852
  b = applySubstTerm(b, subst);
1820
1853
 
@@ -1922,13 +1955,14 @@ function unifyTermWithOptions(a, b, subst, opts) {
1922
1955
 
1923
1956
  // Graphs
1924
1957
  if (a instanceof GraphTerm && b instanceof GraphTerm) {
1925
- const protectedNames = collectProtectedNamesFromSubst(subst);
1958
+ const protectedNamesA = collectProtectedNamesForTerm(aRaw, subst);
1959
+ const protectedNamesB = collectProtectedNamesForTerm(bRaw, subst);
1926
1960
  if (
1927
1961
  alphaEqGraphTriples(a.triples, b.triples, {
1928
- protectedVarsA: protectedNames.protectedVars,
1929
- protectedVarsB: protectedNames.protectedVars,
1930
- protectedBlanksA: protectedNames.protectedBlanks,
1931
- protectedBlanksB: protectedNames.protectedBlanks,
1962
+ protectedVarsA: protectedNamesA.protectedVars,
1963
+ protectedVarsB: protectedNamesB.protectedVars,
1964
+ protectedBlanksA: protectedNamesA.protectedBlanks,
1965
+ protectedBlanksB: protectedNamesB.protectedBlanks,
1932
1966
  })
1933
1967
  ) {
1934
1968
  return subst;
@@ -2232,6 +2266,9 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
2232
2266
  }
2233
2267
 
2234
2268
  function unifyTermTrail(a, b) {
2269
+ const aRaw = a;
2270
+ const bRaw = b;
2271
+
2235
2272
  a = applySubstTerm(a, substMut);
2236
2273
  b = applySubstTerm(b, substMut);
2237
2274
 
@@ -2309,24 +2346,25 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
2309
2346
 
2310
2347
  // Graphs
2311
2348
  if (a instanceof GraphTerm && b instanceof GraphTerm) {
2312
- const protectedNames = collectProtectedNamesFromSubst(substMut);
2349
+ const protectedNamesA = collectProtectedNamesForTerm(aRaw, substMut);
2350
+ const protectedNamesB = collectProtectedNamesForTerm(bRaw, substMut);
2313
2351
  if (
2314
2352
  alphaEqGraphTriples(a.triples, b.triples, {
2315
- protectedVarsA: protectedNames.protectedVars,
2316
- protectedVarsB: protectedNames.protectedVars,
2317
- protectedBlanksA: protectedNames.protectedBlanks,
2318
- protectedBlanksB: protectedNames.protectedBlanks,
2353
+ protectedVarsA: protectedNamesA.protectedVars,
2354
+ protectedVarsB: protectedNamesB.protectedVars,
2355
+ protectedBlanksA: protectedNamesA.protectedBlanks,
2356
+ protectedBlanksB: protectedNamesB.protectedBlanks,
2319
2357
  })
2320
2358
  ) {
2321
2359
  return true;
2322
2360
  }
2323
- // Fallback: reuse allocation-heavy graph unifier rarely hit in typical workloads.
2324
- const delta = unifyGraphTriples(a.triples, b.triples, {});
2325
- if (delta === null) return false;
2361
+ const merged = unifyGraphTriples(a.triples, b.triples, substMut);
2362
+ if (merged === null) return false;
2326
2363
  const mark = trail.length;
2327
- for (const k in delta) {
2328
- if (!Object.prototype.hasOwnProperty.call(delta, k)) continue;
2329
- if (!bindVarTrail(k, delta[k])) {
2364
+ for (const k in merged) {
2365
+ if (!Object.prototype.hasOwnProperty.call(merged, k)) continue;
2366
+ if (Object.prototype.hasOwnProperty.call(substMut, k)) continue;
2367
+ if (!bindVarTrail(k, merged[k])) {
2330
2368
  undoTo(mark);
2331
2369
  return false;
2332
2370
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.22.7",
3
+ "version": "1.22.8",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [
package/test/api.test.js CHANGED
@@ -2305,6 +2305,37 @@ _:x :hates { _:foo :making :mess }.
2305
2305
  }
2306
2306
  },
2307
2307
  },
2308
+ {
2309
+ name: 'regression: unrelated blank bindings must not block alpha-equivalent quoted-formula matches',
2310
+ opt: { proofComments: false },
2311
+ input: `@prefix log: <http://www.w3.org/2000/10/swap/log#> .
2312
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2313
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
2314
+ @prefix : <http://example.org/ns#> .
2315
+
2316
+ {
2317
+ _:b1 a :Mortal .
2318
+ } :because {
2319
+ :Socrates a :Human .
2320
+ :Human rdfs:subClassOf :Mortal .
2321
+ } .
2322
+
2323
+ <> :step {
2324
+ [ a :Mortal ].
2325
+ }.
2326
+
2327
+ {
2328
+ ?A :step ?B .
2329
+ ?B log:includes { ?S ?P ?O }.
2330
+ { _:b2 a :Mortal } :because ?Y.
2331
+ }
2332
+ =>
2333
+ {
2334
+ :test :is true .
2335
+ }.
2336
+ `,
2337
+ expect: [/^:test\s+:is\s+true\s*\./m],
2338
+ },
2308
2339
  ];
2309
2340
 
2310
2341
  let passed = 0;