theprogrammablemind_4wp 7.5.6-beta.0 → 7.5.7-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +43 -8
- package/package.json +2 -1
- package/src/config.js +5 -5
- package/src/digraph.js +32 -0
- package/src/digraph_internal.js +131 -0
package/client.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
const { Semantics, Semantic } = require('./src/semantics')
|
2
2
|
const { Generators, Generator } = require('./src/generators')
|
3
|
+
const DigraphInternal = require('./src/digraph_internal')
|
3
4
|
const Digraph = require('./src/digraph')
|
4
5
|
const fetch = require('node-fetch')
|
5
6
|
const base64 = require('base-64')
|
@@ -228,7 +229,7 @@ const processContext = (context, { objects = {}, config, logs = [] }) => {
|
|
228
229
|
const response = {} // NA but passed in
|
229
230
|
// generators = new Generators(generators.map((g) => new Generator(normalizeGenerator(g))))
|
230
231
|
// semantics = new Semantics(semantics.map((g) => new Semantic(normalizeSemantic(g))))
|
231
|
-
const hierarchy = new
|
232
|
+
const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
|
232
233
|
|
233
234
|
const args = { objects, response, getObjects: getObjects(objects) }
|
234
235
|
setupArgs(args, config, logs, hierarchy)
|
@@ -509,7 +510,7 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
|
|
509
510
|
delete data.generators
|
510
511
|
// const semantics = new Semantics((data.semantics || []).map((g) => new Semantic(normalizeSemantic(g))))
|
511
512
|
delete data.semantics
|
512
|
-
const hierarchy = new
|
513
|
+
const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
|
513
514
|
|
514
515
|
return {
|
515
516
|
data,
|
@@ -721,16 +722,40 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
|
|
721
722
|
const failed_contexts = !matching(result.contexts, expected.contexts)
|
722
723
|
const failed_objects = !matching(actual_objects, expected_objects)
|
723
724
|
|
724
|
-
const pickEm = (
|
725
|
+
const pickEm = (getObjects) => {
|
725
726
|
const picked = {}
|
726
727
|
for (let prop of (testConfig.check || [])) {
|
727
|
-
|
728
|
+
if (prop.km) {
|
729
|
+
c = config.getConfig(prop.km)
|
730
|
+
o = getObjects(prop.km)
|
731
|
+
picked[prop.km] = {}
|
732
|
+
for (let p of c.testConfig.check) {
|
733
|
+
if (p.km) {
|
734
|
+
continue
|
735
|
+
}
|
736
|
+
picked[p] = o[p]
|
737
|
+
}
|
738
|
+
} else {
|
739
|
+
picked[prop] = getObjects(testConfigName)[prop]
|
740
|
+
}
|
728
741
|
}
|
729
742
|
return picked
|
730
743
|
}
|
731
|
-
|
732
|
-
|
733
|
-
|
744
|
+
const expectedGetObjects = (name) => {
|
745
|
+
if (!name) {
|
746
|
+
name = config.name
|
747
|
+
}
|
748
|
+
return expected.objects.namespaced[expected.objects.nameToUUID[name]]
|
749
|
+
}
|
750
|
+
const expected_checked = sortJson(pickEm(expectedGetObjects), { depth: 25 })
|
751
|
+
const actualGetObjects = (name) => {
|
752
|
+
if (!name) {
|
753
|
+
name = config.name
|
754
|
+
}
|
755
|
+
const km = config.configs.find( (km) => km.name == name )
|
756
|
+
return config.config.objects.namespaced[km.uuid]
|
757
|
+
}
|
758
|
+
const actual_checked = sortJson(pickEm(actualGetObjects), { depth: 25 })
|
734
759
|
const failed_checked = !matching(actual_objects, expected_objects)
|
735
760
|
|
736
761
|
const failed_checks = !matching(actual_objects, expected_objects)
|
@@ -863,12 +888,22 @@ const showInfo = (description, section, config) => {
|
|
863
888
|
visibleExamples.push(test.query)
|
864
889
|
}
|
865
890
|
}
|
866
|
-
const
|
891
|
+
const templateQueries = []
|
892
|
+
if (config.instances && config.instances.length > 0) {
|
893
|
+
for (let query of config.instances.slice(-1)[0].queries) {
|
894
|
+
if (typeof query == 'string') {
|
895
|
+
templateQueries.push(query)
|
896
|
+
}
|
897
|
+
}
|
898
|
+
}
|
899
|
+
const info = { name, description, examples: visibleExamples, template: templateQueries, section, includes, demo: config.demo }
|
900
|
+
/*
|
867
901
|
if (config.instances.length > 0) {
|
868
902
|
info.template = {
|
869
903
|
base: config.instances[0].base
|
870
904
|
}
|
871
905
|
}
|
906
|
+
*/
|
872
907
|
console.log(JSON.stringify(info, null, 2))
|
873
908
|
}
|
874
909
|
|
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.7-beta.0",
|
66
67
|
"license": "ISC"
|
67
68
|
}
|
package/src/config.js
CHANGED
@@ -3,7 +3,7 @@ const { Semantics, normalizeGenerator } = require('./semantics')
|
|
3
3
|
const { Generators } = require('./generators')
|
4
4
|
// const { uuid: uuidv4 } = require('uuidv4')
|
5
5
|
const client = require('../client')
|
6
|
-
const
|
6
|
+
const DigraphInternal = require('./digraph_internal')
|
7
7
|
const helpers = require('./helpers')
|
8
8
|
const runtime = require('../runtime')
|
9
9
|
const _ = require('lodash')
|
@@ -1287,7 +1287,7 @@ class Config {
|
|
1287
1287
|
this.name = config.name
|
1288
1288
|
}
|
1289
1289
|
this.motivations = []
|
1290
|
-
this.loadOrder = new
|
1290
|
+
this.loadOrder = new DigraphInternal()
|
1291
1291
|
this.wasInitialized = false
|
1292
1292
|
this.configs = []
|
1293
1293
|
this._api = undefined
|
@@ -1300,7 +1300,7 @@ class Config {
|
|
1300
1300
|
this.config = config
|
1301
1301
|
handleCalculatedProps(this, config)
|
1302
1302
|
}
|
1303
|
-
this.hierarchy = new
|
1303
|
+
this.hierarchy = new DigraphInternal(this.config.hierarchy)
|
1304
1304
|
this.initConfig = _.cloneDeep(this.config)
|
1305
1305
|
this.configs.push(new KM({ config: this.config, getCounter: (name) => this.config.getCounter(name), uuid: this._uuid }))
|
1306
1306
|
|
@@ -1854,7 +1854,7 @@ class Config {
|
|
1854
1854
|
this.resetDelta()
|
1855
1855
|
const debug = this.config.debug;
|
1856
1856
|
this.config = _.cloneDeep(this.initConfig)
|
1857
|
-
this.hierarchy = new
|
1857
|
+
this.hierarchy = new DigraphInternal(this.config.hierarchy)
|
1858
1858
|
if (debug) {
|
1859
1859
|
this.config.debug = debug
|
1860
1860
|
}
|
@@ -1918,7 +1918,7 @@ class Config {
|
|
1918
1918
|
config.wasInitialized = false
|
1919
1919
|
// TODO change name of config: to baseConfig:
|
1920
1920
|
const kmFn = (name) => this.getConfig(name)
|
1921
|
-
// const hierarchy = new
|
1921
|
+
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
1922
1922
|
const args = { isModule, addWord: aw, km: kmFn, hierarchy: this.hierarchy, config, baseConfig: this, currentConfig: config, uuid: config._uuid, objects: namespacedObjects, namespace, api: config.api }
|
1923
1923
|
config.initializerFn(args)
|
1924
1924
|
if (config.initAfterApi) {
|
package/src/digraph.js
CHANGED
@@ -13,6 +13,38 @@ class Digraph {
|
|
13
13
|
this._edges = edges
|
14
14
|
}
|
15
15
|
|
16
|
+
// BFS
|
17
|
+
path(from, to) {
|
18
|
+
debugger
|
19
|
+
const frontier = { [from]: [[]] }
|
20
|
+
const done = new Set()
|
21
|
+
while (Object.keys(frontier).length > 0) {
|
22
|
+
const n = Object.keys(frontier)[0]
|
23
|
+
const ps = frontier[n]
|
24
|
+
if (to == n) {
|
25
|
+
return ps[0]
|
26
|
+
}
|
27
|
+
if (done.has(n)) {
|
28
|
+
delete frontier[n]
|
29
|
+
continue
|
30
|
+
}
|
31
|
+
done.add(n)
|
32
|
+
for (let edge of this._edges) {
|
33
|
+
if (edge.child == n) {
|
34
|
+
if (!frontier[edge.parent]) {
|
35
|
+
frontier[edge.parent] = []
|
36
|
+
}
|
37
|
+
for (let path of ps) {
|
38
|
+
if (edge.parent == to) {
|
39
|
+
return [...path, edge]
|
40
|
+
}
|
41
|
+
frontier[edge.parent].push([...path, edge])
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
16
48
|
addEdges(edges) {
|
17
49
|
for (let edge of edges) {
|
18
50
|
this.addEdge(edge)
|
@@ -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
|