theprogrammablemind_4wp 8.0.0-beta.60 → 8.0.0-beta.62

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/client.js +472 -462
  2. package/package.json +1 -1
  3. package/src/config.js +20 -0
package/client.js CHANGED
@@ -1080,6 +1080,7 @@ const knowledgeModuleImpl = async ({
1080
1080
  config : configStruct,
1081
1081
  api,
1082
1082
  initializer,
1083
+ terminator,
1083
1084
  multiApiInitializer,
1084
1085
 
1085
1086
  module: moduleFromJSFile,
@@ -1111,6 +1112,7 @@ const knowledgeModuleImpl = async ({
1111
1112
 
1112
1113
  const createConfig = async () => {
1113
1114
  const config = new Config(configStruct, moduleFromJSFile, _process)
1115
+ config.setTerminator(terminator)
1114
1116
  config.stop_auto_rebuild()
1115
1117
  await config.add(...(includes || []))
1116
1118
  if (api) {
@@ -1158,547 +1160,555 @@ const knowledgeModuleImpl = async ({
1158
1160
  }
1159
1161
 
1160
1162
  if (isProcess) {
1161
- const parser = new runtime.ArgumentParser({
1162
- description: 'Entodicton knowledge module'
1163
- })
1163
+ let config
1164
+ try {
1165
+ const parser = new runtime.ArgumentParser({
1166
+ description: 'Entodicton knowledge module'
1167
+ })
1164
1168
 
1165
- const helpDebugWord = 'In order to get a debug break when a specific word is created set the DEBUG_WORD environment variable to the JSON of the association to break on. For example DEBUG_WORD=\'"the"\''
1166
- const helpDebugAssociation = 'In order to get a debug break when a specific association is created set the DEBUG_ASSOCIATION environment variable to the JSON of the association to break on. For example DEBUG_ASSOCIATION=\'[["the", 0], ["mammal", 1]]\''
1167
- const helpDebugHierarchy = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_HIERARCHY environment variable to the JSON of the child-parent pair to break on. For example DEBUG_HIERARCHY=\'[["cat", 1], ["mammel", 1]]\''
1168
- const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'[["verb", 0], ["article", 0]]\''
1169
- const helpDebugContextualPriority = 'In order to get a debug break when a specific set of contextual priorities is created set set DEBUG_CONTEXTUAL_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_CONTEXTUAL_PRIORITY=\'{ context: [["verb", 0], ["article", 0], select: 1}\''
1170
- const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id to break on. For example DEBUG_BRIDGE=\'car\''
1171
- const helpDebugOperator = 'In order to get a debug break when a specific hierarcy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\''
1172
-
1173
- parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
1174
- parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
1175
- 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' })
1176
- // parser.add_argument('-ttr', '--testToRun', { help: 'Only the specified test will be run' })
1177
- 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. if -q is specified the tests will be run for just the specified query.' })
1178
- parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
1179
- parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
1180
- // parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
1181
- parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild. Using optimization where if the query/config has not changed it will use the previous value. One there is a change all subsequence query/configs will be run.' })
1182
- parser.add_argument('-rtf', '--rebuildTemplateFull', { action: 'store_true', help: 'Force a template rebuild. Skip the optimization' })
1183
- parser.add_argument('-l', '--loop', { action: 'store_true', help: 'Run a loop so that multiply queries may be run' })
1184
- parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
1185
- parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
1186
- parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
1187
- parser.add_argument('-cl', '--checkForLoop', { nargs: '?', help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
1188
- parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
1189
- parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1190
- parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
1191
- parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
1192
- parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
1193
- parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
1194
- parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
1195
- parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
1196
- parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, g === generators, s === semantics, l === load t=tests ordering p === priorities a == associations j == JSON sent to server. for example --print wb' })
1197
- parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
1198
- parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
1199
- parser.add_argument('-dl', '--debugLoops', { action: 'store_true', help: 'When running with the --debugLoops flag the logs calls to semantics and generators will be immediately written to the console ' })
1200
- parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
1201
- parser.add_argument('-da', '--debugAssociation', { action: 'store_true', help: helpDebugAssociation })
1202
- parser.add_argument('-dw', '--debugWord', { action: 'store_true', help: helpDebugWord })
1203
- parser.add_argument('-dh', '--debugHierarchy', { action: 'store_true', help: helpDebugHierarchy })
1204
- parser.add_argument('-dp', '--debugPriority', { action: 'store_true', help: helpDebugPriority })
1205
- parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
1206
- parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
1207
- parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
1208
- 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' })
1209
- 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' })
1210
-
1211
- const args = parser.parse_args()
1212
- args.count = args.count || 1
1213
-
1214
- if (args.rebuildTemplateFull) {
1215
- args.rebuildTemplate = true
1216
- }
1169
+ const helpDebugWord = 'In order to get a debug break when a specific word is created set the DEBUG_WORD environment variable to the JSON of the association to break on. For example DEBUG_WORD=\'"the"\''
1170
+ const helpDebugAssociation = 'In order to get a debug break when a specific association is created set the DEBUG_ASSOCIATION environment variable to the JSON of the association to break on. For example DEBUG_ASSOCIATION=\'[["the", 0], ["mammal", 1]]\''
1171
+ const helpDebugHierarchy = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_HIERARCHY environment variable to the JSON of the child-parent pair to break on. For example DEBUG_HIERARCHY=\'[["cat", 1], ["mammel", 1]]\''
1172
+ const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'[["verb", 0], ["article", 0]]\''
1173
+ const helpDebugContextualPriority = 'In order to get a debug break when a specific set of contextual priorities is created set set DEBUG_CONTEXTUAL_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_CONTEXTUAL_PRIORITY=\'{ context: [["verb", 0], ["article", 0], select: 1}\''
1174
+ const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id to break on. For example DEBUG_BRIDGE=\'car\''
1175
+ const helpDebugOperator = 'In order to get a debug break when a specific hierarcy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\''
1176
+
1177
+ parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
1178
+ parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
1179
+ 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' })
1180
+ // parser.add_argument('-ttr', '--testToRun', { help: 'Only the specified test will be run' })
1181
+ 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. if -q is specified the tests will be run for just the specified query.' })
1182
+ parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
1183
+ parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
1184
+ // parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
1185
+ parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild. Using optimization where if the query/config has not changed it will use the previous value. One there is a change all subsequence query/configs will be run.' })
1186
+ parser.add_argument('-rtf', '--rebuildTemplateFull', { action: 'store_true', help: 'Force a template rebuild. Skip the optimization' })
1187
+ parser.add_argument('-l', '--loop', { action: 'store_true', help: 'Run a loop so that multiply queries may be run' })
1188
+ parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
1189
+ parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
1190
+ parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
1191
+ parser.add_argument('-cl', '--checkForLoop', { nargs: '?', help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
1192
+ parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
1193
+ parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1194
+ parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
1195
+ parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
1196
+ parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
1197
+ parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
1198
+ parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
1199
+ parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
1200
+ parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, g === generators, s === semantics, l === load t=tests ordering p === priorities a == associations j == JSON sent to server. for example --print wb' })
1201
+ parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
1202
+ parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
1203
+ parser.add_argument('-dl', '--debugLoops', { action: 'store_true', help: 'When running with the --debugLoops flag the logs calls to semantics and generators will be immediately written to the console ' })
1204
+ parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
1205
+ parser.add_argument('-da', '--debugAssociation', { action: 'store_true', help: helpDebugAssociation })
1206
+ parser.add_argument('-dw', '--debugWord', { action: 'store_true', help: helpDebugWord })
1207
+ parser.add_argument('-dh', '--debugHierarchy', { action: 'store_true', help: helpDebugHierarchy })
1208
+ parser.add_argument('-dp', '--debugPriority', { action: 'store_true', help: helpDebugPriority })
1209
+ parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
1210
+ parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
1211
+ parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
1212
+ 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' })
1213
+ 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' })
1214
+
1215
+ const args = parser.parse_args()
1216
+ args.count = args.count || 1
1217
+
1218
+ if (args.rebuildTemplateFull) {
1219
+ args.rebuildTemplate = true
1220
+ }
1217
1221
 
1218
- // dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
1219
- if (args.rebuildTemplate) {
1220
- global.pauseDebugging = true
1221
- }
1222
+ // dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
1223
+ if (args.rebuildTemplate) {
1224
+ global.pauseDebugging = true
1225
+ }
1222
1226
 
1223
- const config = await createConfig()
1224
- setupConfig(config)
1225
- processResults = processResults({ config, errorHandler })
1227
+ config = await createConfig()
1228
+ setupConfig(config)
1229
+ processResults = processResults({ config, errorHandler })
1226
1230
 
1227
- if (args.rebuildTemplate) {
1228
- global.pauseDebugging = false
1229
- }
1231
+ if (args.rebuildTemplate) {
1232
+ global.pauseDebugging = false
1233
+ }
1230
1234
 
1231
- // setup();
1235
+ // setup();
1232
1236
 
1233
- if (args.parenthesized) {
1234
- config.parenthesized = true
1235
- }
1236
- if (args.checkForLoop) {
1237
- try {
1238
- args.checkForLoop = JSON.parse(args.checkForLoop)
1239
- const isKey = (what) => {
1240
- if (!Array.isArray(what)) {
1241
- return false
1242
- }
1243
- if (what.length !== 2) {
1244
- return false
1245
- }
1246
- if (!typeof what[0] == 'string') {
1247
- return false
1237
+ if (args.parenthesized) {
1238
+ config.parenthesized = true
1239
+ }
1240
+ if (args.checkForLoop) {
1241
+ try {
1242
+ args.checkForLoop = JSON.parse(args.checkForLoop)
1243
+ const isKey = (what) => {
1244
+ if (!Array.isArray(what)) {
1245
+ return false
1246
+ }
1247
+ if (what.length !== 2) {
1248
+ return false
1249
+ }
1250
+ if (!typeof what[0] == 'string') {
1251
+ return false
1252
+ }
1253
+ if (!typeof what[1] == 'number') {
1254
+ return false
1255
+ }
1256
+ return true
1248
1257
  }
1249
- if (!typeof what[1] == 'number') {
1250
- return false
1258
+ if (!Array.isArray(args.checkForLoop) || args.checkForLoop.some((value) => !isKey(value))) {
1259
+ throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
1251
1260
  }
1252
- return true
1253
- }
1254
- if (!Array.isArray(args.checkForLoop) || args.checkForLoop.some((value) => !isKey(value))) {
1261
+ } catch (e) {
1255
1262
  throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
1256
1263
  }
1257
- } catch (e) {
1258
- throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
1264
+ } else {
1265
+ if (process.argv.includes('--checkForLoop') || process.argv.includes('-cl')) {
1266
+ args.checkForLoop = true
1267
+ }
1259
1268
  }
1260
- } else {
1261
- if (process.argv.includes('--checkForLoop') || process.argv.includes('-cl')) {
1262
- args.checkForLoop = true
1269
+ if (args.debugAssociation) {
1270
+ console.log(helpDebugAssociation)
1271
+ runtime.process.exit(-1)
1272
+ }
1273
+ if (args.debugWord) {
1274
+ console.log(helpDebugWord)
1275
+ runtime.process.exit(-1)
1276
+ }
1277
+ if (args.debugHierarchy) {
1278
+ console.log(helpDebugHierarchy)
1279
+ runtime.process.exit(-1)
1280
+ }
1281
+ if (args.debugPriority) {
1282
+ console.log(helpDebugPriority)
1283
+ runtime.process.exit(-1)
1284
+ }
1285
+ if (args.debugBridge) {
1286
+ console.log(helpDebugBridge)
1287
+ runtime.process.exit(-1)
1288
+ }
1289
+ if (args.debugOperator) {
1290
+ console.log(helpDebugOperator)
1291
+ runtime.process.exit(-1)
1263
1292
  }
1264
- }
1265
- if (args.debugAssociation) {
1266
- console.log(helpDebugAssociation)
1267
- runtime.process.exit(-1)
1268
- }
1269
- if (args.debugWord) {
1270
- console.log(helpDebugWord)
1271
- runtime.process.exit(-1)
1272
- }
1273
- if (args.debugHierarchy) {
1274
- console.log(helpDebugHierarchy)
1275
- runtime.process.exit(-1)
1276
- }
1277
- if (args.debugPriority) {
1278
- console.log(helpDebugPriority)
1279
- runtime.process.exit(-1)
1280
- }
1281
- if (args.debugBridge) {
1282
- console.log(helpDebugBridge)
1283
- runtime.process.exit(-1)
1284
- }
1285
- if (args.debugOperator) {
1286
- console.log(helpDebugOperator)
1287
- runtime.process.exit(-1)
1288
- }
1289
1293
 
1290
- if (args.clean) {
1291
- const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1292
- for (const test of tests) {
1293
- delete test.associations
1294
+ if (args.clean) {
1295
+ const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1296
+ for (const test of tests) {
1297
+ delete test.associations
1298
+ }
1299
+ writeTestFile(testConfig.name, tests)
1300
+ console.log(`Cleaned ${testConfig.name}`)
1301
+ return
1294
1302
  }
1295
- writeTestFile(testConfig.name, tests)
1296
- console.log(`Cleaned ${testConfig.name}`)
1297
- return
1298
- }
1299
1303
 
1300
- if (args.deleteTest) {
1301
- let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1302
- tests = tests.filter((test) => test.query !== args.deleteTest)
1303
- writeTestFile(testConfig.name, tests)
1304
- console.log(`Remove the test for "${args.deleteTest}"`)
1305
- return
1306
- }
1304
+ if (args.deleteTest) {
1305
+ let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1306
+ tests = tests.filter((test) => test.query !== args.deleteTest)
1307
+ writeTestFile(testConfig.name, tests)
1308
+ console.log(`Remove the test for "${args.deleteTest}"`)
1309
+ return
1310
+ }
1307
1311
 
1308
- const options = { rebuild: false }
1309
- if (args.rebuildTemplate) {
1310
- options.rebuild = true
1311
- }
1312
- if (args.greg) {
1313
- config.server('http://localhost:3000', '6804954f-e56d-471f-bbb8-08e3c54d9321')
1314
- }
1315
- if (args.server) {
1316
- config.server(args.server)
1317
- }
1312
+ const options = { rebuild: false }
1313
+ if (args.rebuildTemplate) {
1314
+ options.rebuild = true
1315
+ }
1316
+ if (args.greg) {
1317
+ config.server('http://localhost:3000', '6804954f-e56d-471f-bbb8-08e3c54d9321')
1318
+ }
1319
+ if (args.server) {
1320
+ config.server(args.server)
1321
+ }
1318
1322
 
1319
- if (args.queryParams) {
1320
- config.setQueryParams(args.queryParams)
1321
- }
1323
+ if (args.queryParams) {
1324
+ config.setQueryParams(args.queryParams)
1325
+ }
1322
1326
 
1323
- if (args.debug) {
1324
- config.config.debug = true
1325
- }
1327
+ if (args.debug) {
1328
+ config.config.debug = true
1329
+ }
1326
1330
 
1327
- if (args.reset) {
1328
- config.config.skip_cache = true
1329
- }
1331
+ if (args.reset) {
1332
+ config.config.skip_cache = true
1333
+ }
1330
1334
 
1331
- if (args.explainPriorities) {
1332
- config.config.explain_priorities = true
1333
- }
1335
+ if (args.explainPriorities) {
1336
+ config.config.explain_priorities = true
1337
+ }
1334
1338
 
1335
- config.config.debugIncludeConvolutions = args.debugIncludeConvolutions || process.argv.includes('--debugIncludeConvolutions') || process.argv.includes('-dic')
1339
+ config.config.debugIncludeConvolutions = args.debugIncludeConvolutions || process.argv.includes('--debugIncludeConvolutions') || process.argv.includes('-dic')
1336
1340
 
1337
- let configPrinted = false
1338
- const printConfig = () => {
1339
- if (configPrinted) {
1340
- return
1341
- }
1342
- configPrinted = true
1343
- if (args.print) {
1344
- if (args.print.includes('t')) {
1345
- console.log('Test queries')
1346
- let counter = 0
1347
- for (const test of config.tests) {
1348
- console.log(`${counter} - ${test.query}`)
1349
- counter += 1
1350
- }
1351
- }
1352
- if (args.print.includes('c')) {
1353
- const { data } = setupProcessB({ config })
1354
- console.log('Config as sent to server')
1355
- console.log(JSON.stringify(data, null, 2))
1341
+ let configPrinted = false
1342
+ const printConfig = () => {
1343
+ if (configPrinted) {
1344
+ return
1356
1345
  }
1346
+ configPrinted = true
1347
+ if (args.print) {
1348
+ if (args.print.includes('t')) {
1349
+ console.log('Test queries')
1350
+ let counter = 0
1351
+ for (const test of config.tests) {
1352
+ console.log(`${counter} - ${test.query}`)
1353
+ counter += 1
1354
+ }
1355
+ }
1356
+ if (args.print.includes('c')) {
1357
+ const { data } = setupProcessB({ config })
1358
+ console.log('Config as sent to server')
1359
+ console.log(JSON.stringify(data, null, 2))
1360
+ }
1357
1361
 
1358
- if (args.print.includes('l')) {
1359
- console.log('Module load ordering')
1360
- for (const km of config.configs) {
1361
- console.log(` ${km.name}`)
1362
+ if (args.print.includes('l')) {
1363
+ console.log('Module load ordering')
1364
+ for (const km of config.configs) {
1365
+ console.log(` ${km.name}`)
1366
+ }
1362
1367
  }
1363
- }
1364
- if (args.print.includes('w')) {
1365
- // { literals: Object, patterns: Array(2), hierarchy: Array(97) }
1366
- console.log('literals')
1367
- for (const word in config.config.words.literals) {
1368
- console.log(' ' + word.concat(...config.config.words.literals[word].map((def, i) => ((i > 0) ? ' '.repeat(4+word.length) : ' ') + JSON.stringify(def) + '\n')))
1368
+ if (args.print.includes('w')) {
1369
+ // { literals: Object, patterns: Array(2), hierarchy: Array(97) }
1370
+ console.log('literals')
1371
+ for (const word in config.config.words.literals) {
1372
+ console.log(' ' + word.concat(...config.config.words.literals[word].map((def, i) => ((i > 0) ? ' '.repeat(4+word.length) : ' ') + JSON.stringify(def) + '\n')))
1373
+ }
1374
+ console.log('patterns')
1375
+ for (const pattern of config.config.words.patterns) {
1376
+ console.log(' ' + JSON.stringify(pattern))
1377
+ }
1369
1378
  }
1370
- console.log('patterns')
1371
- for (const pattern of config.config.words.patterns) {
1372
- console.log(' ' + JSON.stringify(pattern))
1379
+ if (args.print.includes('b')) {
1380
+ for (const bridge of config.config.bridges) {
1381
+ console.log(JSON.stringify(bridge))
1382
+ }
1373
1383
  }
1374
- }
1375
- if (args.print.includes('b')) {
1376
- for (const bridge of config.config.bridges) {
1377
- console.log(JSON.stringify(bridge))
1384
+ if (args.print.includes('o')) {
1385
+ for (const operator of config.config.operators) {
1386
+ console.log(JSON.stringify(operator))
1387
+ }
1378
1388
  }
1379
- }
1380
- if (args.print.includes('o')) {
1381
- for (const operator of config.config.operators) {
1382
- console.log(JSON.stringify(operator))
1389
+ if (args.print.includes('j')) {
1390
+ const { data } = setupProcessB({ config })
1391
+ console.log(JSON.stringify(data, null, 2))
1383
1392
  }
1384
- }
1385
- if (args.print.includes('j')) {
1386
- const { data } = setupProcessB({ config })
1387
- console.log(JSON.stringify(data, null, 2))
1388
- }
1389
- if (args.print.includes('a')) {
1390
- console.log('associations ================')
1391
- const properties = ['negative', 'positive']
1392
- for (const property of properties) {
1393
- console.log(` ${property} ===============`)
1394
- for (const association of config.config.associations[property]) {
1395
- console.log(` ${JSON.stringify(association)}`)
1393
+ if (args.print.includes('a')) {
1394
+ console.log('associations ================')
1395
+ const properties = ['negative', 'positive']
1396
+ for (const property of properties) {
1397
+ console.log(` ${property} ===============`)
1398
+ for (const association of config.config.associations[property]) {
1399
+ console.log(` ${JSON.stringify(association)}`)
1400
+ }
1396
1401
  }
1397
1402
  }
1398
- }
1399
- if (args.print.includes('d')) {
1400
- console.log(JSON.stringify(config.config.objects, null, 2))
1401
- }
1402
- if (args.print.includes('p')) {
1403
- for (const priority of config.config.priorities) {
1404
- console.log(JSON.stringify(priority))
1403
+ if (args.print.includes('d')) {
1404
+ console.log(JSON.stringify(config.config.objects, null, 2))
1405
1405
  }
1406
- }
1407
- if (args.print.includes('h')) {
1408
- for (const edge of config.config.hierarchy) {
1409
- console.log(JSON.stringify(edge))
1406
+ if (args.print.includes('p')) {
1407
+ for (const priority of config.config.priorities) {
1408
+ console.log(JSON.stringify(priority))
1409
+ }
1410
1410
  }
1411
- }
1412
- if (args.print.includes('g')) {
1413
- const easyToRead = _.cloneDeep(config.config.generators)
1414
- for (const semantic of easyToRead) {
1415
- semantic.match = semantic.match.toString()
1416
- semantic.apply = semantic.apply.toString()
1417
- if (semantic.applyWrapped) {
1418
- semantic.applyWrapped = semantic.applyWrapped.toString()
1411
+ if (args.print.includes('h')) {
1412
+ for (const edge of config.config.hierarchy) {
1413
+ console.log(JSON.stringify(edge))
1419
1414
  }
1420
1415
  }
1421
- console.dir(easyToRead)
1422
- }
1423
- if (args.print.includes('s')) {
1424
- const easyToRead = _.cloneDeep(config.config.semantics)
1425
- for (const semantic of easyToRead) {
1426
- semantic.match = semantic.match.toString()
1427
- semantic.apply = semantic.apply.toString()
1416
+ if (args.print.includes('g')) {
1417
+ const easyToRead = _.cloneDeep(config.config.generators)
1418
+ for (const semantic of easyToRead) {
1419
+ semantic.match = semantic.match.toString()
1420
+ semantic.apply = semantic.apply.toString()
1421
+ if (semantic.applyWrapped) {
1422
+ semantic.applyWrapped = semantic.applyWrapped.toString()
1423
+ }
1424
+ }
1425
+ console.dir(easyToRead)
1426
+ }
1427
+ if (args.print.includes('s')) {
1428
+ const easyToRead = _.cloneDeep(config.config.semantics)
1429
+ for (const semantic of easyToRead) {
1430
+ semantic.match = semantic.match.toString()
1431
+ semantic.apply = semantic.apply.toString()
1432
+ }
1433
+ console.dir(easyToRead)
1428
1434
  }
1429
- console.dir(easyToRead)
1430
1435
  }
1431
1436
  }
1432
- }
1433
1437
 
1434
- checkTemplate(template)
1438
+ checkTemplate(template)
1435
1439
 
1436
- if (template) {
1437
- let needsRebuild
1438
- if (args.rebuildTemplate && !args.rebuildTemplateFull) {
1439
- // get the startOfChanges for the partial rebuild
1440
- needsRebuild = config.needsRebuild(template.template, template.instance, { ...options, rebuild: false })
1441
- } else {
1442
- // do a check or full rebuild
1443
- needsRebuild = config.needsRebuild(template.template, template.instance, options)
1444
- }
1440
+ if (template) {
1441
+ let needsRebuild
1442
+ if (args.rebuildTemplate && !args.rebuildTemplateFull) {
1443
+ // get the startOfChanges for the partial rebuild
1444
+ needsRebuild = config.needsRebuild(template.template, template.instance, { ...options, rebuild: false })
1445
+ } else {
1446
+ // do a check or full rebuild
1447
+ needsRebuild = config.needsRebuild(template.template, template.instance, options)
1448
+ }
1445
1449
 
1446
- if (needsRebuild.needsRebuild) {
1447
- if (needsRebuild.previousResultss) {
1448
- console.log('Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf')
1450
+ if (needsRebuild.needsRebuild) {
1451
+ if (needsRebuild.previousResultss) {
1452
+ console.log('Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf')
1453
+ }
1454
+ console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
1455
+ options.rebuild = true
1456
+ config.config.rebuild = true
1457
+ }
1458
+ try {
1459
+ await config.load(rebuildTemplate, template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
1460
+ } catch (e) {
1461
+ console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
1462
+ runtime.process.exit(-1)
1463
+ }
1464
+ if (!args.query) {
1465
+ printConfig()
1466
+ }
1467
+ if (needsRebuild.needsRebuild) {
1468
+ return
1449
1469
  }
1450
- console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
1451
- options.rebuild = true
1452
- config.config.rebuild = true
1453
1470
  }
1454
- try {
1455
- await config.load(rebuildTemplate, template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
1456
- } catch (e) {
1457
- console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
1458
- runtime.process.exit(-1)
1471
+
1472
+ if (args.retrain) {
1473
+ config.config.retrain = true
1459
1474
  }
1460
- if (!args.query) {
1461
- printConfig()
1475
+
1476
+ if (args.saveDeveloper) {
1477
+ args.save = true
1462
1478
  }
1463
- if (needsRebuild.needsRebuild) {
1464
- return
1479
+ if (args.test || args.testVerbose || args.testAllVerbose || args.save) {
1480
+ global.transitoryMode = true
1465
1481
  }
1466
- }
1467
-
1468
- if (args.retrain) {
1469
- config.config.retrain = true
1470
- }
1471
-
1472
- if (args.saveDeveloper) {
1473
- args.save = true
1474
- }
1475
- if (args.test || args.testVerbose || args.testAllVerbose || args.save) {
1476
- global.transitoryMode = true
1477
- }
1478
- if (!args.query && !args.test && !args.info && (args.save || args.saveDeveloper)) {
1479
- global.transitoryMode = true
1480
- saveTests(config, test, testConfig, args.saveDeveloper)
1481
- // } else if (args.build) {
1482
- } else if (args.info) {
1483
- showInfo(description, section, config)
1484
- } else if (args.test || args.testVerbose || args.testAllVerbose) {
1485
- // TODO make test always a string
1486
- if (typeof test === 'string') {
1487
- const l = (n, hasError) => {
1488
- if (n === 0) {
1489
- if (hasError) {
1490
- runtime.process.exit(-1)
1482
+ if (!args.query && !args.test && !args.info && (args.save || args.saveDeveloper)) {
1483
+ global.transitoryMode = true
1484
+ saveTests(config, test, testConfig, args.saveDeveloper)
1485
+ // } else if (args.build) {
1486
+ } else if (args.info) {
1487
+ showInfo(description, section, config)
1488
+ } else if (args.test || args.testVerbose || args.testAllVerbose) {
1489
+ // TODO make test always a string
1490
+ if (typeof test === 'string') {
1491
+ const l = async (n, hasError) => {
1492
+ if (n === 0) {
1493
+ if (hasError) {
1494
+ runtime.process.exit(-1)
1495
+ }
1496
+ return
1491
1497
  }
1492
- return
1493
- }
1494
- let useTestConfig = testConfig
1495
- if (args.testModuleName) {
1496
- useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
1497
- useTestConfig.testModuleName = args.testModuleName
1498
- test = useTestConfig.name
1499
- }
1500
- runTests(config, test, { args, debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
1501
- let newError = false
1502
- if (results.length > 0) {
1503
- let headerShown = false
1504
-
1505
- let hasError = false
1506
- for (const result of results) {
1507
- if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1508
- result.hasError = true
1509
- }
1510
- if (!args.testNoParenthesized) {
1511
- if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1498
+ let useTestConfig = testConfig
1499
+ if (args.testModuleName) {
1500
+ useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
1501
+ useTestConfig.testModuleName = args.testModuleName
1502
+ test = useTestConfig.name
1503
+ }
1504
+ await runTests(config, test, { args, debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
1505
+ let newError = false
1506
+ if (results.length > 0) {
1507
+ let headerShown = false
1508
+
1509
+ let hasError = false
1510
+ for (const result of results) {
1511
+ if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1512
1512
  result.hasError = true
1513
1513
  }
1514
- if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1514
+ if (!args.testNoParenthesized) {
1515
+ if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1516
+ result.hasError = true
1517
+ }
1518
+ if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1519
+ result.hasError = true
1520
+ }
1521
+ }
1522
+ if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1515
1523
  result.hasError = true
1516
1524
  }
1525
+ if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1526
+ result.hasError = true
1527
+ }
1528
+ if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1529
+ result.hasError = true
1530
+ }
1531
+ if (result.hasError) {
1532
+ hasError = true
1533
+ }
1517
1534
  }
1518
- if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1519
- result.hasError = true
1520
- }
1521
- if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1522
- result.hasError = true
1523
- }
1524
- if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1525
- result.hasError = true
1526
- }
1527
- if (result.hasError) {
1528
- hasError = true
1529
- }
1530
- }
1531
1535
 
1532
- if (hasError) {
1533
- console.log('**************************** ERRORS ************************')
1534
- for (const result of results) {
1535
- console.log('Utterance: ', result.utterance)
1536
- const show = (label, expected, actual) => {
1537
- if (JSON.stringify(expected) !== JSON.stringify(actual)) {
1536
+ if (hasError) {
1537
+ console.log('**************************** ERRORS ************************')
1538
+ for (const result of results) {
1539
+ console.log('Utterance: ', result.utterance)
1540
+ const show = (label, expected, actual) => {
1541
+ if (JSON.stringify(expected) !== JSON.stringify(actual)) {
1542
+ if (!headerShown) {
1543
+ console.log(' Failure')
1544
+ }
1545
+ console.log(` expected ${label}`, expected)
1546
+ console.log(` actual ${label} `, actual)
1547
+ newError = true
1548
+ headerShown = true
1549
+ if (args.vimdiff) {
1550
+ vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
1551
+ }
1552
+ result.hasError = true
1553
+ }
1554
+ }
1555
+ show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
1556
+ if (!args.testNoParenthesized) {
1557
+ show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1558
+ }
1559
+ show('responses', result.expected.responses, result.actual.responses)
1560
+ if (!args.testNoParenthesized) {
1561
+ show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1562
+ }
1563
+ /*
1564
+ if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1538
1565
  if (!headerShown) {
1539
1566
  console.log(' Failure')
1540
1567
  }
1541
- console.log(` expected ${label}`, expected)
1542
- console.log(` actual ${label} `, actual)
1568
+ console.log(' expected paraphrases', result.expected.paraphrases)
1569
+ console.log(' actual paraphrases ', result.actual.paraphrases)
1543
1570
  newError = true
1544
1571
  headerShown = true
1545
- if (args.vimdiff) {
1546
- vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
1547
- }
1548
- result.hasError = true
1549
- }
1550
- }
1551
- show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
1552
- if (!args.testNoParenthesized) {
1553
- show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1554
- }
1555
- show('responses', result.expected.responses, result.actual.responses)
1556
- if (!args.testNoParenthesized) {
1557
- show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1558
- }
1559
- /*
1560
- if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1561
- if (!headerShown) {
1562
- console.log(' Failure')
1563
1572
  }
1564
- console.log(' expected paraphrases', result.expected.paraphrases)
1565
- console.log(' actual paraphrases ', result.actual.paraphrases)
1566
- newError = true
1567
- headerShown = true
1568
- }
1569
- if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1570
- if (!headerShown) {
1571
- console.log(' Failure')
1573
+ if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1574
+ if (!headerShown) {
1575
+ console.log(' Failure')
1576
+ }
1577
+ console.log(' expected responses ', result.expected.responses)
1578
+ console.log(' actual responses ', result.actual.responses)
1579
+ newError = true
1580
+ headerShown = true
1572
1581
  }
1573
- console.log(' expected responses ', result.expected.responses)
1574
- console.log(' actual responses ', result.actual.responses)
1575
- newError = true
1576
- headerShown = true
1577
- }
1578
- */
1579
- if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1580
- if (!headerShown) {
1581
- console.log(' Failure')
1582
+ */
1583
+ if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1584
+ if (!headerShown) {
1585
+ console.log(' Failure')
1586
+ }
1587
+ const widths = [4, 18, 72]
1588
+ const lines = new Lines(widths)
1589
+ lines.setElement(1, 1, 'expected checked objects')
1590
+ lines.setElement(2, 2, JSON.stringify(result.expected.checked, null, 2))
1591
+ lines.log()
1592
+ lines.setElement(1, 1, 'actual checked objects')
1593
+ lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
1594
+ lines.log()
1595
+ if (args.vimdiff) {
1596
+ show('checked properties for objects', result.expected.checked, result.actual.checked)
1597
+ }
1598
+ newError = true
1599
+ headerShown = true
1582
1600
  }
1583
- const widths = [4, 18, 72]
1584
- const lines = new Lines(widths)
1585
- lines.setElement(1, 1, 'expected checked objects')
1586
- lines.setElement(2, 2, JSON.stringify(result.expected.checked, null, 2))
1587
- lines.log()
1588
- lines.setElement(1, 1, 'actual checked objects')
1589
- lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
1590
- lines.log()
1591
- if (args.vimdiff) {
1592
- show('checked properties for objects', result.expected.checked, result.actual.checked)
1601
+ if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1602
+ if (!headerShown) {
1603
+ console.log(' Failure')
1604
+ }
1605
+ const widths = [4, 18, 72]
1606
+ const lines = new Lines(widths)
1607
+ lines.setElement(1, 1, 'expected checked contexts', true)
1608
+ lines.setElement(2, 2, JSON.stringify(result.expected.checkedContexts, null, 2))
1609
+ lines.log()
1610
+ lines.setElement(1, 1, 'actual checked contexts', true)
1611
+ lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
1612
+ lines.log()
1613
+ if (args.vimdiff) {
1614
+ show('checked properties for context', result.expected.checkedContexts, result.actual.checkedContexts)
1615
+ }
1616
+ newError = true
1617
+ headerShown = true
1593
1618
  }
1594
- newError = true
1595
- headerShown = true
1596
1619
  }
1597
- if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1598
- if (!headerShown) {
1599
- console.log(' Failure')
1620
+ } else {
1621
+ if (results.length > 0 && args.vimdiff) {
1622
+ for (const result of results) {
1623
+ vimdiff(result.actual, result.expected)
1600
1624
  }
1601
- const widths = [4, 18, 72]
1602
- const lines = new Lines(widths)
1603
- lines.setElement(1, 1, 'expected checked contexts', true)
1604
- lines.setElement(2, 2, JSON.stringify(result.expected.checkedContexts, null, 2))
1605
- lines.log()
1606
- lines.setElement(1, 1, 'actual checked contexts', true)
1607
- lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
1608
- lines.log()
1609
- if (args.vimdiff) {
1610
- show('checked properties for context', result.expected.checkedContexts, result.actual.checkedContexts)
1611
- }
1612
- newError = true
1613
- headerShown = true
1614
1625
  }
1615
1626
  }
1616
- } else {
1617
- if (results.length > 0 && args.vimdiff) {
1618
- for (const result of results) {
1619
- vimdiff(result.actual, result.expected)
1627
+ if (hasError) {
1628
+ if (!headerShown) {
1629
+ if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1630
+ 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.')
1631
+ }
1620
1632
  }
1621
- }
1622
- }
1623
- if (hasError) {
1624
- if (!headerShown) {
1625
1633
  if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1626
- 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.')
1627
- }
1628
- }
1629
- if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1630
- 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.')
1631
- // console.log(JSON.stringify(contexts))
1632
- let errorCount = 0
1633
- for (const result of results) {
1634
- if (result.hasError) {
1635
- errorCount += 1
1634
+ 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.')
1635
+ // console.log(JSON.stringify(contexts))
1636
+ let errorCount = 0
1637
+ for (const result of results) {
1638
+ if (result.hasError) {
1639
+ errorCount += 1
1640
+ }
1636
1641
  }
1642
+ console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
1637
1643
  }
1638
- console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
1639
1644
  }
1640
1645
  }
1641
- }
1642
- // const contexts = { failures: results }
1643
- l(n - 1, hasError || newError)
1644
- }).catch((error) => {
1645
- console.error(error)
1646
- runtime.process.exit(-1)
1647
- errorHandler(error)
1646
+ // const contexts = { failures: results }
1647
+ l(n - 1, hasError || newError)
1648
+ }).catch((error) => {
1649
+ console.error(error)
1650
+ runtime.process.exit(-1)
1651
+ errorHandler(error)
1652
+ })
1653
+ }
1654
+ await l(args.count, false)
1655
+ } else {
1656
+ test()
1657
+ }
1658
+ } else if (args.loop) {
1659
+ const readline = runtime.readline.createInterface({ input: runtime.process.stdin, output: runtime.process.stdout })
1660
+ const f = () => readline.question('Enter query? (newline to quit) ', query => {
1661
+ query = query.trim()
1662
+ if (query.length === 0) {
1663
+ return readline.close()
1664
+ }
1665
+ const promise = _process(config, query, { testsFN: test }).then((results) => {
1666
+ console.log(results.responses.join(' '))
1648
1667
  })
1668
+ if (!('then' in promise)) {
1669
+ throw new Error('Return a promise from process in the definition of knowledgeModule')
1670
+ }
1671
+ promise
1672
+ .then(() => {
1673
+ f()
1674
+ })
1675
+ .catch((e) => {
1676
+ if (e.errno == 'ECONNREFUSED') {
1677
+ console.log(e)
1678
+ readline.close()
1679
+ } else {
1680
+ console.log(e)
1681
+ f()
1682
+ }
1683
+ })
1684
+ })
1685
+ f()
1686
+ } else if (args.query) {
1687
+ let useTestConfig = testConfig
1688
+ if (args.testModuleName) {
1689
+ config.testConfig.testModuleName = args.testModuleName
1690
+ config.testConfig.checks = config.getConfigs()[args.testModuleName].getTestConfig().checks
1691
+ // useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
1692
+ // useTestConfig.testModuleName = args.testModuleName
1649
1693
  }
1650
- l(args.count, false)
1651
- } else {
1652
- test()
1653
- }
1654
- } else if (args.loop) {
1655
- const readline = runtime.readline.createInterface({ input: runtime.process.stdin, output: runtime.process.stdout })
1656
- const f = () => readline.question('Enter query? (newline to quit) ', query => {
1657
- query = query.trim()
1658
- if (query.length === 0) {
1659
- return readline.close()
1694
+ const objects = getObjects(config.config.objects)(config.uuid)
1695
+ // for the compare
1696
+ if (args.objectDiff) {
1697
+ global.beforeObjects = _.cloneDeep(objects)
1660
1698
  }
1661
- const promise = _process(config, query, { testsFN: test }).then((results) => {
1662
- console.log(results.responses.join(' '))
1663
- })
1664
- if (!('then' in promise)) {
1665
- throw new Error('Return a promise from process in the definition of knowledgeModule')
1699
+ try {
1700
+ await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1701
+ } catch (error) {
1702
+ console.log('Error', error)
1666
1703
  }
1667
- promise
1668
- .then(() => {
1669
- f()
1670
- })
1671
- .catch((e) => {
1672
- if (e.errno == 'ECONNREFUSED') {
1673
- console.log(e)
1674
- readline.close()
1675
- } else {
1676
- console.log(e)
1677
- f()
1678
- }
1679
- })
1680
- })
1681
- f()
1682
- } else if (args.query) {
1683
- let useTestConfig = testConfig
1684
- if (args.testModuleName) {
1685
- config.testConfig.testModuleName = args.testModuleName
1686
- config.testConfig.checks = config.getConfigs()[args.testModuleName].getTestConfig().checks
1687
- // useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
1688
- // useTestConfig.testModuleName = args.testModuleName
1689
1704
  }
1690
- const objects = getObjects(config.config.objects)(config.uuid)
1691
- // for the compare
1692
- if (args.objectDiff) {
1693
- global.beforeObjects = _.cloneDeep(objects)
1694
- }
1695
- try {
1696
- await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1697
- } catch (error) {
1698
- console.log('Error', error)
1705
+ printConfig()
1706
+ } finally {
1707
+ debugger
1708
+ if (config) {
1709
+ config.terminate()
1699
1710
  }
1700
1711
  }
1701
- printConfig()
1702
1712
  } else {
1703
1713
  const initConfig = async (config) => {
1704
1714
  if (template) {
package/package.json CHANGED
@@ -65,6 +65,6 @@
65
65
  "sort-json": "^2.0.0",
66
66
  "uuid": "^8.3.2"
67
67
  },
68
- "version": "8.0.0-beta.60",
68
+ "version": "8.0.0-beta.62",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -1807,6 +1807,24 @@ class Config {
1807
1807
  config.words.hierarchy = hierarchyPrime
1808
1808
  }
1809
1809
 
1810
+ terminate() {
1811
+ this.configs.forEach((km) => {
1812
+ const config = km.config
1813
+ debugger
1814
+ if (!config.terminatorFn) {
1815
+ this.terminatorFn(this)
1816
+ } else {
1817
+ config.terminatorFn(this)
1818
+ }
1819
+ })
1820
+ }
1821
+
1822
+ setTerminator(terminatorFn) {
1823
+ if (terminatorFn) {
1824
+ this.terminatorFn = terminatorFn
1825
+ }
1826
+ }
1827
+
1810
1828
  // configs = [ { config, namespace } ... ]
1811
1829
  constructor (config, module, clientProcess) {
1812
1830
  if (config instanceof Config) {
@@ -1873,6 +1891,7 @@ class Config {
1873
1891
  currentConfig.wasInitialized = true
1874
1892
  }
1875
1893
  }
1894
+ this.terminatorFn = () => {}
1876
1895
  if (config) {
1877
1896
  this.name = config.name
1878
1897
  }
@@ -2080,6 +2099,7 @@ class Config {
2080
2099
  cp._uuid = cp.configs[0]._uuid
2081
2100
  // update uuid here set the uuid in the objects and add error checking
2082
2101
  cp.initializerFn = this.initializerFn
2102
+ cp.terminatorFn = this.terminatorFn
2083
2103
  // cp._api = _.cloneDeep(this._api)
2084
2104
  if (this._apiConstructor) {
2085
2105
  cp._api = this._apiConstructor(cp)