theprogrammablemind 7.10.0 → 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 +280 -288
- package/demo.js +24 -24
- package/lines.js +2 -2
- package/package.json +1 -1
- package/runtime.js +2 -2
- package/src/config.js +261 -241
- 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
|
-
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(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) }
|
@@ -667,7 +668,11 @@ const loadInstance = (config, instance) => {
|
|
667
668
|
global.transitoryMode = transitoryMode
|
668
669
|
}
|
669
670
|
|
670
|
-
const
|
671
|
+
const throwErrorHandler = (error) => {
|
672
|
+
throw error
|
673
|
+
}
|
674
|
+
|
675
|
+
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
671
676
|
if (credentials) {
|
672
677
|
config.server(credentials.server, credentials.key)
|
673
678
|
}
|
@@ -682,7 +687,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
682
687
|
config.rebuild()
|
683
688
|
const objects = getObjects(config.config.objects)(config.uuid)
|
684
689
|
}
|
685
|
-
} catch(error) {
|
690
|
+
} catch (error) {
|
686
691
|
throw error
|
687
692
|
}
|
688
693
|
|
@@ -712,12 +717,12 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
712
717
|
paraphrasesParenthesized: [],
|
713
718
|
generatedParenthesized: [],
|
714
719
|
responses: [],
|
715
|
-
associations: []
|
720
|
+
associations: []
|
716
721
|
}
|
717
722
|
|
718
723
|
while (true) {
|
719
724
|
if (queries.length === 0) {
|
720
|
-
break
|
725
|
+
break
|
721
726
|
}
|
722
727
|
|
723
728
|
data.utterance = queries[0]
|
@@ -783,18 +788,18 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
783
788
|
|
784
789
|
if (writeTests) {
|
785
790
|
const actual_config = getConfigForTest(config, testConfig)
|
786
|
-
const saveObjects = {...config.config.objects}
|
791
|
+
const saveObjects = { ...config.config.objects }
|
787
792
|
saveObjects.nameToUUID = {}
|
788
|
-
for (
|
793
|
+
for (const km of config.configs) {
|
789
794
|
saveObjects.nameToUUID[km.name] = km.uuid
|
790
795
|
}
|
791
796
|
writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized)
|
792
797
|
}
|
793
798
|
|
794
799
|
return response
|
795
|
-
} catch(error) {
|
796
|
-
|
797
|
-
|
800
|
+
} catch (error) {
|
801
|
+
error.query = query
|
802
|
+
errorHandler(error)
|
798
803
|
}
|
799
804
|
}
|
800
805
|
|
@@ -849,110 +854,110 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
|
|
849
854
|
objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
|
850
855
|
testConfigName = testConfig.testModuleName
|
851
856
|
}
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
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
|
-
}
|
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
|
941
945
|
}
|
942
946
|
}
|
943
|
-
}
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
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)
|
953
957
|
}
|
954
|
-
throw error
|
955
958
|
}
|
959
|
+
throw error
|
960
|
+
}
|
956
961
|
}
|
957
962
|
|
958
963
|
const runTestsHelper = async (config, tests, failed, juicyBits) => {
|
@@ -990,9 +995,9 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
|
|
990
995
|
const actualConfig = getConfigForTest(config, testConfig)
|
991
996
|
const args = {
|
992
997
|
}
|
993
|
-
const saveObjects = {...config.config.objects}
|
998
|
+
const saveObjects = { ...config.config.objects }
|
994
999
|
saveObjects.nameToUUID = {}
|
995
|
-
for (
|
1000
|
+
for (const km of config.configs) {
|
996
1001
|
saveObjects.nameToUUID[km.name] = km.uuid
|
997
1002
|
}
|
998
1003
|
writeTest(testFile, test, saveObjects, result.generated, result.paraphrases, result.responses, result.contexts, result.associations, result.metadata, actualConfig, saveDeveloper, result.paraphrasesParenthesized, result.generatedParenthesized)
|
@@ -1014,7 +1019,7 @@ const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDe
|
|
1014
1019
|
const saveTests = (config, testFile, testConfig) => {
|
1015
1020
|
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
1016
1021
|
console.log(testFile)
|
1017
|
-
return saveTestsHelper(testFile, config, tests, tests.map(
|
1022
|
+
return saveTestsHelper(testFile, config, tests, tests.map((test) => test.query), testConfig)
|
1018
1023
|
}
|
1019
1024
|
|
1020
1025
|
/*
|
@@ -1025,31 +1030,7 @@ const showExamples = (testFile) => {
|
|
1025
1030
|
*/
|
1026
1031
|
|
1027
1032
|
const showInfo = (description, section, config) => {
|
1028
|
-
|
1029
|
-
const includes = config.configs.slice(1).map((km) => km.config.name)
|
1030
|
-
const visibleExamples = []
|
1031
|
-
for (const test of config.tests) {
|
1032
|
-
if (!test.developerTest) {
|
1033
|
-
visibleExamples.push(test.query)
|
1034
|
-
}
|
1035
|
-
}
|
1036
|
-
const templateQueries = []
|
1037
|
-
if (config.instances && config.instances.length > 0) {
|
1038
|
-
for (let query of config.instances.slice(-1)[0].queries) {
|
1039
|
-
if (typeof query == 'string') {
|
1040
|
-
templateQueries.push(query)
|
1041
|
-
}
|
1042
|
-
}
|
1043
|
-
}
|
1044
|
-
const info = { name, description, examples: visibleExamples, template: templateQueries, section, includes, demo: config.demo }
|
1045
|
-
/*
|
1046
|
-
if (config.instances.length > 0) {
|
1047
|
-
info.template = {
|
1048
|
-
base: config.instances[0].base
|
1049
|
-
}
|
1050
|
-
}
|
1051
|
-
*/
|
1052
|
-
console.log(JSON.stringify(info, null, 2))
|
1033
|
+
console.log(JSON.stringify(config.getInfo(), null, 2))
|
1053
1034
|
}
|
1054
1035
|
|
1055
1036
|
const submitBugToAPI = async (subscription_id, subscription_password, config) => {
|
@@ -1165,7 +1146,7 @@ const defaultErrorHandler = async (error) => {
|
|
1165
1146
|
doErrorExit = true
|
1166
1147
|
}
|
1167
1148
|
|
1168
|
-
if (typeof runtime.process.exit
|
1149
|
+
if (typeof runtime.process.exit === 'function' && doErrorExit) {
|
1169
1150
|
runtime.process.exit(-1)
|
1170
1151
|
}
|
1171
1152
|
|
@@ -1184,7 +1165,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1184
1165
|
for (const lcp of responses.learned_contextual_priorities) {
|
1185
1166
|
console.log(` ${JSON.stringify(lcp)},\n`)
|
1186
1167
|
}
|
1187
|
-
console.log(
|
1168
|
+
console.log('\n')
|
1188
1169
|
}
|
1189
1170
|
if (responses.logs) {
|
1190
1171
|
console.log('Logs')
|
@@ -1200,8 +1181,8 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1200
1181
|
|
1201
1182
|
const pickEm = () => {
|
1202
1183
|
const picked = {}
|
1203
|
-
const namespaced = config.get('objects')
|
1204
|
-
for (
|
1184
|
+
const namespaced = config.get('objects').namespaced
|
1185
|
+
for (const prop of getConfig_getObjectCheck(config.testConfig)) {
|
1205
1186
|
if (prop.km) {
|
1206
1187
|
/*
|
1207
1188
|
const objects = namespaced[prop.km]]
|
@@ -1223,7 +1204,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1223
1204
|
}
|
1224
1205
|
|
1225
1206
|
if (responses.explain_priorities) {
|
1226
|
-
console.log(
|
1207
|
+
console.log('Explain Priorities')
|
1227
1208
|
for ([inputs, output, reason] of responses.explain_priorities) {
|
1228
1209
|
console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
|
1229
1210
|
}
|
@@ -1236,7 +1217,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1236
1217
|
}
|
1237
1218
|
|
1238
1219
|
const pickedResultContexts = responses.contexts.map(pickContext(config.testConfig))
|
1239
|
-
if (pickedResultContexts.some(
|
1220
|
+
if (pickedResultContexts.some((context) => Object.keys(context).length > 0)) {
|
1240
1221
|
console.log('--- Contexts showing only the checked values ---')
|
1241
1222
|
console.log(JSON.stringify(pickedResultContexts, null, 2))
|
1242
1223
|
}
|
@@ -1275,7 +1256,7 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
|
|
1275
1256
|
try {
|
1276
1257
|
const responses = await promise
|
1277
1258
|
defaultInnerProcess(config, errorHandler, responses)
|
1278
|
-
} catch(error) {
|
1259
|
+
} catch (error) {
|
1279
1260
|
error.config = config
|
1280
1261
|
defaultErrorHandler(error)
|
1281
1262
|
}
|
@@ -1288,7 +1269,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1288
1269
|
fragments: [],
|
1289
1270
|
semantics: [],
|
1290
1271
|
associations: [],
|
1291
|
-
learned_contextual_priorities: []
|
1272
|
+
learned_contextual_priorities: []
|
1292
1273
|
}
|
1293
1274
|
const looper = async (queries) => {
|
1294
1275
|
if (queries.length === 0) {
|
@@ -1298,7 +1279,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1298
1279
|
const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = queries.shift()
|
1299
1280
|
// queries are strings or { query: "blah", development: true/false }
|
1300
1281
|
if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query) {
|
1301
|
-
let query = queryOrExtraConfig
|
1282
|
+
let query = queryOrExtraConfig
|
1302
1283
|
if (typeof queryOrExtraConfig === 'string') {
|
1303
1284
|
query = { query }
|
1304
1285
|
}
|
@@ -1308,7 +1289,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1308
1289
|
global.transitoryMode = true
|
1309
1290
|
}
|
1310
1291
|
if (hierarchy) {
|
1311
|
-
for (
|
1292
|
+
for (const edge of hierarchy) {
|
1312
1293
|
if (Array.isArray(edge)) {
|
1313
1294
|
config.addHierarchy(edge[0], edge[1])
|
1314
1295
|
} else {
|
@@ -1324,7 +1305,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1324
1305
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
1325
1306
|
loadInstance(config, { resultss: [results] })
|
1326
1307
|
} else {
|
1327
|
-
results = await _process(config, query.query, {initializer, rebuildingTemplate: true})
|
1308
|
+
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
1328
1309
|
}
|
1329
1310
|
if (config.config.debug) {
|
1330
1311
|
// TODO pass in the error handler like the other ones
|
@@ -1348,12 +1329,12 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1348
1329
|
accumulators.associations = accumulators.associations.concat(results.associations)
|
1349
1330
|
accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
|
1350
1331
|
await looper(queries)
|
1351
|
-
} catch(e) {
|
1352
|
-
const error = { errors: [e], query: query.query }
|
1332
|
+
} catch (e) {
|
1333
|
+
const error = { errors: [e], query: query.query }
|
1353
1334
|
config.config.skipSemantics = null
|
1354
1335
|
errorHandler(error)
|
1355
1336
|
}
|
1356
|
-
} else if (typeof queryOrExtraConfig
|
1337
|
+
} else if (typeof queryOrExtraConfig === 'function') {
|
1357
1338
|
console.log('calling initialize function')
|
1358
1339
|
const initFunction = queryOrExtraConfig
|
1359
1340
|
const objects = config.get('objects')
|
@@ -1371,8 +1352,8 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1371
1352
|
await looper([])
|
1372
1353
|
} else {
|
1373
1354
|
try {
|
1374
|
-
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true }
|
1375
|
-
} catch (
|
1355
|
+
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true })
|
1356
|
+
} catch (e) {
|
1376
1357
|
const where = extraConfig.where ? ` ${extraConfig.where}` : ''
|
1377
1358
|
throw new Error(`Error processing extra config${where}: ${e.stack}}`)
|
1378
1359
|
}
|
@@ -1386,11 +1367,11 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1386
1367
|
const instanceName = `${target}.instance.json`
|
1387
1368
|
console.log(`Writing instance file ${instanceName}`)
|
1388
1369
|
const stabilizeAssociations = (associations) => {
|
1389
|
-
for (
|
1370
|
+
for (const association of associations) {
|
1390
1371
|
association.sort()
|
1391
1372
|
}
|
1392
1373
|
associations.sort()
|
1393
|
-
}
|
1374
|
+
}
|
1394
1375
|
const stabilizeOutput = (template) => {
|
1395
1376
|
stabilizeAssociations(template.associations)
|
1396
1377
|
const stabilize = (results) => {
|
@@ -1415,7 +1396,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1415
1396
|
stabilize(template.resultss)
|
1416
1397
|
stabilize(template.fragments)
|
1417
1398
|
return template
|
1418
|
-
}
|
1399
|
+
}
|
1419
1400
|
stabilizeOutput(accumulators)
|
1420
1401
|
runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries.map(updateQueries) }, accumulators), 0, 2))
|
1421
1402
|
|
@@ -1428,7 +1409,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1428
1409
|
}
|
1429
1410
|
|
1430
1411
|
const toProperties = (queryStringOrProperties) => {
|
1431
|
-
if (typeof queryStringOrProperties
|
1412
|
+
if (typeof queryStringOrProperties === 'string') {
|
1432
1413
|
return { query: queryStringOrProperties }
|
1433
1414
|
} else {
|
1434
1415
|
return queryStringOrProperties
|
@@ -1436,12 +1417,12 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1436
1417
|
}
|
1437
1418
|
let todo = []
|
1438
1419
|
todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false || query.skipSemantics } }))
|
1439
|
-
todo = todo.concat((template.queries || []).map((query, index) => {
|
1420
|
+
todo = todo.concat((template.queries || []).map((query, index) => {
|
1440
1421
|
let pr
|
1441
1422
|
if (index < startOfChanges) {
|
1442
|
-
pr = previousResultss[index]
|
1423
|
+
pr = previousResultss[index]
|
1443
1424
|
}
|
1444
|
-
return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics}
|
1425
|
+
return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics }
|
1445
1426
|
}))
|
1446
1427
|
todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
|
1447
1428
|
todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
|
@@ -1485,6 +1466,18 @@ const knowledgeModuleImpl = async ({
|
|
1485
1466
|
stopAtFirstFailure = true,
|
1486
1467
|
...rest
|
1487
1468
|
} = {}) => {
|
1469
|
+
/*
|
1470
|
+
if (description == 'fastfood related concepts') {
|
1471
|
+
debugger
|
1472
|
+
global.old = template.template.queries[91].bridges[0]
|
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
|
+
*/
|
1488
1481
|
|
1489
1482
|
const unknownArgs = Object.keys(rest)
|
1490
1483
|
if (unknownArgs.length > 0) {
|
@@ -1516,10 +1509,10 @@ const knowledgeModuleImpl = async ({
|
|
1516
1509
|
}
|
1517
1510
|
|
1518
1511
|
config.description = description
|
1519
|
-
if (typeof
|
1520
|
-
if (
|
1521
|
-
config.tests =
|
1522
|
-
test =
|
1512
|
+
if (typeof testConfig === 'object') {
|
1513
|
+
if (testConfig.contents) {
|
1514
|
+
config.tests = testConfig.contents
|
1515
|
+
test = testConfig.name
|
1523
1516
|
}
|
1524
1517
|
} else {
|
1525
1518
|
if (runtime.fs && runtime.fs.existsSync(test)) {
|
@@ -1531,7 +1524,6 @@ const knowledgeModuleImpl = async ({
|
|
1531
1524
|
config.setTestConfig(testConfig)
|
1532
1525
|
}
|
1533
1526
|
|
1534
|
-
|
1535
1527
|
if (isProcess) {
|
1536
1528
|
const config = createConfig()
|
1537
1529
|
setupConfig(config)
|
@@ -1548,7 +1540,6 @@ const knowledgeModuleImpl = async ({
|
|
1548
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\''
|
1549
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]))\''
|
1550
1542
|
|
1551
|
-
|
1552
1543
|
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
1553
1544
|
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1554
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' })
|
@@ -1563,7 +1554,7 @@ const knowledgeModuleImpl = async ({
|
|
1563
1554
|
parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
|
1564
1555
|
parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
|
1565
1556
|
parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
|
1566
|
-
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]]' })
|
1567
1558
|
parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
|
1568
1559
|
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
1569
1560
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
@@ -1575,7 +1566,7 @@ const knowledgeModuleImpl = async ({
|
|
1575
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' })
|
1576
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.' })
|
1577
1568
|
parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
|
1578
|
-
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 ' })
|
1579
1570
|
parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
|
1580
1571
|
parser.add_argument('-da', '--debugAssociation', { action: 'store_true', help: helpDebugAssociation })
|
1581
1572
|
parser.add_argument('-dh', '--debugHierarchy', { action: 'store_true', help: helpDebugHierarchy })
|
@@ -1583,8 +1574,8 @@ const knowledgeModuleImpl = async ({
|
|
1583
1574
|
parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
|
1584
1575
|
parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
|
1585
1576
|
parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
|
1586
|
-
parser.add_argument('-ep', '--explainPriorities', { action: 'store_true', help:
|
1587
|
-
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' })
|
1588
1579
|
|
1589
1580
|
const args = parser.parse_args()
|
1590
1581
|
args.count = args.count || 1
|
@@ -1615,9 +1606,9 @@ const knowledgeModuleImpl = async ({
|
|
1615
1606
|
return true
|
1616
1607
|
}
|
1617
1608
|
if (!Array.isArray(args.checkForLoop) || args.checkForLoop.some((value) => !isKey(value))) {
|
1618
|
-
throw new Error(
|
1609
|
+
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1619
1610
|
}
|
1620
|
-
} catch(
|
1611
|
+
} catch (e) {
|
1621
1612
|
throw new Error(`Error parsing JSON of the checkForLoop argument. ${e}`)
|
1622
1613
|
}
|
1623
1614
|
} else {
|
@@ -1648,7 +1639,7 @@ const knowledgeModuleImpl = async ({
|
|
1648
1639
|
|
1649
1640
|
if (args.clean) {
|
1650
1641
|
const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1651
|
-
for (
|
1642
|
+
for (const test of tests) {
|
1652
1643
|
delete test.associations
|
1653
1644
|
}
|
1654
1645
|
writeTestFile(testConfig.name, tests)
|
@@ -1658,7 +1649,7 @@ const knowledgeModuleImpl = async ({
|
|
1658
1649
|
|
1659
1650
|
if (args.deleteTest) {
|
1660
1651
|
let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1661
|
-
tests = tests.filter(
|
1652
|
+
tests = tests.filter((test) => test.query !== args.deleteTest)
|
1662
1653
|
writeTestFile(testConfig.name, tests)
|
1663
1654
|
console.log(`Remove the test for "${args.deleteTest}"`)
|
1664
1655
|
return
|
@@ -1691,7 +1682,7 @@ const knowledgeModuleImpl = async ({
|
|
1691
1682
|
config.config.explain_priorities = true
|
1692
1683
|
}
|
1693
1684
|
|
1694
|
-
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')
|
1695
1686
|
|
1696
1687
|
let configPrinted = false
|
1697
1688
|
const printConfig = () => {
|
@@ -1701,7 +1692,7 @@ const knowledgeModuleImpl = async ({
|
|
1701
1692
|
configPrinted = true
|
1702
1693
|
if (args.print) {
|
1703
1694
|
if (args.print.includes('t')) {
|
1704
|
-
console.log(
|
1695
|
+
console.log('Test queries')
|
1705
1696
|
let counter = 0
|
1706
1697
|
for (const test of config.tests) {
|
1707
1698
|
console.log(`${counter} - ${test.query}`)
|
@@ -1710,8 +1701,8 @@ const knowledgeModuleImpl = async ({
|
|
1710
1701
|
}
|
1711
1702
|
if (args.print.includes('c')) {
|
1712
1703
|
const { data } = setupProcessB({ config })
|
1713
|
-
console.log(
|
1714
|
-
console.log(JSON.stringify(data, null, 2))
|
1704
|
+
console.log('Config as sent to server')
|
1705
|
+
console.log(JSON.stringify(data, null, 2))
|
1715
1706
|
}
|
1716
1707
|
|
1717
1708
|
if (args.print.includes('l')) {
|
@@ -1736,15 +1727,15 @@ const knowledgeModuleImpl = async ({
|
|
1736
1727
|
}
|
1737
1728
|
}
|
1738
1729
|
if (args.print.includes('j')) {
|
1739
|
-
const { data } = setupProcessB(
|
1730
|
+
const { data } = setupProcessB({ config })
|
1740
1731
|
console.log(JSON.stringify(data, null, 2))
|
1741
1732
|
}
|
1742
1733
|
if (args.print.includes('a')) {
|
1743
1734
|
console.log('associations ================')
|
1744
1735
|
const properties = ['negative', 'positive']
|
1745
|
-
for (
|
1736
|
+
for (const property of properties) {
|
1746
1737
|
console.log(` ${property} ===============`)
|
1747
|
-
for (
|
1738
|
+
for (const association of config.config.associations[property]) {
|
1748
1739
|
console.log(` ${JSON.stringify(association)}`)
|
1749
1740
|
}
|
1750
1741
|
}
|
@@ -1753,12 +1744,12 @@ const knowledgeModuleImpl = async ({
|
|
1753
1744
|
console.log(JSON.stringify(config.config.objects, null, 2))
|
1754
1745
|
}
|
1755
1746
|
if (args.print.includes('p')) {
|
1756
|
-
for (
|
1747
|
+
for (const priority of config.config.priorities) {
|
1757
1748
|
console.log(JSON.stringify(priority))
|
1758
1749
|
}
|
1759
1750
|
}
|
1760
1751
|
if (args.print.includes('h')) {
|
1761
|
-
for (
|
1752
|
+
for (const edge of config.config.hierarchy) {
|
1762
1753
|
console.log(JSON.stringify(edge))
|
1763
1754
|
}
|
1764
1755
|
}
|
@@ -1798,7 +1789,7 @@ const knowledgeModuleImpl = async ({
|
|
1798
1789
|
|
1799
1790
|
if (needsRebuild.needsRebuild) {
|
1800
1791
|
if (needsRebuild.previousResultss) {
|
1801
|
-
console.log(
|
1792
|
+
console.log('Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf')
|
1802
1793
|
}
|
1803
1794
|
console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
|
1804
1795
|
options.rebuild = true
|
@@ -1806,7 +1797,7 @@ const knowledgeModuleImpl = async ({
|
|
1806
1797
|
}
|
1807
1798
|
try {
|
1808
1799
|
config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1809
|
-
} catch(
|
1800
|
+
} catch (e) {
|
1810
1801
|
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1811
1802
|
runtime.process.exit(-1)
|
1812
1803
|
}
|
@@ -1858,12 +1849,12 @@ const knowledgeModuleImpl = async ({
|
|
1858
1849
|
hasError = true
|
1859
1850
|
}
|
1860
1851
|
if (!args.testNoParenthesized) {
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
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
|
+
}
|
1867
1858
|
}
|
1868
1859
|
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1869
1860
|
hasError = true
|
@@ -2009,13 +2000,13 @@ const knowledgeModuleImpl = async ({
|
|
2009
2000
|
.then(() => {
|
2010
2001
|
f()
|
2011
2002
|
})
|
2012
|
-
.catch(
|
2003
|
+
.catch((e) => {
|
2013
2004
|
if (e.errno == 'ECONNREFUSED') {
|
2014
2005
|
console.log(e)
|
2015
2006
|
readline.close()
|
2016
2007
|
} else {
|
2017
2008
|
console.log(e)
|
2018
|
-
f()
|
2009
|
+
f()
|
2019
2010
|
}
|
2020
2011
|
})
|
2021
2012
|
})
|
@@ -2028,13 +2019,19 @@ const knowledgeModuleImpl = async ({
|
|
2028
2019
|
}
|
2029
2020
|
try {
|
2030
2021
|
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
2031
|
-
} catch(
|
2032
|
-
console.log('Error', error)
|
2022
|
+
} catch (error) {
|
2023
|
+
console.log('Error', error)
|
2033
2024
|
}
|
2034
2025
|
}
|
2035
2026
|
printConfig()
|
2036
2027
|
} else {
|
2037
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
|
+
}
|
2038
2035
|
setupConfig(config)
|
2039
2036
|
|
2040
2037
|
let loadForTesting = false
|
@@ -2045,14 +2042,14 @@ const knowledgeModuleImpl = async ({
|
|
2045
2042
|
}
|
2046
2043
|
// remove test only stuff
|
2047
2044
|
if (!isProcess && !loadForTesting) {
|
2048
|
-
config.config.operators = config.config.operators.filter(
|
2045
|
+
config.config.operators = config.config.operators.filter((operator) => {
|
2049
2046
|
if (operator.development) {
|
2050
2047
|
return false
|
2051
2048
|
} else {
|
2052
2049
|
return true
|
2053
2050
|
}
|
2054
2051
|
})
|
2055
|
-
config.config.bridges = config.config.bridges.filter(
|
2052
|
+
config.config.bridges = config.config.bridges.filter((bridge) => {
|
2056
2053
|
if (bridge.development) {
|
2057
2054
|
return false
|
2058
2055
|
} else {
|
@@ -2062,13 +2059,9 @@ const knowledgeModuleImpl = async ({
|
|
2062
2059
|
}
|
2063
2060
|
|
2064
2061
|
if (template) {
|
2065
|
-
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
2066
|
-
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.`
|
2067
|
-
throw new Error(error)
|
2068
|
-
}
|
2069
2062
|
try {
|
2070
2063
|
config.load(template.template, template.instance)
|
2071
|
-
} catch(
|
2064
|
+
} catch (e) {
|
2072
2065
|
errorHandler(e)
|
2073
2066
|
}
|
2074
2067
|
}
|
@@ -2104,19 +2097,19 @@ const ensureTestFile = (module, name, type) => {
|
|
2104
2097
|
}
|
2105
2098
|
}
|
2106
2099
|
|
2107
|
-
function where(goUp = 2) {
|
2108
|
-
const e = new Error()
|
2100
|
+
function where (goUp = 2) {
|
2101
|
+
const e = new Error()
|
2109
2102
|
const regexForm1 = /\((.*):(\d+):(\d+)\)$/
|
2110
2103
|
const regexForm2 = /at (.*):(\d+):(\d+)$/
|
2111
|
-
const lines = e.stack.split(
|
2104
|
+
const lines = e.stack.split('\n')
|
2112
2105
|
let line
|
2113
2106
|
for (line of lines.slice(1)) {
|
2114
|
-
if (!(line.includes(
|
2115
|
-
break
|
2107
|
+
if (!(line.includes('config.js:') || line.includes('client.js:'))) {
|
2108
|
+
break
|
2116
2109
|
}
|
2117
2110
|
}
|
2118
2111
|
// const line = e.stack.split("\n")[goUp];
|
2119
|
-
const match = regexForm1.exec(line) || regexForm2.exec(line)
|
2112
|
+
const match = regexForm1.exec(line) || regexForm2.exec(line)
|
2120
2113
|
if (match) {
|
2121
2114
|
return `${match[1]}:${match[2]}`
|
2122
2115
|
} else {
|
@@ -2124,7 +2117,7 @@ function where(goUp = 2) {
|
|
2124
2117
|
}
|
2125
2118
|
}
|
2126
2119
|
|
2127
|
-
function w(func) {
|
2120
|
+
function w (func) {
|
2128
2121
|
func.where = where(3)
|
2129
2122
|
return func
|
2130
2123
|
}
|
@@ -2156,4 +2149,3 @@ module.exports = {
|
|
2156
2149
|
flattens,
|
2157
2150
|
writeTest
|
2158
2151
|
}
|
2159
|
-
|