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