theprogrammablemind 7.5.7 → 7.5.8-beta.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.
- package/client.js +21 -7
- package/package.json +2 -1
- package/src/digraph_internal.js +131 -0
- package/src/helpers.js +4 -3
- package/src/semantics.js +1 -1
package/client.js
CHANGED
@@ -58,10 +58,10 @@ const vimdiff = (actualJSON, expectedJSON) => {
|
|
58
58
|
// console.log(`vimdiff ${path}/actual.json ${path}/expected.json`)
|
59
59
|
{
|
60
60
|
const editor = runtime.process.env.EDITOR || 'vimdiff'
|
61
|
-
|
62
|
-
child.
|
63
|
-
|
64
|
-
})
|
61
|
+
debugger
|
62
|
+
// const child = runtime.child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
|
63
|
+
console.log(`${editor} ${path}/expected.json ${path}/actual.json`)
|
64
|
+
runtime.child_process.execSync(`${editor} ${path}/expected.json ${path}/actual.json`, {stdio: 'inherit'})
|
65
65
|
}
|
66
66
|
}
|
67
67
|
|
@@ -100,10 +100,20 @@ const asList = (context) => {
|
|
100
100
|
}
|
101
101
|
}
|
102
102
|
|
103
|
+
class ErrorReason extends Error {
|
104
|
+
constructor(context) {
|
105
|
+
super(JSON.stringify(context))
|
106
|
+
this.reason = context
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
103
110
|
const setupArgs = (args, config, logs, hierarchy) => {
|
104
111
|
config.setArgs(args)
|
105
|
-
args.calls = new InitCalls()
|
112
|
+
args.calls = new InitCalls(config.name)
|
106
113
|
args.km = (name) => config.getConfig(name)
|
114
|
+
args.error = (context) => {
|
115
|
+
throw new ErrorReason(context)
|
116
|
+
}
|
107
117
|
args.kms = config.getConfigs()
|
108
118
|
args.config = config
|
109
119
|
args.hierarchy = hierarchy
|
@@ -395,7 +405,8 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
395
405
|
const mostCalled = semantics.getMostCalled()
|
396
406
|
e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
|
397
407
|
}
|
398
|
-
|
408
|
+
// contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
|
409
|
+
contextPrime = semantics.apply(args, { marker: 'error', context, reason: e.reason })
|
399
410
|
}
|
400
411
|
}
|
401
412
|
}
|
@@ -1578,7 +1589,7 @@ const knowledgeModule = async ({
|
|
1578
1589
|
runTests(config, test, { debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1579
1590
|
if (results.length > 0 && args.vimdiff) {
|
1580
1591
|
for (const result of results) {
|
1581
|
-
vimdiff(result.
|
1592
|
+
vimdiff(result.actual, result.expected)
|
1582
1593
|
}
|
1583
1594
|
}
|
1584
1595
|
let newError = false
|
@@ -1632,6 +1643,9 @@ const knowledgeModule = async ({
|
|
1632
1643
|
lines.setElement(1, 1, 'actual checked')
|
1633
1644
|
lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
|
1634
1645
|
lines.log()
|
1646
|
+
if (args.vimdiff) {
|
1647
|
+
vimdiff(result.actual.checked, result.expected.checked)
|
1648
|
+
}
|
1635
1649
|
newError = true
|
1636
1650
|
headerShown = true
|
1637
1651
|
}
|
package/package.json
CHANGED
@@ -44,6 +44,7 @@
|
|
44
44
|
"src/config.js",
|
45
45
|
"src/copy.js",
|
46
46
|
"src/digraph.js",
|
47
|
+
"src/digraph_internal.js",
|
47
48
|
"src/generators.js",
|
48
49
|
"src/semantics.js"
|
49
50
|
],
|
@@ -62,6 +63,6 @@
|
|
62
63
|
"json-stable-stringify": "^1.0.1",
|
63
64
|
"node-fetch": "^2.6.1"
|
64
65
|
},
|
65
|
-
"version": "7.5.
|
66
|
+
"version": "7.5.8-beta.0",
|
66
67
|
"license": "ISC"
|
67
68
|
}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
const toA = (edge) => {
|
2
|
+
if (Array.isArray(edge)) {
|
3
|
+
return edge
|
4
|
+
} else {
|
5
|
+
return [edge.child, edge.parent]
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
class DigraphInternal {
|
10
|
+
// edges maybe either [child, parent] or { child, parent }
|
11
|
+
constructor (edges = []) {
|
12
|
+
// dont make a copy of edges. this is shared and that breaks stuff. TODO fix this
|
13
|
+
this._edges = edges
|
14
|
+
}
|
15
|
+
|
16
|
+
addEdges(edges) {
|
17
|
+
for (let edge of edges) {
|
18
|
+
this.addEdge(edge)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
addEdge(edge) {
|
23
|
+
edge = toA(edge)
|
24
|
+
this._edges.push(edge)
|
25
|
+
}
|
26
|
+
|
27
|
+
get edges() {
|
28
|
+
return this._edges
|
29
|
+
}
|
30
|
+
|
31
|
+
set edges(edges) {
|
32
|
+
this._edges = edges
|
33
|
+
}
|
34
|
+
|
35
|
+
/*
|
36
|
+
set edges(edges) {
|
37
|
+
this._edges = edges.map( toA )
|
38
|
+
}
|
39
|
+
*/
|
40
|
+
|
41
|
+
acdcs (s, from, to) {
|
42
|
+
const todo = [s]
|
43
|
+
const seen = new Set([s])
|
44
|
+
const acdcs = new Set([])
|
45
|
+
while (todo.length > 0) {
|
46
|
+
const n = todo.pop()
|
47
|
+
this._edges.forEach((e) => {
|
48
|
+
e = toA(e)
|
49
|
+
if (e[from] === n) {
|
50
|
+
acdcs.add(e[to])
|
51
|
+
if (!seen.has(e[to])) {
|
52
|
+
todo.push(e[to])
|
53
|
+
seen.add(e[to])
|
54
|
+
}
|
55
|
+
}
|
56
|
+
})
|
57
|
+
}
|
58
|
+
return acdcs
|
59
|
+
}
|
60
|
+
|
61
|
+
isA (low, high) {
|
62
|
+
if (low === high) {
|
63
|
+
return true
|
64
|
+
}
|
65
|
+
return this.ancestors(low).has(high)
|
66
|
+
}
|
67
|
+
|
68
|
+
lessThan (low, high) {
|
69
|
+
if (low === high) {
|
70
|
+
return false
|
71
|
+
}
|
72
|
+
return this.ancestors(low).has(high)
|
73
|
+
}
|
74
|
+
|
75
|
+
descendants (s) {
|
76
|
+
return this.acdcs(s, 1, 0)
|
77
|
+
}
|
78
|
+
|
79
|
+
ancestors (s) {
|
80
|
+
return this.acdcs(s, 0, 1)
|
81
|
+
}
|
82
|
+
|
83
|
+
minima (nodes) {
|
84
|
+
let minima = new Set(nodes)
|
85
|
+
const ancestors = new Set([])
|
86
|
+
nodes.forEach((node) => {
|
87
|
+
this.ancestors(node).forEach((n) => ancestors.add(n))
|
88
|
+
})
|
89
|
+
ancestors.forEach((n) => minima.delete(n))
|
90
|
+
if (minima.size === 0) {
|
91
|
+
// all unrelated
|
92
|
+
minima = new Set(nodes)
|
93
|
+
}
|
94
|
+
return minima
|
95
|
+
}
|
96
|
+
|
97
|
+
maxima (nodes) {
|
98
|
+
const maxima = new Set(nodes)
|
99
|
+
const descendants = new Set([])
|
100
|
+
nodes.forEach((node) => {
|
101
|
+
this.descendants(node).forEach((n) => descendants.add(n))
|
102
|
+
})
|
103
|
+
descendants.forEach((n) => maxima.delete(n))
|
104
|
+
return maxima
|
105
|
+
}
|
106
|
+
|
107
|
+
add (child, parent) {
|
108
|
+
this._edges.push([child, parent])
|
109
|
+
}
|
110
|
+
|
111
|
+
addList (l) {
|
112
|
+
for (let i = 1; i < l.length; ++i) {
|
113
|
+
this._edges.push([l[i - 1], l[i]])
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
order (todo) {
|
118
|
+
const ordered = []
|
119
|
+
while (todo.length > 0) {
|
120
|
+
const nodes = this.minima(todo)
|
121
|
+
todo = todo.filter((e) => !nodes.has(e))
|
122
|
+
for (const node of nodes) {
|
123
|
+
ordered.push(node)
|
124
|
+
}
|
125
|
+
// ordered = ordered.concat([...nodes])
|
126
|
+
}
|
127
|
+
return ordered
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
module.exports = DigraphInternal
|
package/src/helpers.js
CHANGED
@@ -172,10 +172,11 @@ nextContextId = 0
|
|
172
172
|
|
173
173
|
class InitCalls {
|
174
174
|
|
175
|
-
constructor() {
|
175
|
+
constructor(name) {
|
176
176
|
this.nextCallId = 0
|
177
177
|
this.nextContextId = 0
|
178
178
|
this.stack = []
|
179
|
+
this.name = name
|
179
180
|
}
|
180
181
|
|
181
182
|
start() {
|
@@ -192,13 +193,13 @@ class InitCalls {
|
|
192
193
|
// this.nextCallId += 1
|
193
194
|
// this.stack.push(this.nextCallId)
|
194
195
|
this.stack.push(this.nextCallId)
|
195
|
-
const calls = this.stack.map( (call) =>
|
196
|
+
const calls = this.stack.map( (call) => `${this.name}#call${call}` )
|
196
197
|
// return `Context#${this.nextContextId}: ${calls}`
|
197
198
|
return `Context#${nextContextId}: ${calls}`
|
198
199
|
}
|
199
200
|
|
200
201
|
current() {
|
201
|
-
return
|
202
|
+
return `${this.name}#call${this.stack[this.stack.length-1]}`
|
202
203
|
}
|
203
204
|
|
204
205
|
touch(context) {
|
package/src/semantics.js
CHANGED
@@ -237,7 +237,7 @@ class Semantics {
|
|
237
237
|
// this.logs.push(message)
|
238
238
|
// return [message]
|
239
239
|
args.calls.pop()
|
240
|
-
throw { error: [message], logs: this.logs }
|
240
|
+
throw { error: [message], logs: this.logs, reason: e.reason }
|
241
241
|
}
|
242
242
|
args.calls.touch(contextPrime)
|
243
243
|
// this.logs.push(`Semantics: applied ${semantic.toString()}\n to\n ${JSON.stringify(context)}\n the result was ${JSON.stringify(contextPrime)}\n`)
|