theprogrammablemind_4wp 7.5.0-beta.2 → 7.5.0-beta.21
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +40 -14
- package/lines.js +3 -0
- package/package.json +1 -1
- package/src/config.js +36 -34
- package/src/generators.js +4 -2
- package/src/helpers.js +7 -0
- package/src/semantics.js +4 -2
package/client.js
CHANGED
@@ -78,7 +78,15 @@ const listable = (hierarchy) => (c, type) => {
|
|
78
78
|
return false
|
79
79
|
}
|
80
80
|
|
81
|
-
const isA = (hierarchy) => (child, parent) =>
|
81
|
+
const isA = (hierarchy) => (child, parent) => {
|
82
|
+
if (child.marker) {
|
83
|
+
child = child.marker
|
84
|
+
}
|
85
|
+
if (parent.marker) {
|
86
|
+
parent = parent.marker
|
87
|
+
}
|
88
|
+
return hierarchy.isA(child, parent)
|
89
|
+
}
|
82
90
|
|
83
91
|
const asList = (context) => {
|
84
92
|
if (context.marker === 'list') {
|
@@ -670,9 +678,12 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
|
|
670
678
|
defaultErrorHandler(error)
|
671
679
|
}
|
672
680
|
|
673
|
-
|
681
|
+
let objects = getObjects(config.config.objects)(config.uuid)
|
682
|
+
if (testConfig.testModuleName) {
|
683
|
+
objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
|
684
|
+
}
|
674
685
|
config.beforeQuery({ query: test, isModule: false, objects })
|
675
|
-
config.resetMotivations()
|
686
|
+
// config.resetMotivations()
|
676
687
|
try {
|
677
688
|
const result = await _process(config, test, { errorHandler, isTest: true })
|
678
689
|
result.query = test
|
@@ -783,7 +794,7 @@ const runTests = async (config, testFile, juicyBits) => {
|
|
783
794
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
784
795
|
config.rebuild()
|
785
796
|
const objects = getObjects(config.config.objects)(config.uuid)
|
786
|
-
config.resetMotivations()
|
797
|
+
//config.resetMotivations()
|
787
798
|
config.beforeQuery({ query: test, isModule: false, objects })
|
788
799
|
console.log(test)
|
789
800
|
const result = await _process(config, test, { isTest: true })
|
@@ -1252,7 +1263,7 @@ const knowledgeModule = async ({
|
|
1252
1263
|
description: 'Entodicton knowledge module'
|
1253
1264
|
})
|
1254
1265
|
|
1255
|
-
parser.add_argument('-
|
1266
|
+
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
1256
1267
|
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1257
1268
|
parser.add_argument('-tv', '--testVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. Create tests by running with the --query or --loop with the --save flag' })
|
1258
1269
|
parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag' })
|
@@ -1267,7 +1278,7 @@ const knowledgeModule = async ({
|
|
1267
1278
|
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
1268
1279
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
1269
1280
|
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
1270
|
-
parser.add_argument('-
|
1281
|
+
parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
|
1271
1282
|
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
1272
1283
|
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
1273
1284
|
parser.add_argument('-daa', '--dontAddAssociations', { action: 'store_true', help: 'Do not add associations from the tests.' })
|
@@ -1306,11 +1317,11 @@ const knowledgeModule = async ({
|
|
1306
1317
|
return
|
1307
1318
|
}
|
1308
1319
|
|
1309
|
-
if (args.
|
1320
|
+
if (args.deleteTest) {
|
1310
1321
|
let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1311
|
-
tests = tests.filter( (test) => test.query !== args.
|
1322
|
+
tests = tests.filter( (test) => test.query !== args.deleteTest );
|
1312
1323
|
writeTestFile(testConfig.name, tests)
|
1313
|
-
console.log(`Remove the test for "${args.
|
1324
|
+
console.log(`Remove the test for "${args.deleteTest}"`)
|
1314
1325
|
return
|
1315
1326
|
}
|
1316
1327
|
|
@@ -1466,7 +1477,15 @@ const knowledgeModule = async ({
|
|
1466
1477
|
}
|
1467
1478
|
return
|
1468
1479
|
}
|
1469
|
-
|
1480
|
+
let useTestConfig = testConfig
|
1481
|
+
if (args.testModuleName) {
|
1482
|
+
useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
|
1483
|
+
useTestConfig.testModuleName = args.testModuleName
|
1484
|
+
test = useTestConfig.name
|
1485
|
+
|
1486
|
+
}
|
1487
|
+
// runTests(config, args.testFileName ? `${args.testFileName}.test.json` : test, { debug: args.debug, testConfig: testConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1488
|
+
runTests(config, test, { debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1470
1489
|
if (results.length > 0 && args.vimdiff) {
|
1471
1490
|
for (const result of results) {
|
1472
1491
|
vimdiff(result.expected, result.actual)
|
@@ -1515,19 +1534,25 @@ const knowledgeModule = async ({
|
|
1515
1534
|
if (!headerShown) {
|
1516
1535
|
console.log(' Failure')
|
1517
1536
|
}
|
1518
|
-
|
1519
|
-
|
1537
|
+
const widths = [4, 18, 72]
|
1538
|
+
const lines = new Lines(widths)
|
1539
|
+
lines.setElement(1, 1, 'expected checked')
|
1540
|
+
lines.setElement(2, 2, JSON.stringify(result.expected.checked, null, 2))
|
1541
|
+
lines.log()
|
1542
|
+
lines.setElement(1, 1, 'actual checked')
|
1543
|
+
lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
|
1544
|
+
lines.log()
|
1520
1545
|
newError = true
|
1521
1546
|
headerShown = true
|
1522
1547
|
}
|
1523
1548
|
}
|
1524
1549
|
}
|
1525
1550
|
if (!headerShown) {
|
1526
|
-
if (!(
|
1551
|
+
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1527
1552
|
console.log('There are failures due to things other than paraphrases, responses and checked properties being different. They are not shown because you ran -tv or -tva which only shows difference in paraphrase and results. Usually what I do is -s and do a diff to make sure there are no other problems. If the paraphrases or results were different they would have shown here.')
|
1528
1553
|
}
|
1529
1554
|
}
|
1530
|
-
if (!(
|
1555
|
+
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1531
1556
|
console.log('use -v arg to write files expected.json and actual.json in the current directory for detailed comparison. Or do -s and then git diff the changes.')
|
1532
1557
|
// console.log(JSON.stringify(contexts))
|
1533
1558
|
console.log('**************************** ERRORS ************************')
|
@@ -1589,6 +1614,7 @@ const knowledgeModule = async ({
|
|
1589
1614
|
}
|
1590
1615
|
} else {
|
1591
1616
|
config.addAssociationsFromTests(config.tests);
|
1617
|
+
config.setTestConfig(testConfig)
|
1592
1618
|
//for (let query in config.tests) {
|
1593
1619
|
// config.addAssociations(config.tests[query].associations || []);
|
1594
1620
|
//}
|
package/lines.js
CHANGED
@@ -12,6 +12,9 @@ class Lines {
|
|
12
12
|
// will wrap to next line within the column
|
13
13
|
setElement (row, column, value) {
|
14
14
|
const values = value.toString().split('\n')
|
15
|
+
if (column >= this.widths.length) {
|
16
|
+
throw "Column out of range."
|
17
|
+
}
|
15
18
|
const width = this.widths[column]
|
16
19
|
let index = 0
|
17
20
|
for (value of values) {
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -330,6 +330,17 @@ class Config {
|
|
330
330
|
return `${maybeName}${counter}`
|
331
331
|
}
|
332
332
|
|
333
|
+
setTestConfig(testConfig) {
|
334
|
+
if (this.name == 'ui') {
|
335
|
+
console.log('ui setting testConfig')
|
336
|
+
}
|
337
|
+
this.testConfig = testConfig
|
338
|
+
}
|
339
|
+
|
340
|
+
getTestConfig() {
|
341
|
+
return this.testConfig
|
342
|
+
}
|
343
|
+
|
333
344
|
defaultConfig () {
|
334
345
|
this.config = {
|
335
346
|
operators: [], // TODO
|
@@ -412,11 +423,11 @@ class Config {
|
|
412
423
|
}
|
413
424
|
|
414
425
|
getSemantics (logs = []) {
|
415
|
-
return new Semantics(this.config.semantics
|
426
|
+
return new Semantics(this.config.semantics, logs, { km: this.name })
|
416
427
|
}
|
417
428
|
|
418
429
|
getGenerators (logs = []) {
|
419
|
-
return new Generators(this.config.generators
|
430
|
+
return new Generators(this.config.generators, logs, { km: this.name })
|
420
431
|
}
|
421
432
|
|
422
433
|
warningNotEvaluated (log, value) {
|
@@ -601,9 +612,6 @@ class Config {
|
|
601
612
|
if (typeof parent !== 'string') {
|
602
613
|
throw `addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`
|
603
614
|
}
|
604
|
-
if (!this.config.hierarchy) {
|
605
|
-
this.config.hierarchy = []
|
606
|
-
}
|
607
615
|
if (global.entodictonDebugHierarchy) {
|
608
616
|
if (deepEqual(global.entodictonDebugHierarchy, [child, parent])) {
|
609
617
|
debugger; // debug hierarchy hit
|
@@ -622,9 +630,6 @@ class Config {
|
|
622
630
|
throw `addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`
|
623
631
|
}
|
624
632
|
|
625
|
-
if (!this.config.hierarchy) {
|
626
|
-
this.config.hierarchy = []
|
627
|
-
}
|
628
633
|
if (global.entodictonDebugHierarchy) {
|
629
634
|
if (deepEqual(global.entodictonDebugHierarchy, [child, parent])) {
|
630
635
|
debugger; // debug hierarchy hit
|
@@ -962,17 +967,11 @@ class Config {
|
|
962
967
|
if (!config) {
|
963
968
|
return
|
964
969
|
}
|
965
|
-
config.operators = config.operators || []
|
966
|
-
config.bridges = config.bridges || []
|
967
|
-
config.words = config.words || {}
|
968
|
-
config.generators = config.generators || []
|
969
|
-
config.semantics = config.semantics || []
|
970
|
-
|
971
970
|
config.operators = config.operators.filter( (element) => !element.development )
|
972
971
|
config.bridges = config.bridges.filter( (element) => !element.development )
|
973
972
|
config.generators = config.generators.filter( (element) => !element.development )
|
974
973
|
config.semantics = config.semantics.filter( (element) => !element.development )
|
975
|
-
config.hierarchy = (config.hierarchy
|
974
|
+
config.hierarchy = (config.hierarchy).filter( (element) => !element.development )
|
976
975
|
for (const word in config.words) {
|
977
976
|
const defs = config.words[word] || []
|
978
977
|
config.words[word] = defs.filter( (def) => !def.development )
|
@@ -1101,17 +1100,8 @@ class Config {
|
|
1101
1100
|
if (config) {
|
1102
1101
|
config = _.cloneDeep(config)
|
1103
1102
|
this.config = config
|
1104
|
-
|
1105
|
-
|
1106
|
-
}
|
1107
|
-
if (!this.config.semantics) {
|
1108
|
-
this.config.semantics = []
|
1109
|
-
}
|
1110
|
-
if (!this.config.words) {
|
1111
|
-
// this.config.words = {}
|
1112
|
-
}
|
1113
|
-
for (let bridge of (this.config.bridges || [])) {
|
1114
|
-
const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generators', 'id', 'inverted', 'isA',
|
1103
|
+
for (let bridge of this.config.bridges) {
|
1104
|
+
const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generators', 'id', 'implicit', 'inverted', 'isA', 'children', 'parents',
|
1115
1105
|
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy' ]
|
1116
1106
|
helpers.validProps(valid, bridge, 'bridge')
|
1117
1107
|
/*
|
@@ -1122,6 +1112,16 @@ class Config {
|
|
1122
1112
|
})
|
1123
1113
|
}
|
1124
1114
|
*/
|
1115
|
+
if (bridge.children) {
|
1116
|
+
for (let child of bridge.children) {
|
1117
|
+
this.addHierarchy(child, bridge.id)
|
1118
|
+
}
|
1119
|
+
}
|
1120
|
+
if (bridge.parents) {
|
1121
|
+
for (let parent of bridge.parents) {
|
1122
|
+
this.addHierarchy(bridge.id, parent)
|
1123
|
+
}
|
1124
|
+
}
|
1125
1125
|
if (bridge.isA) {
|
1126
1126
|
for (let parent of bridge.isA) {
|
1127
1127
|
this.addHierarchy(bridge.id, parent)
|
@@ -1196,6 +1196,7 @@ class Config {
|
|
1196
1196
|
})
|
1197
1197
|
}
|
1198
1198
|
}
|
1199
|
+
this.hierarchy = new Digraph(this.config.hierarchy)
|
1199
1200
|
this.initConfig = _.cloneDeep(this.config)
|
1200
1201
|
this.configs.push(new KM({ config: this.config, getCounter: (name) => this.config.getCounter(name), uuid: this._uuid }))
|
1201
1202
|
|
@@ -1399,12 +1400,13 @@ class Config {
|
|
1399
1400
|
cp.name = this.name
|
1400
1401
|
cp.description = this.description
|
1401
1402
|
cp.tests = this.tests
|
1402
|
-
cp.motivations = this.motivations
|
1403
|
+
cp.motivations = [...this.motivations]
|
1403
1404
|
cp.isModule = this.isModule
|
1404
1405
|
cp.loadedForTesting = this.loadedForTesting
|
1405
1406
|
cp.initInstances = this.initInstances.slice()
|
1406
1407
|
cp.instances = this.instances.slice()
|
1407
1408
|
cp.configCounter = this.configCounter
|
1409
|
+
cp.testConfig = this.testConfig
|
1408
1410
|
|
1409
1411
|
cp.initConfig = _.cloneDeep(this.initConfig)
|
1410
1412
|
cp.defaultConfig()
|
@@ -1450,7 +1452,7 @@ class Config {
|
|
1450
1452
|
this.config.bridges && this.config.bridges.forEach((bridge) => { bridge.uuid = this._uuid })
|
1451
1453
|
this.config.words && setWordsUUIDs(this.config.words, this._uuid)
|
1452
1454
|
this.config.operators && this.config.operators.forEach((operator) => { operator.uuid = this._uuid })
|
1453
|
-
const ids = Array.from(new Set(
|
1455
|
+
const ids = Array.from(new Set(this.config.bridges.map((bridge) => bridge.id)))
|
1454
1456
|
ids.sort()
|
1455
1457
|
this.config.namespaces = {}
|
1456
1458
|
// if (true || ids.length > 0) {
|
@@ -1682,7 +1684,7 @@ class Config {
|
|
1682
1684
|
}
|
1683
1685
|
|
1684
1686
|
const kmsUuids = this.configs.map((km) => km.uuid)
|
1685
|
-
const bridgesUuids =
|
1687
|
+
const bridgesUuids = this.config.bridges.map((bridge) => bridge.uuid).filter((uuid) => uuid)
|
1686
1688
|
let result = true
|
1687
1689
|
bridgesUuids.forEach((buuid) => {
|
1688
1690
|
if (!kmsUuids.includes(buuid)) {
|
@@ -1752,6 +1754,7 @@ class Config {
|
|
1752
1754
|
this.resetDelta()
|
1753
1755
|
const debug = this.config.debug;
|
1754
1756
|
this.config = _.cloneDeep(this.initConfig)
|
1757
|
+
this.hierarchy = new Digraph(this.config.hierarchy)
|
1755
1758
|
if (debug) {
|
1756
1759
|
this.config.debug = debug
|
1757
1760
|
}
|
@@ -1766,6 +1769,7 @@ class Config {
|
|
1766
1769
|
}
|
1767
1770
|
this.config.objects.namespaced = {}
|
1768
1771
|
this.resetWasInitialized()
|
1772
|
+
this.resetMotivations()
|
1769
1773
|
|
1770
1774
|
// reorder configs base on load ordering
|
1771
1775
|
{
|
@@ -1811,8 +1815,8 @@ class Config {
|
|
1811
1815
|
config.wasInitialized = false
|
1812
1816
|
// TODO change name of config: to baseConfig:
|
1813
1817
|
const kmFn = (name) => this.getConfig(name)
|
1814
|
-
const hierarchy = new Digraph((config.config || {}).hierarchy
|
1815
|
-
const args = { isModule, addWord: aw, km: kmFn, hierarchy, config, baseConfig: this, currentConfig: config, uuid: config._uuid, objects: namespacedObjects, namespace, api: config.api }
|
1818
|
+
// const hierarchy = new Digraph((config.config || {}).hierarchy)
|
1819
|
+
const args = { isModule, addWord: aw, km: kmFn, hierarchy: this.hierarchy, config, baseConfig: this, currentConfig: config, uuid: config._uuid, objects: namespacedObjects, namespace, api: config.api }
|
1816
1820
|
config.initializerFn(args)
|
1817
1821
|
if (config.initAfterApi) {
|
1818
1822
|
initAfterApis.push({ config, args })
|
@@ -2009,8 +2013,7 @@ class Config {
|
|
2009
2013
|
}
|
2010
2014
|
|
2011
2015
|
if (config.hierarchy) {
|
2012
|
-
|
2013
|
-
hierarchy = hierarchy.map((h) => {
|
2016
|
+
helpers.mapInPlace(config.hierarchy, (h) => {
|
2014
2017
|
if (Array.isArray(h)) {
|
2015
2018
|
return h.map((id) => toNS(id))
|
2016
2019
|
} else {
|
@@ -2019,7 +2022,6 @@ class Config {
|
|
2019
2022
|
return Object.assign({}, h, { child: toNS(h.child), parent: toNS(h.parent) })
|
2020
2023
|
}
|
2021
2024
|
})
|
2022
|
-
config.hierarchy = hierarchy
|
2023
2025
|
}
|
2024
2026
|
|
2025
2027
|
if (config.priorities) {
|
package/src/generators.js
CHANGED
@@ -195,10 +195,12 @@ class Generators {
|
|
195
195
|
} catch( e ) {
|
196
196
|
// the next if handle this
|
197
197
|
generated = null
|
198
|
+
e.retryCall = () => generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
|
199
|
+
const help = 'The error has a retryCall property that will recall the function that failed.'
|
198
200
|
if (e.stack && e.message) {
|
199
|
-
errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}`
|
201
|
+
errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}. ${help}`
|
200
202
|
} else if (e.error) {
|
201
|
-
errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.error.join()}. Generator is ${generator.toString()}`
|
203
|
+
errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.error.join()}. Generator is ${generator.toString()}. ${help}`
|
202
204
|
} else {
|
203
205
|
errorMessage = e.toString()
|
204
206
|
}
|
package/src/helpers.js
CHANGED
@@ -232,7 +232,14 @@ const validProps = (valids, object, type) => {
|
|
232
232
|
}
|
233
233
|
}
|
234
234
|
|
235
|
+
const mapInPlace = (list, fn) => {
|
236
|
+
for (let i = 0; i < list.length; ++i) {
|
237
|
+
list[i] =fn(list[i])
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
235
241
|
module.exports = {
|
242
|
+
mapInPlace,
|
236
243
|
validProps,
|
237
244
|
args,
|
238
245
|
safeEquals,
|
package/src/semantics.js
CHANGED
@@ -189,10 +189,12 @@ class Semantics {
|
|
189
189
|
} catch( e ) {
|
190
190
|
contextPrime = null
|
191
191
|
let errorMessage
|
192
|
+
e.retryCall = () => semantic.apply(args, context, s, log, options)
|
193
|
+
const help = 'The error has a retryCall property that will recall the function that failed.'
|
192
194
|
if (e.stack && e.message) {
|
193
|
-
errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.toString()} stack is ${e.stack}. Semantic is ${semantic.toString()}`
|
195
|
+
errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.toString()} stack is ${e.stack}. Semantic is ${semantic.toString()}. ${help}`
|
194
196
|
} else if (e.error) {
|
195
|
-
errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.error.join()}. Semantic is ${semantic.toString()}`
|
197
|
+
errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.error.join()}. Semantic is ${semantic.toString()}. ${help}`
|
196
198
|
} else {
|
197
199
|
errorMessage = e.toString();
|
198
200
|
}
|