eyeling 1.22.14 → 1.22.16
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/HANDBOOK.md +21 -0
- package/dist/browser/eyeling.browser.js +184 -158
- package/examples/barley-seed-becoming.n3 +497 -0
- package/examples/constructor-theory-becoming.n3 +177 -0
- package/examples/control-system-becoming.n3 +203 -0
- package/examples/developmental-genetics-becoming.n3 +204 -0
- package/examples/engineering-becoming.n3 +167 -0
- package/examples/output/barley-seed-becoming.txt +25 -0
- package/examples/output/constructor-theory-becoming.n3 +18 -0
- package/examples/output/control-system-becoming.n3 +35 -0
- package/examples/output/developmental-genetics-becoming.n3 +32 -0
- package/examples/output/engineering-becoming.n3 +26 -0
- package/examples/output/tunnel-junction-wake-switch-becoming.txt +21 -0
- package/examples/output/whitehead-becoming.n3 +42 -0
- package/examples/tunnel-junction-wake-switch-becoming.n3 +216 -0
- package/examples/whitehead-becoming.n3 +155 -0
- package/eyeling.js +184 -159
- package/lib/builtins.js +164 -151
- package/lib/engine.js +20 -7
- package/package.json +1 -1
package/lib/engine.js
CHANGED
|
@@ -76,6 +76,19 @@ const deref = require('./deref');
|
|
|
76
76
|
|
|
77
77
|
const hasOwn = Object.prototype.hasOwnProperty;
|
|
78
78
|
|
|
79
|
+
function __emptySubst() {
|
|
80
|
+
return Object.create(null);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function __cloneSubst(subst) {
|
|
84
|
+
if (!subst) return __emptySubst();
|
|
85
|
+
const out = Object.create(null);
|
|
86
|
+
for (const k in subst) {
|
|
87
|
+
if (hasOwn.call(subst, k)) out[k] = subst[k];
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
79
92
|
let version = 'dev';
|
|
80
93
|
try {
|
|
81
94
|
// Node: keep package.json version if available
|
|
@@ -1287,7 +1300,7 @@ function pushFactIndexed(facts, tr) {
|
|
|
1287
1300
|
|
|
1288
1301
|
function makeDerivedRecord(fact, rule, premises, subst, captureExplanations) {
|
|
1289
1302
|
if (captureExplanations === false) return { fact };
|
|
1290
|
-
return new DerivedFact(fact, rule, premises.slice(),
|
|
1303
|
+
return new DerivedFact(fact, rule, premises.slice(), __cloneSubst(subst));
|
|
1291
1304
|
}
|
|
1292
1305
|
|
|
1293
1306
|
function ensureBackRuleIndexes(backRules) {
|
|
@@ -1878,7 +1891,7 @@ function unifyTermWithOptions(a, b, subst, opts) {
|
|
|
1878
1891
|
const t = b;
|
|
1879
1892
|
if (t instanceof Var && t.name === v) return subst;
|
|
1880
1893
|
if (containsVarTerm(t, v)) return null;
|
|
1881
|
-
const s2 =
|
|
1894
|
+
const s2 = __cloneSubst(subst);
|
|
1882
1895
|
s2[v] = t;
|
|
1883
1896
|
return s2;
|
|
1884
1897
|
}
|
|
@@ -2068,7 +2081,7 @@ function gcCompactForGoals(subst, goals, answerVars) {
|
|
|
2068
2081
|
}
|
|
2069
2082
|
}
|
|
2070
2083
|
|
|
2071
|
-
const out =
|
|
2084
|
+
const out = __emptySubst();
|
|
2072
2085
|
for (const k of Object.keys(subst)) {
|
|
2073
2086
|
if (keep.has(k)) out[k] = subst[k];
|
|
2074
2087
|
}
|
|
@@ -2131,7 +2144,7 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
|
|
|
2131
2144
|
const allowDeferredBuiltins = !!(opts && opts.deferBuiltins);
|
|
2132
2145
|
|
|
2133
2146
|
const initialGoals = Array.isArray(goals) ? goals.slice() : [];
|
|
2134
|
-
const substMut = subst ?
|
|
2147
|
+
const substMut = subst ? __cloneSubst(subst) : {};
|
|
2135
2148
|
const initialVisited = visited ? visited.slice() : [];
|
|
2136
2149
|
|
|
2137
2150
|
// Variables from the original goal list (needed by the caller to instantiate conclusions)
|
|
@@ -2593,7 +2606,7 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
|
|
|
2593
2606
|
const builtinMax = Number.isFinite(remaining) && !restGoals.length ? remaining : undefined;
|
|
2594
2607
|
|
|
2595
2608
|
const builtinGoalForEval = goalPredicateIri === LOG_NS + 'rawType' ? rawGoal : goal0;
|
|
2596
|
-
const builtinSubstForEval = goalPredicateIri === LOG_NS + 'rawType' ? substMut :
|
|
2609
|
+
const builtinSubstForEval = goalPredicateIri === LOG_NS + 'rawType' ? substMut : __emptySubst();
|
|
2597
2610
|
let deltas = evalBuiltin(
|
|
2598
2611
|
builtinGoalForEval,
|
|
2599
2612
|
builtinSubstForEval,
|
|
@@ -2635,7 +2648,7 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen, maxR
|
|
|
2635
2648
|
subjectAndObjectAreFullyUnbound &&
|
|
2636
2649
|
(!restGoals.length || dc >= goalsNow.length)
|
|
2637
2650
|
) {
|
|
2638
|
-
deltas = [
|
|
2651
|
+
deltas = [__emptySubst()];
|
|
2639
2652
|
}
|
|
2640
2653
|
|
|
2641
2654
|
if (deltas.length) {
|
|
@@ -3068,7 +3081,7 @@ function forwardChain(facts, forwardRules, backRules, onDerived /* optional */,
|
|
|
3068
3081
|
const r = entry.rule;
|
|
3069
3082
|
if (__skipForwardRuleNow(r)) continue;
|
|
3070
3083
|
|
|
3071
|
-
const s = unifyTriple(entry.goal, fact,
|
|
3084
|
+
const s = unifyTriple(entry.goal, fact, __emptySubst());
|
|
3072
3085
|
if (s === null) continue;
|
|
3073
3086
|
|
|
3074
3087
|
const outcome = __emitForwardRuleSolution(r, entry.ruleIndex, s);
|