theprogrammablemind 7.10.0-beta.9 → 7.10.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict"
2
-
3
1
  const { Semantics, Semantic } = require('./src/semantics')
4
2
  const { Generators, Generator } = require('./src/generators')
5
3
  const DigraphInternal = require('./src/digraph_internal')
@@ -34,7 +32,7 @@ const pickObjects = (testConfig, objects) => {
34
32
 
35
33
  // move ask to the KM's since verbatim is called
36
34
  const getAsk = (config) => (uuid) => (asks) => {
37
- for (let ask of asks) {
35
+ for (const ask of asks) {
38
36
  let oneShot = true // default
39
37
  if (ask.oneShot === false) {
40
38
  oneShot = false
@@ -47,41 +45,41 @@ const getAsk = (config) => (uuid) => (asks) => {
47
45
  })
48
46
  }
49
47
  let oneShot = true
50
- for (let ask of asks) {
48
+ for (const ask of asks) {
51
49
  if (ask.oneShot === false) {
52
50
  oneShot = false
53
51
  }
54
52
  }
55
53
  config.addSemantic({
56
- uuid,
57
- oneShot,
58
- match: ({context}) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
59
- apply: (args) => {
60
- for (let ask of asks) {
61
- let matchq = ask.matchq
62
- let applyq = ask.applyq
63
- if (!matchq) {
64
- let wasAsked = false
65
- matchq = () => !wasAsked,
66
- applyq = (args) => {
67
- wasAsked = true
68
- applyq(args)
69
- }
54
+ uuid,
55
+ oneShot,
56
+ match: ({ context }) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
57
+ apply: (args) => {
58
+ for (const ask of asks) {
59
+ let matchq = ask.matchq
60
+ let applyq = ask.applyq
61
+ if (!matchq) {
62
+ let wasAsked = false
63
+ matchq = () => !wasAsked,
64
+ applyq = (args) => {
65
+ wasAsked = true
66
+ applyq(args)
70
67
  }
71
- if (matchq(args)) {
72
- // args.context.motivationKeep = true
73
- args.verbatim(applyq(args))
74
- /*
68
+ }
69
+ if (matchq(args)) {
70
+ // args.context.motivationKeep = true
71
+ args.verbatim(applyq(args))
72
+ /*
75
73
  args.context.verbatim = applyq(args)
76
74
  args.context.isResponse = true;
77
75
  delete args.context.controlRemove;
78
76
  */
79
- args.context.controlKeepMotivation = true;
80
- break
81
- }
77
+ args.context.controlKeepMotivation = true
78
+ break
82
79
  }
83
- args.context.cascade = true
84
80
  }
81
+ args.context.cascade = true
82
+ }
85
83
  })
86
84
  }
87
85
 
@@ -102,7 +100,7 @@ const vimdiff = (actualJSON, expectedJSON) => {
102
100
  const editor = runtime.process.env.EDITOR || 'vimdiff'
103
101
  // const child = runtime.child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
104
102
  console.log(`${editor} ${path}/expected.json ${path}/actual.json`)
105
- runtime.child_process.execSync(`${editor} ${path}/expected.json ${path}/actual.json`, {stdio: 'inherit'})
103
+ runtime.child_process.execSync(`${editor} ${path}/expected.json ${path}/actual.json`, { stdio: 'inherit' })
106
104
  }
107
105
  }
108
106
 
@@ -142,10 +140,10 @@ const asList = (context) => {
142
140
  }
143
141
 
144
142
  class ErrorReason extends Error {
145
- constructor(context) {
146
- super(JSON.stringify(context))
147
- this.reason = context
148
- }
143
+ constructor (context) {
144
+ super(JSON.stringify(context))
145
+ this.reason = context
146
+ }
149
147
  }
150
148
 
151
149
  const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
@@ -180,7 +178,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
180
178
  }
181
179
  }
182
180
  args.getUUIDScoped = (uuid) => {
183
- return {
181
+ return {
184
182
  ask: scopedAsk(uuid),
185
183
  api: getAPI(uuid),
186
184
  apis: getAPIs(uuid)
@@ -206,10 +204,10 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
206
204
  return config.getGenerators(logs).apply(addAssumed(args, a), c, a)
207
205
  }
208
206
  args.gp = (c, a = {}) => {
209
- return config.getGenerators(logs).apply(addAssumed(args, a, {paraphrase: true, isResponse: false, response: false}), c, {paraphrase: true, isResponse: false, response: false})
207
+ return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: true, isResponse: false, response: false }), c, { paraphrase: true, isResponse: false, response: false })
210
208
  }
211
209
  args.gr = (c, a = {}) => {
212
- return config.getGenerators(logs).apply(addAssumed(args, a, {paraphrase: false, isResponse: true}), { ...c, paraphrase: false, isResponse: true })
210
+ return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true })
213
211
  }
214
212
  args.e = (c) => {
215
213
  return config.getEvaluator(args.s, args.calls, logs, c)
@@ -226,7 +224,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
226
224
  const gs = (g) => (contexts, separator, lastSeparator) => {
227
225
  if (!Array.isArray(contexts)) {
228
226
  debugger
229
- throw new Error("Expected a list")
227
+ throw new Error('Expected a list')
230
228
  }
231
229
 
232
230
  let s = ''
@@ -290,10 +288,10 @@ const processContexts = (contexts, params) => {
290
288
 
291
289
  const getObjects = (objects) => {
292
290
  return (uuid) => {
293
- if (objects && objects.namespaced) {
294
- return objects.namespaced[uuid]
295
- }
296
- return objects
291
+ if (objects && objects.namespaced) {
292
+ return objects.namespaced[uuid]
293
+ }
294
+ return objects
297
295
  }
298
296
  }
299
297
 
@@ -318,7 +316,7 @@ const processContext = (context, { objects = {}, config, logs = [] }) => {
318
316
  context = semantics.apply(args, context)
319
317
  const generated = generators.apply(args, context)
320
318
  const assumed = { paraphrase: true, response: false, isResponse: false }
321
- const paraphrases = generators.apply({...args, assumed}, context, { paraphrase: true, response: false, isResponse: false })
319
+ const paraphrases = generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
322
320
  let responses = []
323
321
  if (context.isResponse) {
324
322
  responses = generated
@@ -343,7 +341,7 @@ const convertToStable = (objects) => {
343
341
 
344
342
  const writeTestFile = (fn, tests) => {
345
343
  const stabilize = (tests) => {
346
- for (let test of tests) {
344
+ for (const test of tests) {
347
345
  for (opChoice of test.metadata.opChoices) {
348
346
  opChoice.ops.sort()
349
347
  }
@@ -359,30 +357,31 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
359
357
  if (runtime.fs.existsSync(fn)) {
360
358
  tests = JSON.parse(runtime.fs.readFileSync(fn))
361
359
  }
362
- for (let association of associations) {
360
+ for (const association of associations) {
363
361
  association.sort()
364
362
  }
365
363
  associations.sort()
366
364
  // tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
367
- const results = sortJson({
368
- query,
369
- paraphrases,
370
- responses,
371
- contexts,
372
- objects: convertToStable(objects),
373
- associations,
374
- metadata,
375
- config,
376
- developerTest: saveDeveloper,
377
- paraphrasesParenthesized,
378
- generatedParenthesized }, { depth: 25 })
379
- let wasSet = false;
380
- tests.forEach( (test, index) => {
365
+ const results = sortJson({
366
+ query,
367
+ paraphrases,
368
+ responses,
369
+ contexts,
370
+ objects: convertToStable(objects),
371
+ associations,
372
+ metadata,
373
+ config,
374
+ developerTest: saveDeveloper,
375
+ paraphrasesParenthesized,
376
+ generatedParenthesized
377
+ }, { depth: 25 })
378
+ let wasSet = false
379
+ tests.forEach((test, index) => {
381
380
  if (test.query == query) {
382
381
  tests[index] = results
383
382
  wasSet = true
384
383
  }
385
- });
384
+ })
386
385
  if (!wasSet) {
387
386
  tests.push(results)
388
387
  }
@@ -391,7 +390,7 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
391
390
  }
392
391
 
393
392
  const combineRange = (r1, r2) => {
394
- let start = r2.start;
393
+ let start = r2.start
395
394
  if (r1.start < r2.start) {
396
395
  start = r1.start
397
396
  }
@@ -404,14 +403,14 @@ const combineRange = (r1, r2) => {
404
403
 
405
404
  const overlaps = (r1, context) => {
406
405
  if (!context.range) {
407
- return true;
406
+ return true
408
407
  }
409
408
  const r2 = context.range
410
409
  if (r1.start <= r2.end && r1.start >= r2.start) {
411
- return true;
410
+ return true
412
411
  }
413
412
  if (r1.end <= r2.end && r1.end >= r2.start) {
414
- return true;
413
+ return true
415
414
  }
416
415
  return false
417
416
  }
@@ -450,7 +449,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
450
449
  setupArgs(args, config, json.logs, hierarchy)
451
450
  const toDo = [...contexts]
452
451
  args.insert = (context) => toDo.unshift(context)
453
- let overlap, lastRange;
452
+ let overlap, lastRange
454
453
  config.debugLoops = commandLineArgs && commandLineArgs.debugLoops
455
454
  while (toDo.length > 0) {
456
455
  const context = toDo.shift()
@@ -466,7 +465,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
466
465
  const semantics = config.getSemantics(json.logs)
467
466
  try {
468
467
  contextPrime = semantics.apply(args, context)
469
- } catch( e ) {
468
+ } catch (e) {
470
469
  if (e.message == 'Maximum call stack size exceeded') {
471
470
  const mostCalled = semantics.getMostCalled()
472
471
  e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
@@ -475,36 +474,36 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
475
474
  if (isInstance) {
476
475
  console.log('error', e.error)
477
476
  }
478
- contextPrime = semantics.apply(args, {
479
- marker: 'error',
480
- context,
481
- text: e ? e.toString() : 'not available',
482
- reason: e.reason,
483
- error: e.stack || e.error
484
- })
477
+ contextPrime = semantics.apply(args, {
478
+ marker: 'error',
479
+ context,
480
+ text: e ? e.toString() : 'not available',
481
+ reason: e.reason,
482
+ error: e.stack || e.error
483
+ })
485
484
  }
486
485
  }
487
486
  if (contextPrime.controlRemove) {
488
487
  continue
489
488
  }
490
- let assumed = { isResponse: true };
491
- const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed) : ''
489
+ let assumed = { isResponse: true }
490
+ const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
492
491
  let generatedParenthesized = []
493
492
  if (generateParenthesized) {
494
493
  config.parenthesized = true
495
- generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed) : ''
494
+ generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
496
495
  config.parenthesized = false
497
496
  }
498
497
  // assumed = { paraphrase: true, response: false };
499
- assumed = { paraphrase: true, isResponse: false, response: false };
498
+ assumed = { paraphrase: true, isResponse: false, response: false }
500
499
  if (generateParenthesized) {
501
500
  config.parenthesized = false
502
501
  }
503
- const paraphrases = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
502
+ const paraphrases = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
504
503
  let paraphrasesParenthesized = []
505
504
  if (generateParenthesized) {
506
505
  config.parenthesized = true
507
- paraphrasesParenthesized = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
506
+ paraphrasesParenthesized = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
508
507
  config.parenthesized = false
509
508
  }
510
509
  contextsPrime.push(contextPrime)
@@ -580,7 +579,7 @@ const doWithRetries = async (n, url, queryParams, data) => {
580
579
  }
581
580
  }
582
581
 
583
- const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
582
+ const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
584
583
  const key = config._key
585
584
 
586
585
  const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
@@ -593,8 +592,8 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
593
592
  }
594
593
 
595
594
  // config.toServer(data)
596
-
597
- if (data.namespaces) {
595
+
596
+ if (data.namespaces) {
598
597
  for (const uuid of Object.keys(data.namespaces)) {
599
598
  const km = config.configs.find((km) => km.uuid === uuid)
600
599
  data.namespaces[uuid].name = km.name
@@ -639,7 +638,7 @@ const loadInstance = (config, instance) => {
639
638
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
640
639
  // config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
641
640
  const uuid = config.nameToUUID(instance.name)
642
- config.addInternal(instance.template.queries[i], { uuid, addFirst: true, handleCalculatedProps: true } )
641
+ config.addInternal(_.cloneDeep(instance.template.queries[i]), { uuid, addFirst: true, handleCalculatedProps: true })
643
642
  } else if (results.apply) {
644
643
  const objects = config.get('objects')
645
644
  const args = { objects, getObjects: getObjects(objects) }
@@ -688,7 +687,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
688
687
  config.rebuild()
689
688
  const objects = getObjects(config.config.objects)(config.uuid)
690
689
  }
691
- } catch(error) {
690
+ } catch (error) {
692
691
  throw error
693
692
  }
694
693
 
@@ -718,12 +717,12 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
718
717
  paraphrasesParenthesized: [],
719
718
  generatedParenthesized: [],
720
719
  responses: [],
721
- associations: [],
720
+ associations: []
722
721
  }
723
722
 
724
723
  while (true) {
725
724
  if (queries.length === 0) {
726
- break;
725
+ break
727
726
  }
728
727
 
729
728
  data.utterance = queries[0]
@@ -789,18 +788,18 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
789
788
 
790
789
  if (writeTests) {
791
790
  const actual_config = getConfigForTest(config, testConfig)
792
- const saveObjects = {...config.config.objects}
791
+ const saveObjects = { ...config.config.objects }
793
792
  saveObjects.nameToUUID = {}
794
- for (let km of config.configs) {
793
+ for (const km of config.configs) {
795
794
  saveObjects.nameToUUID[km.name] = km.uuid
796
795
  }
797
796
  writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized)
798
797
  }
799
798
 
800
799
  return response
801
- } catch(error) {
802
- error.query = query
803
- errorHandler(error)
800
+ } catch (error) {
801
+ error.query = query
802
+ errorHandler(error)
804
803
  }
805
804
  }
806
805
 
@@ -855,110 +854,110 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
855
854
  objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
856
855
  testConfigName = testConfig.testModuleName
857
856
  }
858
- try {
859
- const result = await _process(config, test, { errorHandler, isTest: true })
860
- result.query = test
861
- if (debug) {
862
- defaultInnerProcess(config, errorHandler, result)
863
- }
864
- if (verbose) {
865
- const widths = [100, 60]
866
- const lines = new Lines(widths)
867
- lines.setElement(0, 0, test)
868
- lines.setElement(0, 1, `time on server: ${result.times.toFixed(2)} client: ${(result.clientSideTimes/1000).toFixed(2)}`)
869
- lines.log()
870
- }
871
- const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
872
- delete expected_objects.nameToUUID
873
- const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
874
- const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
875
- let failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
876
- let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
877
- // TODO fix the naming conventions: camelcase + use actual instead of result
878
- const failed_responses = !matching(result.responses, expected.responses)
879
- const failed_contexts = !matching(result.contexts, expected.contexts)
880
- const failed_objects = !matching(actual_objects, expected_objects)
881
-
882
- if (args.testNoParenthesized) {
883
- failed_paraphrasesParenthesized = false
884
- failed_generatedParenthesized = false
885
- }
886
-
887
- const pickedResultContexts = result.contexts.map(pickContext(testConfig))
888
- const pickedExpectedContexts = expected.contexts.map(pickContext(testConfig))
889
- const failedCheckedContexts = !matching(pickedResultContexts, pickedExpectedContexts)
890
-
891
- const expectedGetObjects = (name) => {
892
- if (!name) {
893
- name = config.name
894
- }
895
- return expected.objects.namespaced[expected.objects.nameToUUID[name]] || {}
896
- }
897
- const expected_checked = sortJson(pickObjects(testConfig, expectedGetObjects(testConfigName)), { depth: 25 })
898
- const actualGetObjects = (name) => {
899
- if (!name) {
900
- name = config.name
901
- }
902
- const km = config.configs.find( (km) => km.name == name )
903
- return config.config.objects.namespaced[km.uuid] || {}
904
- }
905
- const actual_checked = sortJson(pickObjects(testConfig, actualGetObjects(testConfigName)), { depth: 25 })
906
- const failed_checked = !matching(actual_objects, expected_objects)
907
-
908
- const failed_checks = !matching(actual_objects, expected_objects)
909
- const failed_checked_objects = !matching(actual_checked, expected_checked)
910
- const actual_config = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
911
- const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
912
- const failed_config = !matching(actual_config, expected_config)
913
- let failed = failed_checked_objects || failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked || failedCheckedContexts
914
-
915
- if (expected.metadata && result.metadata && failed) {
916
- const priorities = analyzeMetaData(expected.metadata, result.metadata)
917
- if (priorities.length > 0) {
918
- const log = `Hint, if the results are flakey try adding the specified priorities ${JSON.stringify(priorities)}`
919
- result.logs.push(log)
920
- }
921
- }
922
- if (failed) {
923
- return {
924
- utterance: test,
925
- expected: {
926
- responses: expected.responses,
927
- paraphrases: expected.paraphrases,
928
- paraphrasesParenthesized: expected.paraphrasesParenthesized,
929
- generatedParenthesized: expected.generatedParenthesized,
930
- results: expected.contexts,
931
- checked: expected_checked,
932
- checkedContexts: pickedExpectedContexts,
933
- objects: expected_objects,
934
- config: expected.config
935
- },
936
- actual: {
937
- responses: result.responses,
938
- paraphrases: result.paraphrases,
939
- paraphrasesParenthesized: result.paraphrasesParenthesized,
940
- generatedParenthesized: result.generatedParenthesized,
941
- results: result.contexts,
942
- checked: actual_checked,
943
- checkedContexts: pickedResultContexts,
944
- objects: actual_objects,
945
- config: actual_config
946
- }
857
+ try {
858
+ const result = await _process(config, test, { errorHandler, isTest: true })
859
+ result.query = test
860
+ if (debug) {
861
+ defaultInnerProcess(config, errorHandler, result)
862
+ }
863
+ if (verbose) {
864
+ const widths = [100, 60]
865
+ const lines = new Lines(widths)
866
+ lines.setElement(0, 0, test)
867
+ lines.setElement(0, 1, `time on server: ${result.times.toFixed(2)} client: ${(result.clientSideTimes / 1000).toFixed(2)}`)
868
+ lines.log()
869
+ }
870
+ const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
871
+ delete expected_objects.nameToUUID
872
+ const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
873
+ const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
874
+ let failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
875
+ let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
876
+ // TODO fix the naming conventions: camelcase + use actual instead of result
877
+ const failed_responses = !matching(result.responses, expected.responses)
878
+ const failed_contexts = !matching(result.contexts, expected.contexts)
879
+ const failed_objects = !matching(actual_objects, expected_objects)
880
+
881
+ if (args.testNoParenthesized) {
882
+ failed_paraphrasesParenthesized = false
883
+ failed_generatedParenthesized = false
884
+ }
885
+
886
+ const pickedResultContexts = result.contexts.map(pickContext(testConfig))
887
+ const pickedExpectedContexts = expected.contexts.map(pickContext(testConfig))
888
+ const failedCheckedContexts = !matching(pickedResultContexts, pickedExpectedContexts)
889
+
890
+ const expectedGetObjects = (name) => {
891
+ if (!name) {
892
+ name = config.name
893
+ }
894
+ return expected.objects.namespaced[expected.objects.nameToUUID[name]] || {}
895
+ }
896
+ const expected_checked = sortJson(pickObjects(testConfig, expectedGetObjects(testConfigName)), { depth: 25 })
897
+ const actualGetObjects = (name) => {
898
+ if (!name) {
899
+ name = config.name
900
+ }
901
+ const km = config.configs.find((km) => km.name == name)
902
+ return config.config.objects.namespaced[km.uuid] || {}
903
+ }
904
+ const actual_checked = sortJson(pickObjects(testConfig, actualGetObjects(testConfigName)), { depth: 25 })
905
+ const failed_checked = !matching(actual_objects, expected_objects)
906
+
907
+ const failed_checks = !matching(actual_objects, expected_objects)
908
+ const failed_checked_objects = !matching(actual_checked, expected_checked)
909
+ const actual_config = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
910
+ const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
911
+ const failed_config = !matching(actual_config, expected_config)
912
+ const failed = failed_checked_objects || failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked || failedCheckedContexts
913
+
914
+ if (expected.metadata && result.metadata && failed) {
915
+ const priorities = analyzeMetaData(expected.metadata, result.metadata)
916
+ if (priorities.length > 0) {
917
+ const log = `Hint, if the results are flakey try adding the specified priorities ${JSON.stringify(priorities)}`
918
+ result.logs.push(log)
919
+ }
920
+ }
921
+ if (failed) {
922
+ return {
923
+ utterance: test,
924
+ expected: {
925
+ responses: expected.responses,
926
+ paraphrases: expected.paraphrases,
927
+ paraphrasesParenthesized: expected.paraphrasesParenthesized,
928
+ generatedParenthesized: expected.generatedParenthesized,
929
+ results: expected.contexts,
930
+ checked: expected_checked,
931
+ checkedContexts: pickedExpectedContexts,
932
+ objects: expected_objects,
933
+ config: expected.config
934
+ },
935
+ actual: {
936
+ responses: result.responses,
937
+ paraphrases: result.paraphrases,
938
+ paraphrasesParenthesized: result.paraphrasesParenthesized,
939
+ generatedParenthesized: result.generatedParenthesized,
940
+ results: result.contexts,
941
+ checked: actual_checked,
942
+ checkedContexts: pickedResultContexts,
943
+ objects: actual_objects,
944
+ config: actual_config
947
945
  }
948
946
  }
949
- } catch(error) {
950
- if (verbose) {
951
- console.log(test)
952
- }
953
- if (error.metadata) {
954
- const priorities = analyzeMetaData(expected.metadata, error.metadata)
955
- if (priorities.length > 0) {
956
- const log = `Hint, if the results are flakey try adding the specified priorities ${JSON.stringify(priorities)}`
957
- error.logs.push(log)
958
- }
947
+ }
948
+ } catch (error) {
949
+ if (verbose) {
950
+ console.log(test)
951
+ }
952
+ if (error.metadata) {
953
+ const priorities = analyzeMetaData(expected.metadata, error.metadata)
954
+ if (priorities.length > 0) {
955
+ const log = `Hint, if the results are flakey try adding the specified priorities ${JSON.stringify(priorities)}`
956
+ error.logs.push(log)
959
957
  }
960
- throw error
961
958
  }
959
+ throw error
960
+ }
962
961
  }
963
962
 
964
963
  const runTestsHelper = async (config, tests, failed, juicyBits) => {
@@ -996,9 +995,9 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
996
995
  const actualConfig = getConfigForTest(config, testConfig)
997
996
  const args = {
998
997
  }
999
- const saveObjects = {...config.config.objects}
998
+ const saveObjects = { ...config.config.objects }
1000
999
  saveObjects.nameToUUID = {}
1001
- for (let km of config.configs) {
1000
+ for (const km of config.configs) {
1002
1001
  saveObjects.nameToUUID[km.name] = km.uuid
1003
1002
  }
1004
1003
  writeTest(testFile, test, saveObjects, result.generated, result.paraphrases, result.responses, result.contexts, result.associations, result.metadata, actualConfig, saveDeveloper, result.paraphrasesParenthesized, result.generatedParenthesized)
@@ -1020,7 +1019,7 @@ const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDe
1020
1019
  const saveTests = (config, testFile, testConfig) => {
1021
1020
  const tests = JSON.parse(runtime.fs.readFileSync(testFile))
1022
1021
  console.log(testFile)
1023
- return saveTestsHelper(testFile, config, tests, tests.map( (test) => test.query ), testConfig)
1022
+ return saveTestsHelper(testFile, config, tests, tests.map((test) => test.query), testConfig)
1024
1023
  }
1025
1024
 
1026
1025
  /*
@@ -1147,7 +1146,7 @@ const defaultErrorHandler = async (error) => {
1147
1146
  doErrorExit = true
1148
1147
  }
1149
1148
 
1150
- if (typeof runtime.process.exit == 'function' && doErrorExit) {
1149
+ if (typeof runtime.process.exit === 'function' && doErrorExit) {
1151
1150
  runtime.process.exit(-1)
1152
1151
  }
1153
1152
 
@@ -1166,7 +1165,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1166
1165
  for (const lcp of responses.learned_contextual_priorities) {
1167
1166
  console.log(` ${JSON.stringify(lcp)},\n`)
1168
1167
  }
1169
- console.log("\n")
1168
+ console.log('\n')
1170
1169
  }
1171
1170
  if (responses.logs) {
1172
1171
  console.log('Logs')
@@ -1182,8 +1181,8 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1182
1181
 
1183
1182
  const pickEm = () => {
1184
1183
  const picked = {}
1185
- const namespaced = config.get('objects')['namespaced']
1186
- for (let prop of getConfig_getObjectCheck(config.testConfig)) {
1184
+ const namespaced = config.get('objects').namespaced
1185
+ for (const prop of getConfig_getObjectCheck(config.testConfig)) {
1187
1186
  if (prop.km) {
1188
1187
  /*
1189
1188
  const objects = namespaced[prop.km]]
@@ -1205,7 +1204,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1205
1204
  }
1206
1205
 
1207
1206
  if (responses.explain_priorities) {
1208
- console.log("Explain Priorities")
1207
+ console.log('Explain Priorities')
1209
1208
  for ([inputs, output, reason] of responses.explain_priorities) {
1210
1209
  console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
1211
1210
  }
@@ -1218,7 +1217,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1218
1217
  }
1219
1218
 
1220
1219
  const pickedResultContexts = responses.contexts.map(pickContext(config.testConfig))
1221
- if (pickedResultContexts.some( (context) => Object.keys(context).length > 0 )) {
1220
+ if (pickedResultContexts.some((context) => Object.keys(context).length > 0)) {
1222
1221
  console.log('--- Contexts showing only the checked values ---')
1223
1222
  console.log(JSON.stringify(pickedResultContexts, null, 2))
1224
1223
  }
@@ -1257,7 +1256,7 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
1257
1256
  try {
1258
1257
  const responses = await promise
1259
1258
  defaultInnerProcess(config, errorHandler, responses)
1260
- } catch(error) {
1259
+ } catch (error) {
1261
1260
  error.config = config
1262
1261
  defaultErrorHandler(error)
1263
1262
  }
@@ -1270,7 +1269,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1270
1269
  fragments: [],
1271
1270
  semantics: [],
1272
1271
  associations: [],
1273
- learned_contextual_priorities: [],
1272
+ learned_contextual_priorities: []
1274
1273
  }
1275
1274
  const looper = async (queries) => {
1276
1275
  if (queries.length === 0) {
@@ -1280,7 +1279,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1280
1279
  const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = queries.shift()
1281
1280
  // queries are strings or { query: "blah", development: true/false }
1282
1281
  if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query) {
1283
- let query = queryOrExtraConfig;
1282
+ let query = queryOrExtraConfig
1284
1283
  if (typeof queryOrExtraConfig === 'string') {
1285
1284
  query = { query }
1286
1285
  }
@@ -1290,7 +1289,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1290
1289
  global.transitoryMode = true
1291
1290
  }
1292
1291
  if (hierarchy) {
1293
- for (let edge of hierarchy) {
1292
+ for (const edge of hierarchy) {
1294
1293
  if (Array.isArray(edge)) {
1295
1294
  config.addHierarchy(edge[0], edge[1])
1296
1295
  } else {
@@ -1306,7 +1305,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1306
1305
  prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
1307
1306
  loadInstance(config, { resultss: [results] })
1308
1307
  } else {
1309
- results = await _process(config, query.query, {initializer, rebuildingTemplate: true})
1308
+ results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
1310
1309
  }
1311
1310
  if (config.config.debug) {
1312
1311
  // TODO pass in the error handler like the other ones
@@ -1330,12 +1329,12 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1330
1329
  accumulators.associations = accumulators.associations.concat(results.associations)
1331
1330
  accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
1332
1331
  await looper(queries)
1333
- } catch(e) {
1334
- const error = { errors: [e], query: query.query };
1332
+ } catch (e) {
1333
+ const error = { errors: [e], query: query.query }
1335
1334
  config.config.skipSemantics = null
1336
1335
  errorHandler(error)
1337
1336
  }
1338
- } else if (typeof queryOrExtraConfig == 'function') {
1337
+ } else if (typeof queryOrExtraConfig === 'function') {
1339
1338
  console.log('calling initialize function')
1340
1339
  const initFunction = queryOrExtraConfig
1341
1340
  const objects = config.get('objects')
@@ -1353,8 +1352,8 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1353
1352
  await looper([])
1354
1353
  } else {
1355
1354
  try {
1356
- config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true } )
1357
- } catch ( e ) {
1355
+ config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true })
1356
+ } catch (e) {
1358
1357
  const where = extraConfig.where ? ` ${extraConfig.where}` : ''
1359
1358
  throw new Error(`Error processing extra config${where}: ${e.stack}}`)
1360
1359
  }
@@ -1368,11 +1367,11 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1368
1367
  const instanceName = `${target}.instance.json`
1369
1368
  console.log(`Writing instance file ${instanceName}`)
1370
1369
  const stabilizeAssociations = (associations) => {
1371
- for (let association of associations) {
1370
+ for (const association of associations) {
1372
1371
  association.sort()
1373
1372
  }
1374
1373
  associations.sort()
1375
- };
1374
+ }
1376
1375
  const stabilizeOutput = (template) => {
1377
1376
  stabilizeAssociations(template.associations)
1378
1377
  const stabilize = (results) => {
@@ -1397,7 +1396,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1397
1396
  stabilize(template.resultss)
1398
1397
  stabilize(template.fragments)
1399
1398
  return template
1400
- };
1399
+ }
1401
1400
  stabilizeOutput(accumulators)
1402
1401
  runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries.map(updateQueries) }, accumulators), 0, 2))
1403
1402
 
@@ -1410,7 +1409,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1410
1409
  }
1411
1410
 
1412
1411
  const toProperties = (queryStringOrProperties) => {
1413
- if (typeof queryStringOrProperties == 'string') {
1412
+ if (typeof queryStringOrProperties === 'string') {
1414
1413
  return { query: queryStringOrProperties }
1415
1414
  } else {
1416
1415
  return queryStringOrProperties
@@ -1418,12 +1417,12 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1418
1417
  }
1419
1418
  let todo = []
1420
1419
  todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false || query.skipSemantics } }))
1421
- todo = todo.concat((template.queries || []).map((query, index) => {
1420
+ todo = todo.concat((template.queries || []).map((query, index) => {
1422
1421
  let pr
1423
1422
  if (index < startOfChanges) {
1424
- pr = previousResultss[index]
1423
+ pr = previousResultss[index]
1425
1424
  }
1426
- return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics}
1425
+ return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics }
1427
1426
  }))
1428
1427
  todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
1429
1428
  todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
@@ -1467,15 +1466,19 @@ const knowledgeModuleImpl = async ({
1467
1466
  stopAtFirstFailure = true,
1468
1467
  ...rest
1469
1468
  } = {}) => {
1470
-
1471
- template = _.cloneDeep(template)
1472
-
1473
- // if (template.queries[91] && template.queries[91].bridge) {
1474
- if (template.queries[91]) {
1475
- debugger
1469
+ /*
1470
+ if (description == 'fastfood related concepts') {
1476
1471
  debugger
1477
- Object.freeze(template.queries[91])
1472
+ global.old = template.template.queries[91].bridges[0]
1478
1473
  }
1474
+ let old
1475
+ if (template && template.template && template.template.queries) {
1476
+ old = template.template.queries
1477
+ template.template.queries = _.cloneDeep(template.template.queries)
1478
+ template.wasCopied = true
1479
+ }
1480
+ */
1481
+
1479
1482
  const unknownArgs = Object.keys(rest)
1480
1483
  if (unknownArgs.length > 0) {
1481
1484
  throw new Error(`Unknown arguments to knowledgeModule: ${unknownArgs.join()}`)
@@ -1506,10 +1509,10 @@ const knowledgeModuleImpl = async ({
1506
1509
  }
1507
1510
 
1508
1511
  config.description = description
1509
- if (typeof test === 'object') {
1510
- if (test.contents) {
1511
- config.tests = test.contents
1512
- test = test.name
1512
+ if (typeof testConfig === 'object') {
1513
+ if (testConfig.contents) {
1514
+ config.tests = testConfig.contents
1515
+ test = testConfig.name
1513
1516
  }
1514
1517
  } else {
1515
1518
  if (runtime.fs && runtime.fs.existsSync(test)) {
@@ -1521,7 +1524,6 @@ const knowledgeModuleImpl = async ({
1521
1524
  config.setTestConfig(testConfig)
1522
1525
  }
1523
1526
 
1524
-
1525
1527
  if (isProcess) {
1526
1528
  const config = createConfig()
1527
1529
  setupConfig(config)
@@ -1538,7 +1540,6 @@ const knowledgeModuleImpl = async ({
1538
1540
  const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id/level to break on. For example DEBUG_BRIDGE=\'id#level\''
1539
1541
  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]))\''
1540
1542
 
1541
-
1542
1543
  parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
1543
1544
  parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
1544
1545
  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' })
@@ -1553,7 +1554,7 @@ const knowledgeModuleImpl = async ({
1553
1554
  parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
1554
1555
  parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
1555
1556
  parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
1556
- 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]]' })
1557
+ 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]]' })
1557
1558
  parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
1558
1559
  parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1559
1560
  parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
@@ -1565,7 +1566,7 @@ const knowledgeModuleImpl = async ({
1565
1566
  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' })
1566
1567
  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.' })
1567
1568
  parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
1568
- 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 '})
1569
+ 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 ' })
1569
1570
  parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
1570
1571
  parser.add_argument('-da', '--debugAssociation', { action: 'store_true', help: helpDebugAssociation })
1571
1572
  parser.add_argument('-dh', '--debugHierarchy', { action: 'store_true', help: helpDebugHierarchy })
@@ -1573,8 +1574,8 @@ const knowledgeModuleImpl = async ({
1573
1574
  parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
1574
1575
  parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
1575
1576
  parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
1576
- 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"})
1577
- 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' })
1577
+ 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' })
1578
+ 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' })
1578
1579
 
1579
1580
  const args = parser.parse_args()
1580
1581
  args.count = args.count || 1
@@ -1605,9 +1606,9 @@ const knowledgeModuleImpl = async ({
1605
1606
  return true
1606
1607
  }
1607
1608
  if (!Array.isArray(args.checkForLoop) || args.checkForLoop.some((value) => !isKey(value))) {
1608
- throw new Error(`Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"`)
1609
+ throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
1609
1610
  }
1610
- } catch( e ) {
1611
+ } catch (e) {
1611
1612
  throw new Error(`Error parsing JSON of the checkForLoop argument. ${e}`)
1612
1613
  }
1613
1614
  } else {
@@ -1638,7 +1639,7 @@ const knowledgeModuleImpl = async ({
1638
1639
 
1639
1640
  if (args.clean) {
1640
1641
  const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1641
- for (let test of tests) {
1642
+ for (const test of tests) {
1642
1643
  delete test.associations
1643
1644
  }
1644
1645
  writeTestFile(testConfig.name, tests)
@@ -1648,7 +1649,7 @@ const knowledgeModuleImpl = async ({
1648
1649
 
1649
1650
  if (args.deleteTest) {
1650
1651
  let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1651
- tests = tests.filter( (test) => test.query !== args.deleteTest );
1652
+ tests = tests.filter((test) => test.query !== args.deleteTest)
1652
1653
  writeTestFile(testConfig.name, tests)
1653
1654
  console.log(`Remove the test for "${args.deleteTest}"`)
1654
1655
  return
@@ -1681,7 +1682,7 @@ const knowledgeModuleImpl = async ({
1681
1682
  config.config.explain_priorities = true
1682
1683
  }
1683
1684
 
1684
- config.config.debugIncludeConvolutions = args.debugIncludeConvolutions || process.argv.includes('--debugIncludeConvolutions') || process.argv.includes('-dic')
1685
+ config.config.debugIncludeConvolutions = args.debugIncludeConvolutions || process.argv.includes('--debugIncludeConvolutions') || process.argv.includes('-dic')
1685
1686
 
1686
1687
  let configPrinted = false
1687
1688
  const printConfig = () => {
@@ -1691,7 +1692,7 @@ const knowledgeModuleImpl = async ({
1691
1692
  configPrinted = true
1692
1693
  if (args.print) {
1693
1694
  if (args.print.includes('t')) {
1694
- console.log("Test queries")
1695
+ console.log('Test queries')
1695
1696
  let counter = 0
1696
1697
  for (const test of config.tests) {
1697
1698
  console.log(`${counter} - ${test.query}`)
@@ -1700,8 +1701,8 @@ const knowledgeModuleImpl = async ({
1700
1701
  }
1701
1702
  if (args.print.includes('c')) {
1702
1703
  const { data } = setupProcessB({ config })
1703
- console.log("Config as sent to server")
1704
- console.log(JSON.stringify(data, null, 2));
1704
+ console.log('Config as sent to server')
1705
+ console.log(JSON.stringify(data, null, 2))
1705
1706
  }
1706
1707
 
1707
1708
  if (args.print.includes('l')) {
@@ -1726,15 +1727,15 @@ const knowledgeModuleImpl = async ({
1726
1727
  }
1727
1728
  }
1728
1729
  if (args.print.includes('j')) {
1729
- const { data } = setupProcessB( { config } )
1730
+ const { data } = setupProcessB({ config })
1730
1731
  console.log(JSON.stringify(data, null, 2))
1731
1732
  }
1732
1733
  if (args.print.includes('a')) {
1733
1734
  console.log('associations ================')
1734
1735
  const properties = ['negative', 'positive']
1735
- for (let property of properties) {
1736
+ for (const property of properties) {
1736
1737
  console.log(` ${property} ===============`)
1737
- for (let association of config.config.associations[property]) {
1738
+ for (const association of config.config.associations[property]) {
1738
1739
  console.log(` ${JSON.stringify(association)}`)
1739
1740
  }
1740
1741
  }
@@ -1743,12 +1744,12 @@ const knowledgeModuleImpl = async ({
1743
1744
  console.log(JSON.stringify(config.config.objects, null, 2))
1744
1745
  }
1745
1746
  if (args.print.includes('p')) {
1746
- for (let priority of config.config.priorities) {
1747
+ for (const priority of config.config.priorities) {
1747
1748
  console.log(JSON.stringify(priority))
1748
1749
  }
1749
1750
  }
1750
1751
  if (args.print.includes('h')) {
1751
- for (let edge of config.config.hierarchy) {
1752
+ for (const edge of config.config.hierarchy) {
1752
1753
  console.log(JSON.stringify(edge))
1753
1754
  }
1754
1755
  }
@@ -1778,7 +1779,6 @@ const knowledgeModuleImpl = async ({
1778
1779
 
1779
1780
  if (template) {
1780
1781
  let needsRebuild
1781
- console.log('template.template needs rebuild', template.template)
1782
1782
  if (args.rebuildTemplate && !args.rebuildTemplateFull) {
1783
1783
  // get the startOfChanges for the partial rebuild
1784
1784
  needsRebuild = config.needsRebuild(template.template, template.instance, { ...options, rebuild: false })
@@ -1789,7 +1789,7 @@ const knowledgeModuleImpl = async ({
1789
1789
 
1790
1790
  if (needsRebuild.needsRebuild) {
1791
1791
  if (needsRebuild.previousResultss) {
1792
- console.log("Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf")
1792
+ console.log('Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf')
1793
1793
  }
1794
1794
  console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
1795
1795
  options.rebuild = true
@@ -1797,7 +1797,7 @@ const knowledgeModuleImpl = async ({
1797
1797
  }
1798
1798
  try {
1799
1799
  config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
1800
- } catch( e ) {
1800
+ } catch (e) {
1801
1801
  console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
1802
1802
  runtime.process.exit(-1)
1803
1803
  }
@@ -1849,12 +1849,12 @@ const knowledgeModuleImpl = async ({
1849
1849
  hasError = true
1850
1850
  }
1851
1851
  if (!args.testNoParenthesized) {
1852
- if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1853
- hasError = true
1854
- }
1855
- if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1856
- hasError = true
1857
- }
1852
+ if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1853
+ hasError = true
1854
+ }
1855
+ if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1856
+ hasError = true
1857
+ }
1858
1858
  }
1859
1859
  if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1860
1860
  hasError = true
@@ -2000,13 +2000,13 @@ const knowledgeModuleImpl = async ({
2000
2000
  .then(() => {
2001
2001
  f()
2002
2002
  })
2003
- .catch( (e) => {
2003
+ .catch((e) => {
2004
2004
  if (e.errno == 'ECONNREFUSED') {
2005
2005
  console.log(e)
2006
2006
  readline.close()
2007
2007
  } else {
2008
2008
  console.log(e)
2009
- f()
2009
+ f()
2010
2010
  }
2011
2011
  })
2012
2012
  })
@@ -2019,13 +2019,19 @@ const knowledgeModuleImpl = async ({
2019
2019
  }
2020
2020
  try {
2021
2021
  await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
2022
- } catch( error ) {
2023
- console.log('Error', error);
2022
+ } catch (error) {
2023
+ console.log('Error', error)
2024
2024
  }
2025
2025
  }
2026
2026
  printConfig()
2027
2027
  } else {
2028
2028
  const initConfig = (config) => {
2029
+ if (template) {
2030
+ if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
2031
+ const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
2032
+ throw new Error(error)
2033
+ }
2034
+ }
2029
2035
  setupConfig(config)
2030
2036
 
2031
2037
  let loadForTesting = false
@@ -2036,14 +2042,14 @@ const knowledgeModuleImpl = async ({
2036
2042
  }
2037
2043
  // remove test only stuff
2038
2044
  if (!isProcess && !loadForTesting) {
2039
- config.config.operators = config.config.operators.filter( (operator) => {
2045
+ config.config.operators = config.config.operators.filter((operator) => {
2040
2046
  if (operator.development) {
2041
2047
  return false
2042
2048
  } else {
2043
2049
  return true
2044
2050
  }
2045
2051
  })
2046
- config.config.bridges = config.config.bridges.filter( (bridge) => {
2052
+ config.config.bridges = config.config.bridges.filter((bridge) => {
2047
2053
  if (bridge.development) {
2048
2054
  return false
2049
2055
  } else {
@@ -2053,14 +2059,9 @@ const knowledgeModuleImpl = async ({
2053
2059
  }
2054
2060
 
2055
2061
  if (template) {
2056
- console.log('template.template needs rebuild', template.template)
2057
- if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
2058
- const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
2059
- throw new Error(error)
2060
- }
2061
2062
  try {
2062
2063
  config.load(template.template, template.instance)
2063
- } catch( e ) {
2064
+ } catch (e) {
2064
2065
  errorHandler(e)
2065
2066
  }
2066
2067
  }
@@ -2096,19 +2097,19 @@ const ensureTestFile = (module, name, type) => {
2096
2097
  }
2097
2098
  }
2098
2099
 
2099
- function where(goUp = 2) {
2100
- const e = new Error();
2100
+ function where (goUp = 2) {
2101
+ const e = new Error()
2101
2102
  const regexForm1 = /\((.*):(\d+):(\d+)\)$/
2102
2103
  const regexForm2 = /at (.*):(\d+):(\d+)$/
2103
- const lines = e.stack.split("\n")
2104
+ const lines = e.stack.split('\n')
2104
2105
  let line
2105
2106
  for (line of lines.slice(1)) {
2106
- if (!(line.includes("config.js:") || line.includes("client.js:"))) {
2107
- break;
2107
+ if (!(line.includes('config.js:') || line.includes('client.js:'))) {
2108
+ break
2108
2109
  }
2109
2110
  }
2110
2111
  // const line = e.stack.split("\n")[goUp];
2111
- const match = regexForm1.exec(line) || regexForm2.exec(line);
2112
+ const match = regexForm1.exec(line) || regexForm2.exec(line)
2112
2113
  if (match) {
2113
2114
  return `${match[1]}:${match[2]}`
2114
2115
  } else {
@@ -2116,7 +2117,7 @@ function where(goUp = 2) {
2116
2117
  }
2117
2118
  }
2118
2119
 
2119
- function w(func) {
2120
+ function w (func) {
2120
2121
  func.where = where(3)
2121
2122
  return func
2122
2123
  }
@@ -2148,4 +2149,3 @@ module.exports = {
2148
2149
  flattens,
2149
2150
  writeTest
2150
2151
  }
2151
-