theprogrammablemind_4wp 7.5.7 → 7.5.8-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +43 -13
- package/package.json +2 -1
- package/src/config.js +4 -2
- 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,23 @@ 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)
|
113
|
+
if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
|
114
|
+
args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
|
115
|
+
}
|
106
116
|
args.km = (name) => config.getConfig(name)
|
117
|
+
args.error = (context) => {
|
118
|
+
throw new ErrorReason(context)
|
119
|
+
}
|
107
120
|
args.kms = config.getConfigs()
|
108
121
|
args.config = config
|
109
122
|
args.hierarchy = hierarchy
|
@@ -139,7 +152,10 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
139
152
|
args.g = (c) => config.getGenerators(logs).apply(args, c)
|
140
153
|
args.gp = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: true, isResponse: false, response: false})
|
141
154
|
args.gr = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: false, isResponse: true })
|
142
|
-
|
155
|
+
if (!logs) {
|
156
|
+
debugger
|
157
|
+
}
|
158
|
+
args.e = (c) => config.getEvaluator(args.s, args.calls, logs, c)
|
143
159
|
args.log = (message) => logs.push(message)
|
144
160
|
// config.getAddedArgs(args)
|
145
161
|
args.gs = gs(args.g)
|
@@ -349,6 +365,9 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
349
365
|
|
350
366
|
const objects = config.get('objects')
|
351
367
|
const args = { objects, isResponse: true, response: json, isTest, getObjects: getObjects(objects) }
|
368
|
+
if (!json.logs) {
|
369
|
+
json.logs = []
|
370
|
+
}
|
352
371
|
setupArgs(args, config, json.logs, hierarchy)
|
353
372
|
const toDo = [...contexts]
|
354
373
|
args.insert = (context) => toDo.unshift(context)
|
@@ -395,7 +414,8 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
395
414
|
const mostCalled = semantics.getMostCalled()
|
396
415
|
e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
|
397
416
|
}
|
398
|
-
|
417
|
+
// contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
|
418
|
+
contextPrime = semantics.apply(args, { marker: 'error', context, reason: e.reason })
|
399
419
|
}
|
400
420
|
}
|
401
421
|
}
|
@@ -846,10 +866,12 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
|
|
846
866
|
const args = {
|
847
867
|
}
|
848
868
|
const saveObjects = {...config.config.objects}
|
869
|
+
/*
|
849
870
|
saveObjects.nameToUUID = {}
|
850
871
|
for (let km of config.configs) {
|
851
872
|
saveObjects.nameToUUID[km.name] = km.uuid
|
852
873
|
}
|
874
|
+
*/
|
853
875
|
writeTest(testFile, test, saveObjects, result.generated, result.paraphrases, result.responses, result.contexts, result.associations, result.metadata, actualConfig, saveDeveloper)
|
854
876
|
}
|
855
877
|
|
@@ -1333,7 +1355,11 @@ const knowledgeModule = async ({
|
|
1333
1355
|
if (config.needsRebuild(template.template, template.instance)) {
|
1334
1356
|
throw `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguements or the -rt argument to rebuild.`
|
1335
1357
|
}
|
1336
|
-
|
1358
|
+
try {
|
1359
|
+
config.load(template.template, template.instance)
|
1360
|
+
} catch( e ) {
|
1361
|
+
errorHandler(e)
|
1362
|
+
}
|
1337
1363
|
}
|
1338
1364
|
}
|
1339
1365
|
if (isProcess) {
|
@@ -1576,11 +1602,6 @@ const knowledgeModule = async ({
|
|
1576
1602
|
|
1577
1603
|
}
|
1578
1604
|
runTests(config, test, { debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1579
|
-
if (results.length > 0 && args.vimdiff) {
|
1580
|
-
for (const result of results) {
|
1581
|
-
vimdiff(result.expected, result.actual)
|
1582
|
-
}
|
1583
|
-
}
|
1584
1605
|
let newError = false
|
1585
1606
|
if (results.length > 0) {
|
1586
1607
|
let headerShown = false
|
@@ -1632,10 +1653,19 @@ const knowledgeModule = async ({
|
|
1632
1653
|
lines.setElement(1, 1, 'actual checked')
|
1633
1654
|
lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
|
1634
1655
|
lines.log()
|
1656
|
+
if (args.vimdiff) {
|
1657
|
+
vimdiff(result.actual.checked, result.expected.checked)
|
1658
|
+
}
|
1635
1659
|
newError = true
|
1636
1660
|
headerShown = true
|
1637
1661
|
}
|
1638
1662
|
}
|
1663
|
+
} else {
|
1664
|
+
if (results.length > 0 && args.vimdiff) {
|
1665
|
+
for (const result of results) {
|
1666
|
+
vimdiff(result.actual, result.expected)
|
1667
|
+
}
|
1668
|
+
}
|
1639
1669
|
}
|
1640
1670
|
if (!headerShown) {
|
1641
1671
|
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
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.1",
|
66
67
|
"license": "ISC"
|
67
68
|
}
|
package/src/config.js
CHANGED
@@ -79,7 +79,8 @@ const handleBridgeProps = (config, bridge) => {
|
|
79
79
|
if (bridge.generatorp) {
|
80
80
|
config.config.generators.unshift({
|
81
81
|
where: bridge.generatorp.where || bridge.where || client.where(4),
|
82
|
-
match: ({context}) => bridge.id == context.marker && context.paraphrase,
|
82
|
+
// match: ({context}) => bridge.id == context.marker && context.paraphrase,
|
83
|
+
match: ({context}) => bridge.id == context.marker && context.level == bridge.level + 1 && context.paraphrase,
|
83
84
|
apply: (args) => bridge.generatorp(args),
|
84
85
|
applyWrapped: bridge.generatorp,
|
85
86
|
property: 'generatorp',
|
@@ -614,8 +615,9 @@ class Config {
|
|
614
615
|
return instance
|
615
616
|
}
|
616
617
|
*/
|
617
|
-
getEvaluator (s, log, context) {
|
618
|
+
getEvaluator (s, calls, log, context) {
|
618
619
|
const instance = s({ ...context, evaluate: true })
|
620
|
+
calls.touch(instance)
|
619
621
|
if (!instance.evalue && !instance.verbatim && !instance.value) {
|
620
622
|
this.warningNotEvaluated(log, context);
|
621
623
|
}
|
@@ -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`)
|