theprogrammablemind_4wp 8.1.0 → 8.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +19 -9
- package/package.json +1 -1
- package/src/config.js +37 -13
- package/src/configHelpers.js +4 -2
- package/src/digraph.js +10 -0
- package/src/digraph_internal.js +10 -0
package/client.js
CHANGED
@@ -441,7 +441,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
441
441
|
return configForTest
|
442
442
|
}
|
443
443
|
|
444
|
-
const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
|
444
|
+
const runTest = async (config, expected, { args, verbose, testConfig, debug, timings={ server: 0, client: 0 } }) => {
|
445
445
|
const test = expected.query
|
446
446
|
if (args.query && args.query != test) {
|
447
447
|
// no run this
|
@@ -472,6 +472,8 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
|
|
472
472
|
const lines = new Lines(widths)
|
473
473
|
lines.setElement(0, 0, test)
|
474
474
|
lines.setElement(0, 1, `time on server: ${result.times.toFixed(2)} client: ${(result.clientSideTimes / 1000).toFixed(2)}`)
|
475
|
+
timings.server += result.times
|
476
|
+
timings.client += result.clientSideTimes / 1000
|
475
477
|
lines.log()
|
476
478
|
}
|
477
479
|
const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
|
@@ -784,7 +786,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
784
786
|
responses.errors.forEach((error) => console.log(` ${error}`))
|
785
787
|
}
|
786
788
|
console.log("KM's loaded (ordered)", config.configs.map((c) => c.name))
|
787
|
-
console.log('This is the global objects from running semantics:\n', config.objects)
|
789
|
+
// console.log('This is the global objects from running semantics:\n', config.objects)
|
788
790
|
if (!_.isEmpty(responses.learned_contextual_priorities)) {
|
789
791
|
console.log('\nThe learned contextual priorties are :\n')
|
790
792
|
for (const lcp of responses.learned_contextual_priorities) {
|
@@ -801,10 +803,12 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
801
803
|
}
|
802
804
|
console.log(responses.trace)
|
803
805
|
|
804
|
-
if (
|
805
|
-
|
806
|
-
|
807
|
-
|
806
|
+
if (false) {
|
807
|
+
if (global.beforeObjects) {
|
808
|
+
console.log('objects', runtime.jsonDiff.diffString(global.beforeObjects, config.get('objects')))
|
809
|
+
} else {
|
810
|
+
console.log('objects', runtime.util.inspect(config.get('objects'), { depth: Infinity, sorted: true }))
|
811
|
+
}
|
808
812
|
}
|
809
813
|
|
810
814
|
const pickEm = () => {
|
@@ -867,7 +871,9 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
867
871
|
}
|
868
872
|
*/
|
869
873
|
console.log('')
|
870
|
-
const
|
874
|
+
const screen_width = process.stdout.columns
|
875
|
+
// || 0 for when running without a console
|
876
|
+
const widths = [60, 10, Math.max(80, screen_width-71 || 0)]
|
871
877
|
const lines = new Lines(widths)
|
872
878
|
lines.setElement(0, 0, '--- The paraphrases are ----------')
|
873
879
|
lines.setElement(0, 2, '--- The response strings are ----------')
|
@@ -1229,6 +1235,7 @@ const knowledgeModuleImpl = async ({
|
|
1229
1235
|
parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
|
1230
1236
|
parser.add_argument('-ep', '--explainPriorities', { action: 'store_true', help: 'The server will return all priorities including the generated one along with an explanation of there they came from' })
|
1231
1237
|
parser.add_argument('-dic', '--debugIncludeConvolutions', { nargs: '?', help: 'When running with the --debugIncludeConvolutions flag the logs will include convolutions which are somewhat annoyingly verbose. Default is false' })
|
1238
|
+
parser.add_argument('-bc', '--bypassCache', { action: 'store_true', help: 'Bypass the cache on the server side and rebuild' })
|
1232
1239
|
|
1233
1240
|
const args = parser.parse_args()
|
1234
1241
|
args.count = args.count || 1
|
@@ -1488,7 +1495,7 @@ const knowledgeModuleImpl = async ({
|
|
1488
1495
|
}
|
1489
1496
|
}
|
1490
1497
|
|
1491
|
-
if (args.
|
1498
|
+
if (args.bypassCache) {
|
1492
1499
|
config.config.retrain = true
|
1493
1500
|
}
|
1494
1501
|
|
@@ -1520,7 +1527,8 @@ const knowledgeModuleImpl = async ({
|
|
1520
1527
|
useTestConfig.testModuleName = args.testModuleName
|
1521
1528
|
test = useTestConfig.name
|
1522
1529
|
}
|
1523
|
-
|
1530
|
+
const timings = { server: 0, client: 0 }
|
1531
|
+
await runTests(config, test, { timings, args, debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1524
1532
|
let newError = false
|
1525
1533
|
if (results.length > 0) {
|
1526
1534
|
let headerShown = false
|
@@ -1552,6 +1560,8 @@ const knowledgeModuleImpl = async ({
|
|
1552
1560
|
}
|
1553
1561
|
}
|
1554
1562
|
|
1563
|
+
|
1564
|
+
console.log(`Total Server Time: ${timings.server.toFixed(2)}. Total Client Time: ${timings.client.toFixed(2)}`)
|
1555
1565
|
if (hasError) {
|
1556
1566
|
console.log('**************************** ERRORS ************************')
|
1557
1567
|
for (const result of results) {
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -27,6 +27,10 @@ const config_toServer = (config) => {
|
|
27
27
|
// cant change things because copy breaks something
|
28
28
|
}
|
29
29
|
|
30
|
+
const updateHierarchy = (config) => {
|
31
|
+
config.hierarchy = new DigraphInternal(config.config.hierarchy)
|
32
|
+
}
|
33
|
+
|
30
34
|
const initWords = (words) => {
|
31
35
|
if (!words.literals) {
|
32
36
|
words.literals = {}
|
@@ -266,7 +270,6 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
266
270
|
}
|
267
271
|
if (bridge.children) {
|
268
272
|
for (const child of bridge.children) {
|
269
|
-
// config.addHierarchy(child, bridge.id)
|
270
273
|
if (child.child) {
|
271
274
|
config.addHierarchy(child.child, bridge.id, child.instance)
|
272
275
|
} else {
|
@@ -1366,8 +1369,25 @@ class Config {
|
|
1366
1369
|
}
|
1367
1370
|
}
|
1368
1371
|
|
1369
|
-
|
1370
|
-
|
1372
|
+
addHierarchyInternal (edge) {
|
1373
|
+
debugHierarchy([edge[0], edge[1]])
|
1374
|
+
// because this is called from the semantics and internally. in the semantics the config can be a pseudo config
|
1375
|
+
// where hierarchy and config.hierarchy do not match
|
1376
|
+
if (this.hierarchy) {
|
1377
|
+
this.hierarchy.addEdge(edge)
|
1378
|
+
// no dups due to sharing
|
1379
|
+
if (this.hierarchy._edges != this.config.hierarchy) {
|
1380
|
+
this.config.hierarchy.push(edge)
|
1381
|
+
this._delta.json.hierarchy.push(edge)
|
1382
|
+
}
|
1383
|
+
} else {
|
1384
|
+
this.config.hierarchy.push(edge)
|
1385
|
+
this._delta.json.hierarchy.push(edge)
|
1386
|
+
}
|
1387
|
+
}
|
1388
|
+
|
1389
|
+
addHierarchyProperties (properties) {
|
1390
|
+
const { child, parent, instance } = properties
|
1371
1391
|
if (typeof child !== 'string') {
|
1372
1392
|
throw new Error(`addHierarchy expected child property to be a string. got ${JSON.stringify(child)}`)
|
1373
1393
|
}
|
@@ -1377,10 +1397,8 @@ class Config {
|
|
1377
1397
|
if (instance && typeof instance !== 'boolean') {
|
1378
1398
|
throw new Error(`addHierarchy expected instance property to be a boolean or undefined. got ${JSON.stringify(instance)}`)
|
1379
1399
|
}
|
1380
|
-
|
1381
|
-
this.
|
1382
|
-
// TODO greg11 this.hierarchy.addEdge(edge)
|
1383
|
-
this._delta.json.hierarchy.push([child, parent, instance || false])
|
1400
|
+
const edge = [child, parent, instance || false]
|
1401
|
+
this.addHierarchyInternal(edge)
|
1384
1402
|
}
|
1385
1403
|
|
1386
1404
|
addHierarchyChildParent (child, parent, instance) {
|
@@ -1403,9 +1421,8 @@ class Config {
|
|
1403
1421
|
return
|
1404
1422
|
}
|
1405
1423
|
|
1406
|
-
|
1407
|
-
|
1408
|
-
this._delta.json.hierarchy.push([child, parent, instance || false])
|
1424
|
+
const edge = [child, parent, instance || false]
|
1425
|
+
this.addHierarchyInternal(edge)
|
1409
1426
|
}
|
1410
1427
|
|
1411
1428
|
getBridge (id, level) {
|
@@ -2116,6 +2133,7 @@ class Config {
|
|
2116
2133
|
cp.configCounter = this.configCounter
|
2117
2134
|
cp.testConfig = this.testConfig
|
2118
2135
|
cp._server = this._server
|
2136
|
+
cp.hierarchy = new DigraphInternal(this.config.hierarchy)
|
2119
2137
|
|
2120
2138
|
cp.initConfig = _.cloneDeep(this.initConfig)
|
2121
2139
|
cp.defaultConfig()
|
@@ -2506,6 +2524,7 @@ class Config {
|
|
2506
2524
|
}
|
2507
2525
|
if (!isSelf) {
|
2508
2526
|
config.config = _.cloneDeep(config.initConfig)
|
2527
|
+
config.hierarchy = new DigraphInternal(config.config.hierarchy)
|
2509
2528
|
}
|
2510
2529
|
config.wasInitialized = false
|
2511
2530
|
// TODO change name of config: to baseConfig:
|
@@ -3132,10 +3151,15 @@ class Config {
|
|
3132
3151
|
|
3133
3152
|
// console.log('key', key, 'XXX')
|
3134
3153
|
// console.log('more', JSON.stringify(more, null, 2))
|
3135
|
-
|
3136
|
-
|
3154
|
+
// hierarchy must update in place and does not care about the list order
|
3155
|
+
if (key == 'hierarchy') {
|
3156
|
+
this.config[key].push(...more[key])
|
3137
3157
|
} else {
|
3138
|
-
|
3158
|
+
if (addFirst) {
|
3159
|
+
this.config[key] = more[key].concat(this.config[key])
|
3160
|
+
} else {
|
3161
|
+
this.config[key] = this.config[key].concat(more[key])
|
3162
|
+
}
|
3139
3163
|
}
|
3140
3164
|
} else {
|
3141
3165
|
if (!(key in this.config)) {
|
package/src/configHelpers.js
CHANGED
@@ -240,7 +240,8 @@ const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
|
|
240
240
|
delete data.generators
|
241
241
|
// const semantics = new Semantics((data.semantics || []).map((g) => new Semantic(normalizeSemantic(g))))
|
242
242
|
delete data.semantics
|
243
|
-
const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
|
243
|
+
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
|
244
|
+
const hierarchy = config.hierarchy
|
244
245
|
|
245
246
|
return {
|
246
247
|
data,
|
@@ -406,7 +407,8 @@ const loadInstance = async (config, instance) => {
|
|
406
407
|
}
|
407
408
|
}
|
408
409
|
|
409
|
-
const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
|
410
|
+
// const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
|
411
|
+
const hierarchy = config.hierarchy
|
410
412
|
for (const i in (instance.resultss || [])) {
|
411
413
|
const results = instance.resultss[i]
|
412
414
|
if (results.extraConfig) {
|
package/src/digraph.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
const _ = require('lodash')
|
2
|
+
|
1
3
|
const toA = (edge) => {
|
2
4
|
if (Array.isArray(edge)) {
|
3
5
|
return edge
|
@@ -45,6 +47,10 @@ class Digraph {
|
|
45
47
|
}
|
46
48
|
}
|
47
49
|
|
50
|
+
get length () {
|
51
|
+
return this._edges.length
|
52
|
+
}
|
53
|
+
|
48
54
|
addEdges (edges) {
|
49
55
|
for (const edge of edges) {
|
50
56
|
this.addEdge(edge)
|
@@ -53,7 +59,11 @@ class Digraph {
|
|
53
59
|
|
54
60
|
addEdge (edge) {
|
55
61
|
edge = toA(edge)
|
62
|
+
if (this._edges.find((existing) => _.isEqual(edge, existing))) {
|
63
|
+
return false
|
64
|
+
}
|
56
65
|
this._edges.push(edge)
|
66
|
+
return true
|
57
67
|
}
|
58
68
|
|
59
69
|
get edges () {
|
package/src/digraph_internal.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
const _ = require('lodash')
|
2
|
+
|
1
3
|
const toA = (edge) => {
|
2
4
|
if (Array.isArray(edge)) {
|
3
5
|
return edge
|
@@ -21,7 +23,11 @@ class DigraphInternal {
|
|
21
23
|
|
22
24
|
addEdge (edge) {
|
23
25
|
edge = toA(edge)
|
26
|
+
if (this._edges.find((existing) => _.isEqual(edge, existing))) {
|
27
|
+
return false
|
28
|
+
}
|
24
29
|
this._edges.push(edge)
|
30
|
+
return true
|
25
31
|
}
|
26
32
|
|
27
33
|
get edges () {
|
@@ -32,6 +38,10 @@ class DigraphInternal {
|
|
32
38
|
this._edges = edges
|
33
39
|
}
|
34
40
|
|
41
|
+
get length () {
|
42
|
+
return this._edges.length
|
43
|
+
}
|
44
|
+
|
35
45
|
/*
|
36
46
|
set edges(edges) {
|
37
47
|
this._edges = edges.map( toA )
|