eyeling 1.26.2 → 1.26.4
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/dist/browser/eyeling.browser.js +195 -533
- package/eyeling.js +195 -533
- package/lib/engine.js +195 -533
- package/package.json +1 -1
|
@@ -5535,6 +5535,27 @@ const INFERENCE_FUSE_EXIT_CODE = 65;
|
|
|
5535
5535
|
const RDF_NIL_IRI = RDF_NS + 'nil';
|
|
5536
5536
|
const EMPTY_LIST_TERM = new ListTerm([]);
|
|
5537
5537
|
|
|
5538
|
+
const LOG_COLLECT_ALL_IN_IRI = LOG_NS + 'collectAllIn';
|
|
5539
|
+
const LOG_FOR_ALL_IN_IRI = LOG_NS + 'forAllIn';
|
|
5540
|
+
const LOG_INCLUDES_IRI = LOG_NS + 'includes';
|
|
5541
|
+
const LOG_NOT_INCLUDES_IRI = LOG_NS + 'notIncludes';
|
|
5542
|
+
const LOG_IMPLIES_IRI = LOG_NS + 'implies';
|
|
5543
|
+
const LOG_IMPLIED_BY_IRI = LOG_NS + 'impliedBy';
|
|
5544
|
+
|
|
5545
|
+
const MATH_BUILTINS_SATISFIABLE_WHEN_FULLY_UNBOUND = new Set([
|
|
5546
|
+
MATH_NS + 'sin',
|
|
5547
|
+
MATH_NS + 'cos',
|
|
5548
|
+
MATH_NS + 'tan',
|
|
5549
|
+
MATH_NS + 'asin',
|
|
5550
|
+
MATH_NS + 'acos',
|
|
5551
|
+
MATH_NS + 'atan',
|
|
5552
|
+
MATH_NS + 'sinh',
|
|
5553
|
+
MATH_NS + 'cosh',
|
|
5554
|
+
MATH_NS + 'tanh',
|
|
5555
|
+
MATH_NS + 'degrees',
|
|
5556
|
+
MATH_NS + 'negation',
|
|
5557
|
+
]);
|
|
5558
|
+
|
|
5538
5559
|
const { lex, N3SyntaxError } = require('./lexer');
|
|
5539
5560
|
const { Parser } = require('./parser');
|
|
5540
5561
|
const { liftBlankRuleVars } = require('./rules');
|
|
@@ -5595,6 +5616,29 @@ function __cloneSubst(subst) {
|
|
|
5595
5616
|
return out;
|
|
5596
5617
|
}
|
|
5597
5618
|
|
|
5619
|
+
function __defineHidden(obj, name, value, writable) {
|
|
5620
|
+
Object.defineProperty(obj, name, { value, enumerable: false, writable, configurable: true });
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5623
|
+
function __defineHiddenValue(obj, name, value) {
|
|
5624
|
+
__defineHidden(obj, name, value, false);
|
|
5625
|
+
}
|
|
5626
|
+
|
|
5627
|
+
function __defineHiddenWritable(obj, name, value) {
|
|
5628
|
+
__defineHidden(obj, name, value, true);
|
|
5629
|
+
}
|
|
5630
|
+
|
|
5631
|
+
function __setHiddenWritable(obj, name, value) {
|
|
5632
|
+
if (hasOwn.call(obj, name)) obj[name] = value;
|
|
5633
|
+
else __defineHiddenWritable(obj, name, value);
|
|
5634
|
+
}
|
|
5635
|
+
|
|
5636
|
+
const FACT_INDEX_ARRAY_FIELDS = ['__varPred', '__varPredNonFastS', '__varPredNonFastO'];
|
|
5637
|
+
const FACT_INDEX_ARRAY_MAP_FIELDS = ['__byPred', '__byPNonFastS', '__byPNonFastO', '__varPredPS', '__varPredPO'];
|
|
5638
|
+
const FACT_INDEX_NESTED_ARRAY_MAP_FIELDS = ['__byPS', '__byPO'];
|
|
5639
|
+
const FACT_INDEX_MAP_FIELDS = FACT_INDEX_ARRAY_MAP_FIELDS.concat(FACT_INDEX_NESTED_ARRAY_MAP_FIELDS);
|
|
5640
|
+
const FACT_INDEX_REQUIRED_FIELDS = FACT_INDEX_ARRAY_FIELDS.concat(FACT_INDEX_MAP_FIELDS, ['__keySet']);
|
|
5641
|
+
|
|
5598
5642
|
let version = 'dev';
|
|
5599
5643
|
try {
|
|
5600
5644
|
// Node: keep package.json version if available
|
|
@@ -5818,14 +5862,13 @@ function __firingKey(ruleIndex, instantiatedPremises) {
|
|
|
5818
5862
|
// -----------------------------------------------------------------------------
|
|
5819
5863
|
function __ensureRuleKeySet(rules) {
|
|
5820
5864
|
if (!hasOwn.call(rules, '__ruleKeySet')) {
|
|
5821
|
-
|
|
5822
|
-
|
|
5865
|
+
__defineHiddenValue(
|
|
5866
|
+
rules,
|
|
5867
|
+
'__ruleKeySet',
|
|
5868
|
+
new Set(
|
|
5823
5869
|
rules.map((r) => __ruleKey(r.isForward, r.isFuse, r.premise, r.conclusion, r.__dynamicConclusionTerm || null)),
|
|
5824
5870
|
),
|
|
5825
|
-
|
|
5826
|
-
writable: false,
|
|
5827
|
-
configurable: true,
|
|
5828
|
-
});
|
|
5871
|
+
);
|
|
5829
5872
|
}
|
|
5830
5873
|
return rules.__ruleKeySet;
|
|
5831
5874
|
}
|
|
@@ -5843,28 +5886,13 @@ function __computeHeadIsStrictGround(r) {
|
|
|
5843
5886
|
function __prepareForwardRule(r) {
|
|
5844
5887
|
if (!hasOwn.call(r, '__scopedSkipInfo')) {
|
|
5845
5888
|
const info = __computeForwardRuleScopedSkipInfo(r);
|
|
5846
|
-
|
|
5847
|
-
value: info,
|
|
5848
|
-
enumerable: false,
|
|
5849
|
-
writable: false,
|
|
5850
|
-
configurable: true,
|
|
5851
|
-
});
|
|
5889
|
+
__defineHiddenValue(r, '__scopedSkipInfo', info);
|
|
5852
5890
|
}
|
|
5853
5891
|
if (!hasOwn.call(r, '__headIsStrictGround')) {
|
|
5854
|
-
|
|
5855
|
-
value: __computeHeadIsStrictGround(r),
|
|
5856
|
-
enumerable: false,
|
|
5857
|
-
writable: false,
|
|
5858
|
-
configurable: true,
|
|
5859
|
-
});
|
|
5892
|
+
__defineHiddenValue(r, '__headIsStrictGround', __computeHeadIsStrictGround(r));
|
|
5860
5893
|
}
|
|
5861
5894
|
if (!hasOwn.call(r, '__needsForwardSkipCheck')) {
|
|
5862
|
-
|
|
5863
|
-
value: !!(r.__headIsStrictGround || (r.__scopedSkipInfo && r.__scopedSkipInfo.needsSnap)),
|
|
5864
|
-
enumerable: false,
|
|
5865
|
-
writable: false,
|
|
5866
|
-
configurable: true,
|
|
5867
|
-
});
|
|
5895
|
+
__defineHiddenValue(r, '__needsForwardSkipCheck', !!(r.__headIsStrictGround || (r.__scopedSkipInfo && r.__scopedSkipInfo.needsSnap)));
|
|
5868
5896
|
}
|
|
5869
5897
|
}
|
|
5870
5898
|
|
|
@@ -5906,44 +5934,29 @@ function __logNaturalPriorityFromTerm(t) {
|
|
|
5906
5934
|
function __computeMaxScopedClosurePriorityNeeded(forwardRules, backRules) {
|
|
5907
5935
|
let maxP = 0;
|
|
5908
5936
|
|
|
5937
|
+
function bumpMaxPriority(term) {
|
|
5938
|
+
if (term instanceof GraphTerm) return;
|
|
5939
|
+
if (term instanceof Var) {
|
|
5940
|
+
if (maxP < 1) maxP = 1;
|
|
5941
|
+
return;
|
|
5942
|
+
}
|
|
5943
|
+
const p0 = __logNaturalPriorityFromTerm(term);
|
|
5944
|
+
const priority = p0 !== null ? p0 : 1;
|
|
5945
|
+
if (priority > maxP) maxP = priority;
|
|
5946
|
+
}
|
|
5947
|
+
|
|
5909
5948
|
function scanTriple(tr) {
|
|
5910
5949
|
if (!(tr && tr.p instanceof Iri)) return;
|
|
5911
5950
|
const pv = tr.p.value;
|
|
5912
5951
|
|
|
5913
5952
|
// log:collectAllIn / log:forAllIn use the object position for the priority.
|
|
5914
|
-
if (pv ===
|
|
5915
|
-
|
|
5916
|
-
if (tr.o instanceof GraphTerm) return;
|
|
5917
|
-
// Variable or non-numeric object => default priority 1 (if used).
|
|
5918
|
-
if (tr.o instanceof Var) {
|
|
5919
|
-
if (maxP < 1) maxP = 1;
|
|
5920
|
-
return;
|
|
5921
|
-
}
|
|
5922
|
-
const p0 = __logNaturalPriorityFromTerm(tr.o);
|
|
5923
|
-
if (p0 !== null) {
|
|
5924
|
-
if (p0 > maxP) maxP = p0;
|
|
5925
|
-
} else {
|
|
5926
|
-
if (maxP < 1) maxP = 1;
|
|
5927
|
-
}
|
|
5953
|
+
if (pv === LOG_COLLECT_ALL_IN_IRI || pv === LOG_FOR_ALL_IN_IRI) {
|
|
5954
|
+
bumpMaxPriority(tr.o);
|
|
5928
5955
|
return;
|
|
5929
5956
|
}
|
|
5930
5957
|
|
|
5931
5958
|
// log:includes / log:notIncludes use the subject position for the priority.
|
|
5932
|
-
if (pv ===
|
|
5933
|
-
// Explicit scope graphs are immediate and do not require a closure.
|
|
5934
|
-
if (tr.s instanceof GraphTerm) return;
|
|
5935
|
-
// Variable or non-numeric subject => default priority 1 (if used).
|
|
5936
|
-
if (tr.s instanceof Var) {
|
|
5937
|
-
if (maxP < 1) maxP = 1;
|
|
5938
|
-
return;
|
|
5939
|
-
}
|
|
5940
|
-
const p0 = __logNaturalPriorityFromTerm(tr.s);
|
|
5941
|
-
if (p0 !== null) {
|
|
5942
|
-
if (p0 > maxP) maxP = p0;
|
|
5943
|
-
} else {
|
|
5944
|
-
if (maxP < 1) maxP = 1;
|
|
5945
|
-
}
|
|
5946
|
-
}
|
|
5959
|
+
if (pv === LOG_INCLUDES_IRI || pv === LOG_NOT_INCLUDES_IRI) bumpMaxPriority(tr.s);
|
|
5947
5960
|
}
|
|
5948
5961
|
|
|
5949
5962
|
for (const r of forwardRules) {
|
|
@@ -5955,17 +5968,6 @@ function __computeMaxScopedClosurePriorityNeeded(forwardRules, backRules) {
|
|
|
5955
5968
|
return maxP;
|
|
5956
5969
|
}
|
|
5957
5970
|
|
|
5958
|
-
function __termContainsVarName(t, name) {
|
|
5959
|
-
if (t instanceof Var) return t.name === name;
|
|
5960
|
-
if (t instanceof ListTerm) return t.elems.some((e) => __termContainsVarName(e, name));
|
|
5961
|
-
if (t instanceof OpenListTerm) return t.tailVar === name || t.prefix.some((e) => __termContainsVarName(e, name));
|
|
5962
|
-
if (t instanceof GraphTerm)
|
|
5963
|
-
return t.triples.some(
|
|
5964
|
-
(tr) =>
|
|
5965
|
-
__termContainsVarName(tr.s, name) || __termContainsVarName(tr.p, name) || __termContainsVarName(tr.o, name),
|
|
5966
|
-
);
|
|
5967
|
-
return false;
|
|
5968
|
-
}
|
|
5969
5971
|
|
|
5970
5972
|
function __varOccursElsewhereInPremise(premise, name, idx, field) {
|
|
5971
5973
|
for (let i = 0; i < premise.length; i++) {
|
|
@@ -5973,14 +5975,13 @@ function __varOccursElsewhereInPremise(premise, name, idx, field) {
|
|
|
5973
5975
|
if (!(tr && tr.s && tr.p && tr.o)) continue;
|
|
5974
5976
|
|
|
5975
5977
|
// Skip the specific scope/priority occurrence we are analyzing.
|
|
5976
|
-
if (!(i === idx && field === 's') &&
|
|
5977
|
-
if (!(i === idx && field === 'p') &&
|
|
5978
|
-
if (!(i === idx && field === 'o') &&
|
|
5978
|
+
if (!(i === idx && field === 's') && containsVarTerm(tr.s, name)) return true;
|
|
5979
|
+
if (!(i === idx && field === 'p') && containsVarTerm(tr.p, name)) return true;
|
|
5980
|
+
if (!(i === idx && field === 'o') && containsVarTerm(tr.o, name)) return true;
|
|
5979
5981
|
}
|
|
5980
5982
|
return false;
|
|
5981
5983
|
}
|
|
5982
5984
|
|
|
5983
|
-
|
|
5984
5985
|
function __scopedPriorityForTerm(t) {
|
|
5985
5986
|
if (t instanceof GraphTerm) return 0;
|
|
5986
5987
|
const p0 = __logNaturalPriorityFromTerm(t);
|
|
@@ -6007,7 +6008,7 @@ function __analyzeForwardRuleScopedUse(rule) {
|
|
|
6007
6008
|
if (!(tr && tr.p instanceof Iri)) continue;
|
|
6008
6009
|
const pv = tr.p.value;
|
|
6009
6010
|
|
|
6010
|
-
if (pv ===
|
|
6011
|
+
if (pv === LOG_INCLUDES_IRI || pv === LOG_NOT_INCLUDES_IRI) {
|
|
6011
6012
|
// Explicit quoted scopes are local formulas, not snapshots of the global closure.
|
|
6012
6013
|
if (tr.s instanceof GraphTerm) continue;
|
|
6013
6014
|
|
|
@@ -6021,7 +6022,7 @@ function __analyzeForwardRuleScopedUse(rule) {
|
|
|
6021
6022
|
continue;
|
|
6022
6023
|
}
|
|
6023
6024
|
|
|
6024
|
-
if (pv ===
|
|
6025
|
+
if (pv === LOG_COLLECT_ALL_IN_IRI) {
|
|
6025
6026
|
if (tr.o instanceof GraphTerm) continue;
|
|
6026
6027
|
|
|
6027
6028
|
out.needsSnap = true;
|
|
@@ -6033,7 +6034,7 @@ function __analyzeForwardRuleScopedUse(rule) {
|
|
|
6033
6034
|
continue;
|
|
6034
6035
|
}
|
|
6035
6036
|
|
|
6036
|
-
if (pv ===
|
|
6037
|
+
if (pv === LOG_FOR_ALL_IN_IRI) {
|
|
6037
6038
|
if (tr.o instanceof GraphTerm) continue;
|
|
6038
6039
|
|
|
6039
6040
|
out.needsSnap = true;
|
|
@@ -6075,16 +6076,7 @@ function __setForwardRuleScopedStratumInfo(rule, level) {
|
|
|
6075
6076
|
? { needsSnap: true, requiredLevel: level, exactLevel: true }
|
|
6076
6077
|
: { needsSnap: false, requiredLevel: 0, exactLevel: false };
|
|
6077
6078
|
|
|
6078
|
-
|
|
6079
|
-
Object.defineProperty(rule, '__scopedStratumInfo', {
|
|
6080
|
-
value,
|
|
6081
|
-
enumerable: false,
|
|
6082
|
-
writable: true,
|
|
6083
|
-
configurable: true,
|
|
6084
|
-
});
|
|
6085
|
-
} else {
|
|
6086
|
-
rule.__scopedStratumInfo = value;
|
|
6087
|
-
}
|
|
6079
|
+
__setHiddenWritable(rule, '__scopedStratumInfo', value);
|
|
6088
6080
|
}
|
|
6089
6081
|
|
|
6090
6082
|
function __computeForwardRuleScopedStrata(forwardRules) {
|
|
@@ -6122,7 +6114,6 @@ function __computeForwardRuleScopedStrata(forwardRules) {
|
|
|
6122
6114
|
if (!changed) break;
|
|
6123
6115
|
}
|
|
6124
6116
|
|
|
6125
|
-
|
|
6126
6117
|
maxLevel = 0;
|
|
6127
6118
|
for (let i = 0; i < forwardRules.length; i++) {
|
|
6128
6119
|
__setForwardRuleScopedStratumInfo(forwardRules[i], levels[i]);
|
|
@@ -6136,42 +6127,33 @@ function __computeForwardRuleScopedSkipInfo(rule) {
|
|
|
6136
6127
|
let needsSnap = false;
|
|
6137
6128
|
let requiredLevel = 0;
|
|
6138
6129
|
|
|
6130
|
+
function addScopedUse(scopeTerm, idx, field) {
|
|
6131
|
+
if (scopeTerm instanceof GraphTerm) return true; // explicit scope
|
|
6132
|
+
|
|
6133
|
+
// If scope term is a Var that appears elsewhere, it might be bound to a GraphTerm.
|
|
6134
|
+
// Be conservative and do not skip in that case.
|
|
6135
|
+
if (scopeTerm instanceof Var) {
|
|
6136
|
+
if (__varOccursElsewhereInPremise(rule.premise, scopeTerm.name, idx, field)) return false;
|
|
6137
|
+
needsSnap = true;
|
|
6138
|
+
requiredLevel = Math.max(requiredLevel, 1);
|
|
6139
|
+
return true;
|
|
6140
|
+
}
|
|
6141
|
+
|
|
6142
|
+
needsSnap = true;
|
|
6143
|
+
const p0 = __logNaturalPriorityFromTerm(scopeTerm);
|
|
6144
|
+
requiredLevel = Math.max(requiredLevel, p0 !== null ? p0 : 1);
|
|
6145
|
+
return true;
|
|
6146
|
+
}
|
|
6147
|
+
|
|
6139
6148
|
for (let i = 0; i < rule.premise.length; i++) {
|
|
6140
6149
|
const tr = rule.premise[i];
|
|
6141
6150
|
if (!(tr && tr.p instanceof Iri)) continue;
|
|
6142
6151
|
const pv = tr.p.value;
|
|
6143
6152
|
|
|
6144
|
-
if (pv ===
|
|
6145
|
-
if (tr.o
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
if (tr.o instanceof Var) {
|
|
6149
|
-
if (__varOccursElsewhereInPremise(rule.premise, tr.o.name, i, 'o')) return null;
|
|
6150
|
-
needsSnap = true;
|
|
6151
|
-
requiredLevel = Math.max(requiredLevel, 1);
|
|
6152
|
-
} else {
|
|
6153
|
-
needsSnap = true;
|
|
6154
|
-
let prio = 1;
|
|
6155
|
-
const p0 = __logNaturalPriorityFromTerm(tr.o);
|
|
6156
|
-
if (p0 !== null) prio = p0;
|
|
6157
|
-
requiredLevel = Math.max(requiredLevel, prio);
|
|
6158
|
-
}
|
|
6159
|
-
continue;
|
|
6160
|
-
}
|
|
6161
|
-
|
|
6162
|
-
if (pv === LOG_NS + 'includes' || pv === LOG_NS + 'notIncludes') {
|
|
6163
|
-
if (tr.s instanceof GraphTerm) continue; // explicit scope
|
|
6164
|
-
if (tr.s instanceof Var) {
|
|
6165
|
-
if (__varOccursElsewhereInPremise(rule.premise, tr.s.name, i, 's')) return null;
|
|
6166
|
-
needsSnap = true;
|
|
6167
|
-
requiredLevel = Math.max(requiredLevel, 1);
|
|
6168
|
-
} else {
|
|
6169
|
-
needsSnap = true;
|
|
6170
|
-
let prio = 1;
|
|
6171
|
-
const p0 = __logNaturalPriorityFromTerm(tr.s);
|
|
6172
|
-
if (p0 !== null) prio = p0;
|
|
6173
|
-
requiredLevel = Math.max(requiredLevel, prio);
|
|
6174
|
-
}
|
|
6153
|
+
if (pv === LOG_COLLECT_ALL_IN_IRI || pv === LOG_FOR_ALL_IN_IRI) {
|
|
6154
|
+
if (!addScopedUse(tr.o, i, 'o')) return null;
|
|
6155
|
+
} else if (pv === LOG_INCLUDES_IRI || pv === LOG_NOT_INCLUDES_IRI) {
|
|
6156
|
+
if (!addScopedUse(tr.s, i, 's')) return null;
|
|
6175
6157
|
}
|
|
6176
6158
|
}
|
|
6177
6159
|
|
|
@@ -6354,140 +6336,70 @@ function skolemizeTripleForHeadBlanks(tr, headBlankLabels, mapping, skCounter, f
|
|
|
6354
6336
|
// Alpha equivalence helpers
|
|
6355
6337
|
// ===========================================================================
|
|
6356
6338
|
|
|
6357
|
-
function
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
if (a.__tid && b.__tid && a.__tid === b.__tid) return true;
|
|
6361
|
-
|
|
6362
|
-
// rdf:nil is equivalent to the empty list ()
|
|
6363
|
-
if (a instanceof Iri && a.value === RDF_NIL_IRI && b instanceof ListTerm && b.elems.length === 0) return true;
|
|
6364
|
-
if (b instanceof Iri && b.value === RDF_NIL_IRI && a instanceof ListTerm && a.elems.length === 0) return true;
|
|
6365
|
-
if (a.constructor !== b.constructor) return false;
|
|
6366
|
-
|
|
6367
|
-
if (a instanceof Iri) return a.value === b.value;
|
|
6368
|
-
|
|
6369
|
-
if (a instanceof Literal) {
|
|
6370
|
-
if (a.value === b.value) return true;
|
|
6371
|
-
|
|
6372
|
-
// Plain "abc" == "abc"^^xsd:string (but not language-tagged strings)
|
|
6373
|
-
if (literalsEquivalentAsXsdString(a.value, b.value)) return true;
|
|
6339
|
+
function __isRdfNilEmptyListPair(a, b) {
|
|
6340
|
+
return a instanceof Iri && a.value === RDF_NIL_IRI && b instanceof ListTerm && b.elems.length === 0;
|
|
6341
|
+
}
|
|
6374
6342
|
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6343
|
+
function __numericInfosSameDatatypeEqual(ai, bi, exactDecimal) {
|
|
6344
|
+
if (!ai || !bi || ai.dt !== bi.dt) return false;
|
|
6345
|
+
if (ai.kind === 'bigint' && bi.kind === 'bigint') return ai.value === bi.value;
|
|
6378
6346
|
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
const bn = bi.kind === 'bigint' ? Number(bi.value) : bi.value;
|
|
6386
|
-
return !Number.isNaN(an) && !Number.isNaN(bn) && an === bn;
|
|
6387
|
-
}
|
|
6347
|
+
if (exactDecimal && ai.dt === XSD_NS + 'decimal') {
|
|
6348
|
+
const da = parseXsdDecimalToBigIntScale(ai.lexStr);
|
|
6349
|
+
const db = parseXsdDecimalToBigIntScale(bi.lexStr);
|
|
6350
|
+
if (da && db) {
|
|
6351
|
+
const scale = Math.max(da.scale, db.scale);
|
|
6352
|
+
return da.num * pow10n(scale - da.scale) === db.num * pow10n(scale - db.scale);
|
|
6388
6353
|
}
|
|
6389
|
-
|
|
6390
|
-
return false;
|
|
6391
6354
|
}
|
|
6392
6355
|
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
if (a.elems.length !== b.elems.length) return false;
|
|
6398
|
-
for (let i = 0; i < a.elems.length; i++) {
|
|
6399
|
-
if (!termsEqual(a.elems[i], b.elems[i])) return false;
|
|
6400
|
-
}
|
|
6401
|
-
return true;
|
|
6402
|
-
}
|
|
6356
|
+
const an = ai.kind === 'bigint' ? Number(ai.value) : ai.value;
|
|
6357
|
+
const bn = bi.kind === 'bigint' ? Number(bi.value) : bi.value;
|
|
6358
|
+
return !Number.isNaN(an) && !Number.isNaN(bn) && an === bn;
|
|
6359
|
+
}
|
|
6403
6360
|
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
}
|
|
6410
|
-
return true;
|
|
6411
|
-
}
|
|
6361
|
+
function __literalsEqual(a, b, exactDecimal) {
|
|
6362
|
+
if (a.value === b.value) return true;
|
|
6363
|
+
if (literalsEquivalentAsXsdString(a.value, b.value)) return true;
|
|
6364
|
+
return __numericInfosSameDatatypeEqual(parseNumericLiteralInfo(a), parseNumericLiteralInfo(b), exactDecimal);
|
|
6365
|
+
}
|
|
6412
6366
|
|
|
6413
|
-
|
|
6414
|
-
|
|
6367
|
+
function __termArraysEqual(xs, ys, eq) {
|
|
6368
|
+
if (xs.length !== ys.length) return false;
|
|
6369
|
+
for (let i = 0; i < xs.length; i++) {
|
|
6370
|
+
if (!eq(xs[i], ys[i])) return false;
|
|
6415
6371
|
}
|
|
6416
|
-
|
|
6417
|
-
return false;
|
|
6372
|
+
return true;
|
|
6418
6373
|
}
|
|
6419
6374
|
|
|
6420
|
-
function
|
|
6375
|
+
function __termsEqual(a, b, exactDecimal) {
|
|
6421
6376
|
if (a === b) return true;
|
|
6422
6377
|
if (!a || !b) return false;
|
|
6423
6378
|
if (a.__tid && b.__tid && a.__tid === b.__tid) return true;
|
|
6424
6379
|
|
|
6425
6380
|
// rdf:nil is equivalent to the empty list ()
|
|
6426
|
-
if (a
|
|
6427
|
-
if (b instanceof Iri && b.value === RDF_NIL_IRI && a instanceof ListTerm && a.elems.length === 0) return true;
|
|
6381
|
+
if (__isRdfNilEmptyListPair(a, b) || __isRdfNilEmptyListPair(b, a)) return true;
|
|
6428
6382
|
if (a.constructor !== b.constructor) return false;
|
|
6429
6383
|
|
|
6430
6384
|
if (a instanceof Iri) return a.value === b.value;
|
|
6431
|
-
|
|
6432
|
-
if (a instanceof Literal) {
|
|
6433
|
-
if (a.value === b.value) return true;
|
|
6434
|
-
|
|
6435
|
-
// Plain "abc" == "abc"^^xsd:string (but not language-tagged)
|
|
6436
|
-
if (literalsEquivalentAsXsdString(a.value, b.value)) return true;
|
|
6437
|
-
|
|
6438
|
-
// Numeric equality ONLY when datatypes agree (no integer<->decimal here)
|
|
6439
|
-
const ai = parseNumericLiteralInfo(a);
|
|
6440
|
-
const bi = parseNumericLiteralInfo(b);
|
|
6441
|
-
if (ai && bi && ai.dt === bi.dt) {
|
|
6442
|
-
// integer: exact bigint
|
|
6443
|
-
if (ai.kind === 'bigint' && bi.kind === 'bigint') return ai.value === bi.value;
|
|
6444
|
-
|
|
6445
|
-
// decimal: compare exactly via num/scale if possible
|
|
6446
|
-
if (ai.dt === XSD_NS + 'decimal') {
|
|
6447
|
-
const da = parseXsdDecimalToBigIntScale(ai.lexStr);
|
|
6448
|
-
const db = parseXsdDecimalToBigIntScale(bi.lexStr);
|
|
6449
|
-
if (da && db) {
|
|
6450
|
-
const scale = Math.max(da.scale, db.scale);
|
|
6451
|
-
const na = da.num * pow10n(scale - da.scale);
|
|
6452
|
-
const nb = db.num * pow10n(scale - db.scale);
|
|
6453
|
-
return na === nb;
|
|
6454
|
-
}
|
|
6455
|
-
}
|
|
6456
|
-
|
|
6457
|
-
// double/float-ish: JS number (same as your normal same-dt path)
|
|
6458
|
-
const an = ai.kind === 'bigint' ? Number(ai.value) : ai.value;
|
|
6459
|
-
const bn = bi.kind === 'bigint' ? Number(bi.value) : bi.value;
|
|
6460
|
-
return !Number.isNaN(an) && !Number.isNaN(bn) && an === bn;
|
|
6461
|
-
}
|
|
6462
|
-
|
|
6463
|
-
return false;
|
|
6464
|
-
}
|
|
6465
|
-
|
|
6385
|
+
if (a instanceof Literal) return __literalsEqual(a, b, exactDecimal);
|
|
6466
6386
|
if (a instanceof Var) return a.name === b.name;
|
|
6467
6387
|
if (a instanceof Blank) return a.label === b.label;
|
|
6388
|
+
if (a instanceof ListTerm) return __termArraysEqual(a.elems, b.elems, (x, y) => __termsEqual(x, y, exactDecimal));
|
|
6389
|
+
if (a instanceof OpenListTerm)
|
|
6390
|
+
return a.tailVar === b.tailVar && __termArraysEqual(a.prefix, b.prefix, (x, y) => __termsEqual(x, y, exactDecimal));
|
|
6391
|
+
if (a instanceof GraphTerm) return alphaEqGraphTriples(a.triples, b.triples);
|
|
6392
|
+
return false;
|
|
6393
|
+
}
|
|
6468
6394
|
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
}
|
|
6474
|
-
return true;
|
|
6475
|
-
}
|
|
6476
|
-
|
|
6477
|
-
if (a instanceof OpenListTerm) {
|
|
6478
|
-
if (a.tailVar !== b.tailVar) return false;
|
|
6479
|
-
if (a.prefix.length !== b.prefix.length) return false;
|
|
6480
|
-
for (let i = 0; i < a.prefix.length; i++) {
|
|
6481
|
-
if (!termsEqualNoIntDecimal(a.prefix[i], b.prefix[i])) return false;
|
|
6482
|
-
}
|
|
6483
|
-
return true;
|
|
6484
|
-
}
|
|
6485
|
-
|
|
6486
|
-
if (a instanceof GraphTerm) {
|
|
6487
|
-
return alphaEqGraphTriples(a.triples, b.triples);
|
|
6488
|
-
}
|
|
6395
|
+
function termsEqual(a, b) {
|
|
6396
|
+
// Keep in sync with unifyTerm(): numeric-value equality, datatype-aware.
|
|
6397
|
+
return __termsEqual(a, b, false);
|
|
6398
|
+
}
|
|
6489
6399
|
|
|
6490
|
-
|
|
6400
|
+
function termsEqualNoIntDecimal(a, b) {
|
|
6401
|
+
// Numeric equality ONLY when datatypes agree; decimals are compared exactly.
|
|
6402
|
+
return __termsEqual(a, b, true);
|
|
6491
6403
|
}
|
|
6492
6404
|
|
|
6493
6405
|
function triplesEqual(a, b) {
|
|
@@ -6832,81 +6744,12 @@ function tripleFastKey(tr) {
|
|
|
6832
6744
|
}
|
|
6833
6745
|
|
|
6834
6746
|
function ensureFactIndexes(facts) {
|
|
6835
|
-
if (
|
|
6836
|
-
facts.__byPred &&
|
|
6837
|
-
facts.__byPS &&
|
|
6838
|
-
facts.__byPO &&
|
|
6839
|
-
facts.__byPNonFastS &&
|
|
6840
|
-
facts.__byPNonFastO &&
|
|
6841
|
-
facts.__varPred &&
|
|
6842
|
-
facts.__varPredPS &&
|
|
6843
|
-
facts.__varPredPO &&
|
|
6844
|
-
facts.__varPredNonFastS &&
|
|
6845
|
-
facts.__varPredNonFastO &&
|
|
6846
|
-
facts.__keySet
|
|
6847
|
-
)
|
|
6848
|
-
return;
|
|
6747
|
+
if (FACT_INDEX_REQUIRED_FIELDS.every((name) => facts[name])) return;
|
|
6849
6748
|
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
});
|
|
6855
|
-
Object.defineProperty(facts, '__byPS', {
|
|
6856
|
-
value: new Map(),
|
|
6857
|
-
enumerable: false,
|
|
6858
|
-
writable: true,
|
|
6859
|
-
});
|
|
6860
|
-
Object.defineProperty(facts, '__byPO', {
|
|
6861
|
-
value: new Map(),
|
|
6862
|
-
enumerable: false,
|
|
6863
|
-
writable: true,
|
|
6864
|
-
});
|
|
6865
|
-
Object.defineProperty(facts, '__byPNonFastS', {
|
|
6866
|
-
value: new Map(),
|
|
6867
|
-
enumerable: false,
|
|
6868
|
-
writable: true,
|
|
6869
|
-
});
|
|
6870
|
-
Object.defineProperty(facts, '__byPNonFastO', {
|
|
6871
|
-
value: new Map(),
|
|
6872
|
-
enumerable: false,
|
|
6873
|
-
writable: true,
|
|
6874
|
-
});
|
|
6875
|
-
Object.defineProperty(facts, '__varPred', {
|
|
6876
|
-
value: [],
|
|
6877
|
-
enumerable: false,
|
|
6878
|
-
writable: true,
|
|
6879
|
-
});
|
|
6880
|
-
Object.defineProperty(facts, '__varPredPS', {
|
|
6881
|
-
value: new Map(),
|
|
6882
|
-
enumerable: false,
|
|
6883
|
-
writable: true,
|
|
6884
|
-
});
|
|
6885
|
-
Object.defineProperty(facts, '__varPredPO', {
|
|
6886
|
-
value: new Map(),
|
|
6887
|
-
enumerable: false,
|
|
6888
|
-
writable: true,
|
|
6889
|
-
});
|
|
6890
|
-
Object.defineProperty(facts, '__varPredNonFastS', {
|
|
6891
|
-
value: [],
|
|
6892
|
-
enumerable: false,
|
|
6893
|
-
writable: true,
|
|
6894
|
-
});
|
|
6895
|
-
Object.defineProperty(facts, '__varPredNonFastO', {
|
|
6896
|
-
value: [],
|
|
6897
|
-
enumerable: false,
|
|
6898
|
-
writable: true,
|
|
6899
|
-
});
|
|
6900
|
-
Object.defineProperty(facts, '__keySet', {
|
|
6901
|
-
value: new Set(),
|
|
6902
|
-
enumerable: false,
|
|
6903
|
-
writable: true,
|
|
6904
|
-
});
|
|
6905
|
-
Object.defineProperty(facts, '__keySetComplete', {
|
|
6906
|
-
value: false,
|
|
6907
|
-
enumerable: false,
|
|
6908
|
-
writable: true,
|
|
6909
|
-
});
|
|
6749
|
+
for (const name of FACT_INDEX_MAP_FIELDS) __defineHiddenWritable(facts, name, new Map());
|
|
6750
|
+
for (const name of FACT_INDEX_ARRAY_FIELDS) __defineHiddenWritable(facts, name, []);
|
|
6751
|
+
__defineHiddenWritable(facts, '__keySet', new Set());
|
|
6752
|
+
__defineHiddenWritable(facts, '__keySetComplete', false);
|
|
6910
6753
|
|
|
6911
6754
|
// Build lookup indexes eagerly, but do not populate the duplicate-detection
|
|
6912
6755
|
// string Set for every input fact. The predicate/subject/object indexes are
|
|
@@ -6934,45 +6777,14 @@ function cloneFactIndexesForSnapshot(src, dest) {
|
|
|
6934
6777
|
return out;
|
|
6935
6778
|
}
|
|
6936
6779
|
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
enumerable: false,
|
|
6943
|
-
writable: true,
|
|
6944
|
-
});
|
|
6945
|
-
Object.defineProperty(dest, '__byPNonFastO', {
|
|
6946
|
-
value: cloneArrayMap(src.__byPNonFastO),
|
|
6947
|
-
enumerable: false,
|
|
6948
|
-
writable: true,
|
|
6949
|
-
});
|
|
6950
|
-
Object.defineProperty(dest, '__varPred', { value: src.__varPred.slice(), enumerable: false, writable: true });
|
|
6951
|
-
Object.defineProperty(dest, '__varPredPS', {
|
|
6952
|
-
value: cloneArrayMap(src.__varPredPS),
|
|
6953
|
-
enumerable: false,
|
|
6954
|
-
writable: true,
|
|
6955
|
-
});
|
|
6956
|
-
Object.defineProperty(dest, '__varPredPO', {
|
|
6957
|
-
value: cloneArrayMap(src.__varPredPO),
|
|
6958
|
-
enumerable: false,
|
|
6959
|
-
writable: true,
|
|
6960
|
-
});
|
|
6961
|
-
Object.defineProperty(dest, '__varPredNonFastS', {
|
|
6962
|
-
value: src.__varPredNonFastS.slice(),
|
|
6963
|
-
enumerable: false,
|
|
6964
|
-
writable: true,
|
|
6965
|
-
});
|
|
6966
|
-
Object.defineProperty(dest, '__varPredNonFastO', {
|
|
6967
|
-
value: src.__varPredNonFastO.slice(),
|
|
6968
|
-
enumerable: false,
|
|
6969
|
-
writable: true,
|
|
6970
|
-
});
|
|
6971
|
-
Object.defineProperty(dest, '__keySet', { value: new Set(src.__keySet), enumerable: false, writable: true });
|
|
6972
|
-
Object.defineProperty(dest, '__keySetComplete', { value: !!src.__keySetComplete, enumerable: false, writable: true });
|
|
6780
|
+
for (const name of FACT_INDEX_ARRAY_MAP_FIELDS) __defineHiddenWritable(dest, name, cloneArrayMap(src[name]));
|
|
6781
|
+
for (const name of FACT_INDEX_NESTED_ARRAY_MAP_FIELDS) __defineHiddenWritable(dest, name, cloneNestedArrayMap(src[name]));
|
|
6782
|
+
for (const name of FACT_INDEX_ARRAY_FIELDS) __defineHiddenWritable(dest, name, src[name].slice());
|
|
6783
|
+
__defineHiddenWritable(dest, '__keySet', new Set(src.__keySet));
|
|
6784
|
+
__defineHiddenWritable(dest, '__keySetComplete', !!src.__keySetComplete);
|
|
6973
6785
|
}
|
|
6974
6786
|
|
|
6975
|
-
function
|
|
6787
|
+
function pushMapArray(map, key, value) {
|
|
6976
6788
|
let bucket = map.get(key);
|
|
6977
6789
|
if (!bucket) {
|
|
6978
6790
|
bucket = [];
|
|
@@ -6981,6 +6793,15 @@ function addToIndexArrayMap(map, key, value) {
|
|
|
6981
6793
|
bucket.push(value);
|
|
6982
6794
|
}
|
|
6983
6795
|
|
|
6796
|
+
function getOrCreateMap(map, key) {
|
|
6797
|
+
let inner = map.get(key);
|
|
6798
|
+
if (!inner) {
|
|
6799
|
+
inner = new Map();
|
|
6800
|
+
map.set(key, inner);
|
|
6801
|
+
}
|
|
6802
|
+
return inner;
|
|
6803
|
+
}
|
|
6804
|
+
|
|
6984
6805
|
function indexFact(facts, tr, idx, addKeySet = true) {
|
|
6985
6806
|
const sk = termLookupKey(tr.s);
|
|
6986
6807
|
const ok = termLookupKey(tr.o);
|
|
@@ -6991,45 +6812,30 @@ function indexFact(facts, tr, idx, addKeySet = true) {
|
|
|
6991
6812
|
const pk = tr.p.__tid;
|
|
6992
6813
|
pkForKey = pk;
|
|
6993
6814
|
|
|
6994
|
-
|
|
6995
|
-
if (!pb) {
|
|
6996
|
-
pb = [];
|
|
6997
|
-
facts.__byPred.set(pk, pb);
|
|
6998
|
-
}
|
|
6999
|
-
pb.push(idx);
|
|
6815
|
+
pushMapArray(facts.__byPred, pk, idx);
|
|
7000
6816
|
|
|
7001
6817
|
if (sk !== null) {
|
|
7002
|
-
|
|
7003
|
-
if (!ps) {
|
|
7004
|
-
ps = new Map();
|
|
7005
|
-
facts.__byPS.set(pk, ps);
|
|
7006
|
-
}
|
|
7007
|
-
addToIndexArrayMap(ps, sk, idx);
|
|
6818
|
+
pushMapArray(getOrCreateMap(facts.__byPS, pk), sk, idx);
|
|
7008
6819
|
} else {
|
|
7009
|
-
|
|
6820
|
+
pushMapArray(facts.__byPNonFastS, pk, idx);
|
|
7010
6821
|
}
|
|
7011
6822
|
|
|
7012
6823
|
if (ok !== null) {
|
|
7013
|
-
|
|
7014
|
-
if (!po) {
|
|
7015
|
-
po = new Map();
|
|
7016
|
-
facts.__byPO.set(pk, po);
|
|
7017
|
-
}
|
|
7018
|
-
addToIndexArrayMap(po, ok, idx);
|
|
6824
|
+
pushMapArray(getOrCreateMap(facts.__byPO, pk), ok, idx);
|
|
7019
6825
|
} else {
|
|
7020
|
-
|
|
6826
|
+
pushMapArray(facts.__byPNonFastO, pk, idx);
|
|
7021
6827
|
}
|
|
7022
6828
|
} else if (tr.p instanceof Var) {
|
|
7023
6829
|
facts.__varPred.push(idx);
|
|
7024
6830
|
|
|
7025
6831
|
if (sk !== null) {
|
|
7026
|
-
|
|
6832
|
+
pushMapArray(facts.__varPredPS, sk, idx);
|
|
7027
6833
|
} else {
|
|
7028
6834
|
facts.__varPredNonFastS.push(idx);
|
|
7029
6835
|
}
|
|
7030
6836
|
|
|
7031
6837
|
if (ok !== null) {
|
|
7032
|
-
|
|
6838
|
+
pushMapArray(facts.__varPredPO, ok, idx);
|
|
7033
6839
|
} else {
|
|
7034
6840
|
facts.__varPredNonFastO.push(idx);
|
|
7035
6841
|
}
|
|
@@ -7183,16 +6989,8 @@ function makeDerivedRecord(fact, rule, premises, subst, captureExplanations) {
|
|
|
7183
6989
|
function ensureBackRuleIndexes(backRules) {
|
|
7184
6990
|
if (backRules.__byHeadPred && backRules.__wildHeadPred) return;
|
|
7185
6991
|
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
enumerable: false,
|
|
7189
|
-
writable: true,
|
|
7190
|
-
});
|
|
7191
|
-
Object.defineProperty(backRules, '__wildHeadPred', {
|
|
7192
|
-
value: [],
|
|
7193
|
-
enumerable: false,
|
|
7194
|
-
writable: true,
|
|
7195
|
-
});
|
|
6992
|
+
__defineHiddenWritable(backRules, '__byHeadPred', new Map());
|
|
6993
|
+
__defineHiddenWritable(backRules, '__wildHeadPred', []);
|
|
7196
6994
|
|
|
7197
6995
|
for (const r of backRules) indexBackRule(backRules, r);
|
|
7198
6996
|
}
|
|
@@ -7201,13 +6999,7 @@ function indexBackRule(backRules, r) {
|
|
|
7201
6999
|
if (!r || !r.conclusion || r.conclusion.length !== 1) return;
|
|
7202
7000
|
const head = r.conclusion[0];
|
|
7203
7001
|
if (head && head.p instanceof Iri) {
|
|
7204
|
-
|
|
7205
|
-
let bucket = backRules.__byHeadPred.get(k);
|
|
7206
|
-
if (!bucket) {
|
|
7207
|
-
bucket = [];
|
|
7208
|
-
backRules.__byHeadPred.set(k, bucket);
|
|
7209
|
-
}
|
|
7210
|
-
bucket.push(r);
|
|
7002
|
+
pushMapArray(backRules.__byHeadPred, head.p.__tid, r);
|
|
7211
7003
|
} else {
|
|
7212
7004
|
backRules.__wildHeadPred.push(r);
|
|
7213
7005
|
}
|
|
@@ -7242,12 +7034,11 @@ function isSinglePremiseAgendaRuleSafe(r, backRules) {
|
|
|
7242
7034
|
return backRules.__wildHeadPred.length === 0;
|
|
7243
7035
|
}
|
|
7244
7036
|
|
|
7245
|
-
function mergeSinglePremiseAgendaBuckets() {
|
|
7037
|
+
function mergeSinglePremiseAgendaBuckets(...buckets) {
|
|
7246
7038
|
let out = null;
|
|
7247
7039
|
let seen = null;
|
|
7248
7040
|
|
|
7249
|
-
for (
|
|
7250
|
-
const bucket = arguments[i];
|
|
7041
|
+
for (const bucket of buckets) {
|
|
7251
7042
|
if (!bucket || bucket.length === 0) continue;
|
|
7252
7043
|
|
|
7253
7044
|
if (out === null) {
|
|
@@ -7257,8 +7048,7 @@ function mergeSinglePremiseAgendaBuckets() {
|
|
|
7257
7048
|
}
|
|
7258
7049
|
|
|
7259
7050
|
if (!seen) seen = new Set(out);
|
|
7260
|
-
for (
|
|
7261
|
-
const entry = bucket[j];
|
|
7051
|
+
for (const entry of bucket) {
|
|
7262
7052
|
if (seen.has(entry)) continue;
|
|
7263
7053
|
seen.add(entry);
|
|
7264
7054
|
out.push(entry);
|
|
@@ -7268,18 +7058,6 @@ function mergeSinglePremiseAgendaBuckets() {
|
|
|
7268
7058
|
return out;
|
|
7269
7059
|
}
|
|
7270
7060
|
|
|
7271
|
-
function termContainsVarForAgenda(t) {
|
|
7272
|
-
if (t instanceof Var) return true;
|
|
7273
|
-
if (t instanceof ListTerm) return t.elems.some(termContainsVarForAgenda);
|
|
7274
|
-
if (t instanceof OpenListTerm) return true;
|
|
7275
|
-
if (t instanceof GraphTerm)
|
|
7276
|
-
return t.triples.some(
|
|
7277
|
-
(tr) =>
|
|
7278
|
-
termContainsVarForAgenda(tr.s) || termContainsVarForAgenda(tr.p) || termContainsVarForAgenda(tr.o),
|
|
7279
|
-
);
|
|
7280
|
-
return false;
|
|
7281
|
-
}
|
|
7282
|
-
|
|
7283
7061
|
function makeSinglePremiseAgendaIndex(forwardRules, backRules) {
|
|
7284
7062
|
const index = {
|
|
7285
7063
|
byPred: new Map(),
|
|
@@ -7294,15 +7072,6 @@ function makeSinglePremiseAgendaIndex(forwardRules, backRules) {
|
|
|
7294
7072
|
size: 0,
|
|
7295
7073
|
};
|
|
7296
7074
|
|
|
7297
|
-
function addToMapArray(m, k, v) {
|
|
7298
|
-
let bucket = m.get(k);
|
|
7299
|
-
if (!bucket) {
|
|
7300
|
-
bucket = [];
|
|
7301
|
-
m.set(k, bucket);
|
|
7302
|
-
}
|
|
7303
|
-
bucket.push(v);
|
|
7304
|
-
}
|
|
7305
|
-
|
|
7306
7075
|
for (let i = 0; i < forwardRules.length; i++) {
|
|
7307
7076
|
const r = forwardRules[i];
|
|
7308
7077
|
if (!isSinglePremiseAgendaRuleSafe(r, backRules)) continue;
|
|
@@ -7328,29 +7097,15 @@ function makeSinglePremiseAgendaIndex(forwardRules, backRules) {
|
|
|
7328
7097
|
index.size += 1;
|
|
7329
7098
|
|
|
7330
7099
|
if (entry.goalPredTid !== null) {
|
|
7331
|
-
|
|
7100
|
+
pushMapArray(index.byPredAll, entry.goalPredTid, entry);
|
|
7332
7101
|
index.allIriPred.push(entry);
|
|
7333
|
-
if (entry.goalSKey === null && entry.goalOKey === null)
|
|
7334
|
-
if (entry.goalSKey !== null)
|
|
7335
|
-
|
|
7336
|
-
if (!ps) {
|
|
7337
|
-
ps = new Map();
|
|
7338
|
-
index.byPS.set(entry.goalPredTid, ps);
|
|
7339
|
-
}
|
|
7340
|
-
addToMapArray(ps, entry.goalSKey, entry);
|
|
7341
|
-
}
|
|
7342
|
-
if (entry.goalOKey !== null) {
|
|
7343
|
-
let po = index.byPO.get(entry.goalPredTid);
|
|
7344
|
-
if (!po) {
|
|
7345
|
-
po = new Map();
|
|
7346
|
-
index.byPO.set(entry.goalPredTid, po);
|
|
7347
|
-
}
|
|
7348
|
-
addToMapArray(po, entry.goalOKey, entry);
|
|
7349
|
-
}
|
|
7102
|
+
if (entry.goalSKey === null && entry.goalOKey === null) pushMapArray(index.byPred, entry.goalPredTid, entry);
|
|
7103
|
+
if (entry.goalSKey !== null) pushMapArray(getOrCreateMap(index.byPS, entry.goalPredTid), entry.goalSKey, entry);
|
|
7104
|
+
if (entry.goalOKey !== null) pushMapArray(getOrCreateMap(index.byPO, entry.goalPredTid), entry.goalOKey, entry);
|
|
7350
7105
|
} else {
|
|
7351
7106
|
if (entry.goalSKey === null && entry.goalOKey === null) index.wildPred.push(entry);
|
|
7352
|
-
if (entry.goalSKey !== null)
|
|
7353
|
-
if (entry.goalOKey !== null)
|
|
7107
|
+
if (entry.goalSKey !== null) pushMapArray(index.wildPS, entry.goalSKey, entry);
|
|
7108
|
+
if (entry.goalOKey !== null) pushMapArray(index.wildPO, entry.goalOKey, entry);
|
|
7354
7109
|
}
|
|
7355
7110
|
}
|
|
7356
7111
|
|
|
@@ -7366,7 +7121,7 @@ function getSinglePremiseAgendaCandidates(index, fact) {
|
|
|
7366
7121
|
let exact = null;
|
|
7367
7122
|
if (fact.p instanceof Iri) {
|
|
7368
7123
|
const pk = fact.p.__tid;
|
|
7369
|
-
if ((sk === null &&
|
|
7124
|
+
if ((sk === null && containsVarTerm(fact.s)) || (ok === null && containsVarTerm(fact.o))) {
|
|
7370
7125
|
// A fact with a variable-bearing subject/object (most importantly a
|
|
7371
7126
|
// top-level variable fact such as `?S :p ?O.`) can match rules whose
|
|
7372
7127
|
// premise is fixed in that position. The ordinary `(p,s)` / `(p,o)` lookup
|
|
@@ -7411,11 +7166,11 @@ function getSinglePremiseAgendaCandidates(index, fact) {
|
|
|
7411
7166
|
// ===========================================================================
|
|
7412
7167
|
|
|
7413
7168
|
function isLogImplies(p) {
|
|
7414
|
-
return p instanceof Iri && p.value ===
|
|
7169
|
+
return p instanceof Iri && p.value === LOG_IMPLIES_IRI;
|
|
7415
7170
|
}
|
|
7416
7171
|
|
|
7417
7172
|
function isLogImpliedBy(p) {
|
|
7418
|
-
return p instanceof Iri && p.value ===
|
|
7173
|
+
return p instanceof Iri && p.value === LOG_IMPLIED_BY_IRI;
|
|
7419
7174
|
}
|
|
7420
7175
|
|
|
7421
7176
|
// ===========================================================================
|
|
@@ -7448,16 +7203,7 @@ function __makeGoalTable() {
|
|
|
7448
7203
|
|
|
7449
7204
|
function __attachGoalTable(scopeCarrier, goalTable) {
|
|
7450
7205
|
if (!scopeCarrier) return goalTable;
|
|
7451
|
-
|
|
7452
|
-
Object.defineProperty(scopeCarrier, 'goalTable', {
|
|
7453
|
-
value: goalTable,
|
|
7454
|
-
enumerable: false,
|
|
7455
|
-
writable: true,
|
|
7456
|
-
configurable: true,
|
|
7457
|
-
});
|
|
7458
|
-
} else {
|
|
7459
|
-
scopeCarrier.goalTable = goalTable;
|
|
7460
|
-
}
|
|
7206
|
+
__setHiddenWritable(scopeCarrier, 'goalTable', goalTable);
|
|
7461
7207
|
return goalTable;
|
|
7462
7208
|
}
|
|
7463
7209
|
|
|
@@ -7512,11 +7258,10 @@ function __canStoreGoalMemo(visited, maxResults) {
|
|
|
7512
7258
|
// Unification + substitution
|
|
7513
7259
|
// ===========================================================================
|
|
7514
7260
|
|
|
7515
|
-
function containsVarTerm(t, v) {
|
|
7516
|
-
if (t instanceof
|
|
7517
|
-
if (t instanceof Var) return t.name === v;
|
|
7261
|
+
function containsVarTerm(t, v = null) {
|
|
7262
|
+
if (t instanceof Var) return v === null || t.name === v;
|
|
7518
7263
|
if (t instanceof ListTerm) return t.elems.some((e) => containsVarTerm(e, v));
|
|
7519
|
-
if (t instanceof OpenListTerm) return t.prefix.some((e) => containsVarTerm(e, v)) || t.tailVar === v;
|
|
7264
|
+
if (t instanceof OpenListTerm) return t.prefix.some((e) => containsVarTerm(e, v)) || v === null || t.tailVar === v;
|
|
7520
7265
|
if (t instanceof GraphTerm)
|
|
7521
7266
|
return t.triples.some((tr) => containsVarTerm(tr.s, v) || containsVarTerm(tr.p, v) || containsVarTerm(tr.o, v));
|
|
7522
7267
|
return false;
|
|
@@ -7721,16 +7466,8 @@ function unifyOpenWithList(prefix, tailv, ys, subst) {
|
|
|
7721
7466
|
}
|
|
7722
7467
|
|
|
7723
7468
|
function graphTriplesContainVars(triples) {
|
|
7724
|
-
function termHasVar(t) {
|
|
7725
|
-
if (t instanceof Var) return true;
|
|
7726
|
-
if (t instanceof ListTerm) return t.elems.some(termHasVar);
|
|
7727
|
-
if (t instanceof OpenListTerm) return t.prefix.some(termHasVar) || true;
|
|
7728
|
-
if (t instanceof GraphTerm) return t.triples.some((tr) => termHasVar(tr.s) || termHasVar(tr.p) || termHasVar(tr.o));
|
|
7729
|
-
return false;
|
|
7730
|
-
}
|
|
7731
|
-
|
|
7732
7469
|
for (const tr of triples) {
|
|
7733
|
-
if (
|
|
7470
|
+
if (containsVarTerm(tr.s) || containsVarTerm(tr.p) || containsVarTerm(tr.o)) return true;
|
|
7734
7471
|
}
|
|
7735
7472
|
return false;
|
|
7736
7473
|
}
|
|
@@ -8015,19 +7752,7 @@ function __tripleHasVarOrBlank(tr) {
|
|
|
8015
7752
|
}
|
|
8016
7753
|
|
|
8017
7754
|
function __builtinIsSatisfiableWhenFullyUnbound(pIriVal) {
|
|
8018
|
-
return (
|
|
8019
|
-
pIriVal === MATH_NS + 'sin' ||
|
|
8020
|
-
pIriVal === MATH_NS + 'cos' ||
|
|
8021
|
-
pIriVal === MATH_NS + 'tan' ||
|
|
8022
|
-
pIriVal === MATH_NS + 'asin' ||
|
|
8023
|
-
pIriVal === MATH_NS + 'acos' ||
|
|
8024
|
-
pIriVal === MATH_NS + 'atan' ||
|
|
8025
|
-
pIriVal === MATH_NS + 'sinh' ||
|
|
8026
|
-
pIriVal === MATH_NS + 'cosh' ||
|
|
8027
|
-
pIriVal === MATH_NS + 'tanh' ||
|
|
8028
|
-
pIriVal === MATH_NS + 'degrees' ||
|
|
8029
|
-
pIriVal === MATH_NS + 'negation'
|
|
8030
|
-
);
|
|
7755
|
+
return MATH_BUILTINS_SATISFIABLE_WHEN_FULLY_UNBOUND.has(pIriVal);
|
|
8031
7756
|
}
|
|
8032
7757
|
|
|
8033
7758
|
function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxResults, opts) {
|
|
@@ -8662,12 +8387,7 @@ function __proofTripleKey(tr) {
|
|
|
8662
8387
|
|
|
8663
8388
|
function __copyProofSource(from, to) {
|
|
8664
8389
|
if (from && to && Object.prototype.hasOwnProperty.call(from, '__source')) {
|
|
8665
|
-
|
|
8666
|
-
value: from.__source,
|
|
8667
|
-
enumerable: false,
|
|
8668
|
-
writable: false,
|
|
8669
|
-
configurable: true,
|
|
8670
|
-
});
|
|
8390
|
+
__defineHiddenValue(to, '__source', from.__source);
|
|
8671
8391
|
}
|
|
8672
8392
|
return to;
|
|
8673
8393
|
}
|
|
@@ -8679,12 +8399,7 @@ function __annotateProofVarSourceNames(rule) {
|
|
|
8679
8399
|
const m = /^(.*)__\d+$/.exec(name);
|
|
8680
8400
|
sourceNames[name] = m ? m[1] : name;
|
|
8681
8401
|
}
|
|
8682
|
-
|
|
8683
|
-
value: sourceNames,
|
|
8684
|
-
enumerable: false,
|
|
8685
|
-
writable: false,
|
|
8686
|
-
configurable: true,
|
|
8687
|
-
});
|
|
8402
|
+
__defineHiddenValue(rule, '__proofVarSourceNames', sourceNames);
|
|
8688
8403
|
return rule;
|
|
8689
8404
|
}
|
|
8690
8405
|
|
|
@@ -8890,45 +8605,16 @@ function forwardChain(facts, forwardRules, backRules, onDerived /* optional */,
|
|
|
8890
8605
|
// until a scoped snapshot exists (or a given closure level is reached).
|
|
8891
8606
|
// Helper functions are module-scoped: __computeForwardRuleScopedSkipInfo, etc.
|
|
8892
8607
|
function setScopedSnapshot(snap, level) {
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
value: snap,
|
|
8896
|
-
enumerable: false,
|
|
8897
|
-
writable: true,
|
|
8898
|
-
configurable: true,
|
|
8899
|
-
});
|
|
8900
|
-
} else {
|
|
8901
|
-
facts.__scopedSnapshot = snap;
|
|
8902
|
-
}
|
|
8903
|
-
|
|
8904
|
-
if (!hasOwn.call(facts, '__scopedClosureLevel')) {
|
|
8905
|
-
Object.defineProperty(facts, '__scopedClosureLevel', {
|
|
8906
|
-
value: level,
|
|
8907
|
-
enumerable: false,
|
|
8908
|
-
writable: true,
|
|
8909
|
-
configurable: true,
|
|
8910
|
-
});
|
|
8911
|
-
} else {
|
|
8912
|
-
facts.__scopedClosureLevel = level;
|
|
8913
|
-
}
|
|
8608
|
+
__setHiddenWritable(facts, '__scopedSnapshot', snap);
|
|
8609
|
+
__setHiddenWritable(facts, '__scopedClosureLevel', level);
|
|
8914
8610
|
}
|
|
8915
8611
|
|
|
8916
8612
|
function makeScopedSnapshot() {
|
|
8917
8613
|
const snap = facts.slice();
|
|
8918
8614
|
cloneFactIndexesForSnapshot(facts, snap);
|
|
8919
|
-
|
|
8920
|
-
value: snap,
|
|
8921
|
-
enumerable: false,
|
|
8922
|
-
writable: true,
|
|
8923
|
-
configurable: true,
|
|
8924
|
-
});
|
|
8615
|
+
__defineHiddenWritable(snap, '__scopedSnapshot', snap);
|
|
8925
8616
|
// Propagate closure level so nested scoped builtins can see it.
|
|
8926
|
-
|
|
8927
|
-
value: scopedClosureLevel,
|
|
8928
|
-
enumerable: false,
|
|
8929
|
-
writable: true,
|
|
8930
|
-
configurable: true,
|
|
8931
|
-
});
|
|
8617
|
+
__defineHiddenWritable(snap, '__scopedClosureLevel', scopedClosureLevel);
|
|
8932
8618
|
return snap;
|
|
8933
8619
|
}
|
|
8934
8620
|
|
|
@@ -9276,36 +8962,12 @@ function __withScopedSnapshotForQueries(facts, fn) {
|
|
|
9276
8962
|
// Create a frozen snapshot of the saturated closure.
|
|
9277
8963
|
const snap = facts.slice();
|
|
9278
8964
|
ensureFactIndexes(snap);
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
enumerable: false,
|
|
9282
|
-
writable: true,
|
|
9283
|
-
configurable: true,
|
|
9284
|
-
});
|
|
9285
|
-
Object.defineProperty(snap, '__scopedClosureLevel', {
|
|
9286
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
9287
|
-
enumerable: false,
|
|
9288
|
-
writable: true,
|
|
9289
|
-
configurable: true,
|
|
9290
|
-
});
|
|
8965
|
+
__defineHiddenWritable(snap, '__scopedSnapshot', snap);
|
|
8966
|
+
__defineHiddenWritable(snap, '__scopedClosureLevel', Number.MAX_SAFE_INTEGER);
|
|
9291
8967
|
|
|
9292
8968
|
// Ensure the live facts array exposes the snapshot/level for builtins.
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
value: null,
|
|
9296
|
-
enumerable: false,
|
|
9297
|
-
writable: true,
|
|
9298
|
-
configurable: true,
|
|
9299
|
-
});
|
|
9300
|
-
}
|
|
9301
|
-
if (!hasOwn.call(facts, '__scopedClosureLevel')) {
|
|
9302
|
-
Object.defineProperty(facts, '__scopedClosureLevel', {
|
|
9303
|
-
value: 0,
|
|
9304
|
-
enumerable: false,
|
|
9305
|
-
writable: true,
|
|
9306
|
-
configurable: true,
|
|
9307
|
-
});
|
|
9308
|
-
}
|
|
8969
|
+
__setHiddenWritable(facts, '__scopedSnapshot', null);
|
|
8970
|
+
__setHiddenWritable(facts, '__scopedClosureLevel', 0);
|
|
9309
8971
|
|
|
9310
8972
|
facts.__scopedSnapshot = snap;
|
|
9311
8973
|
facts.__scopedClosureLevel = Number.MAX_SAFE_INTEGER;
|