theprogrammablemind_4wp 7.5.8-beta.0 → 7.5.8-beta.10
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +260 -118
- package/lines.js +1 -1
- package/package.json +1 -1
- package/src/config.js +174 -117
- package/src/generators.js +2 -2
- package/src/helpers.js +19 -3
- package/src/semantics.js +1 -1
package/client.js
CHANGED
@@ -110,6 +110,9 @@ class ErrorReason extends Error {
|
|
110
110
|
const setupArgs = (args, config, logs, hierarchy) => {
|
111
111
|
config.setArgs(args)
|
112
112
|
args.calls = new InitCalls(config.name)
|
113
|
+
if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
|
114
|
+
args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
|
115
|
+
}
|
113
116
|
args.km = (name) => config.getConfig(name)
|
114
117
|
args.error = (context) => {
|
115
118
|
throw new ErrorReason(context)
|
@@ -149,7 +152,10 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
149
152
|
args.g = (c) => config.getGenerators(logs).apply(args, c)
|
150
153
|
args.gp = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: true, isResponse: false, response: false})
|
151
154
|
args.gr = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: false, isResponse: true })
|
152
|
-
|
155
|
+
if (!logs) {
|
156
|
+
debugger
|
157
|
+
}
|
158
|
+
args.e = (c) => config.getEvaluator(args.s, args.calls, logs, c)
|
153
159
|
args.log = (message) => logs.push(message)
|
154
160
|
// config.getAddedArgs(args)
|
155
161
|
args.gs = gs(args.g)
|
@@ -282,7 +288,7 @@ const writeTestFile = (fn, tests) => {
|
|
282
288
|
runtime.fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
283
289
|
}
|
284
290
|
|
285
|
-
const writeTest = (fn, query, objects, generated, paraphrases, responses, contexts, associations, metadata, config, saveDeveloper) => {
|
291
|
+
const writeTest = (fn, query, objects, generated, paraphrases, responses, contexts, associations, metadata, config, saveDeveloper, paraphrasesParenthesized, generatedParenthesized) => {
|
286
292
|
let tests = []
|
287
293
|
if (runtime.fs.existsSync(fn)) {
|
288
294
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
@@ -292,7 +298,19 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
292
298
|
}
|
293
299
|
associations.sort()
|
294
300
|
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
295
|
-
|
301
|
+
debugger
|
302
|
+
results = sortJson({
|
303
|
+
query,
|
304
|
+
paraphrases,
|
305
|
+
responses,
|
306
|
+
contexts,
|
307
|
+
objects: convertToStable(objects),
|
308
|
+
associations,
|
309
|
+
metadata,
|
310
|
+
config,
|
311
|
+
developerTest: saveDeveloper,
|
312
|
+
paraphrasesParenthesized,
|
313
|
+
generatedParenthesized }, { depth: 25 })
|
296
314
|
let wasSet = false;
|
297
315
|
tests.forEach( (test, index) => {
|
298
316
|
if (test.query == query) {
|
@@ -354,11 +372,16 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
354
372
|
const contextsPrime = []
|
355
373
|
const generatedPrime = []
|
356
374
|
const paraphrasesPrime = []
|
375
|
+
const paraphrasesParenthesizedPrime = []
|
376
|
+
const generatedParenthesizedPrime = []
|
357
377
|
const responsesPrime = []
|
358
378
|
const contexts = setupContexts(json.contexts)
|
359
379
|
|
360
380
|
const objects = config.get('objects')
|
361
381
|
const args = { objects, isResponse: true, response: json, isTest, getObjects: getObjects(objects) }
|
382
|
+
if (!json.logs) {
|
383
|
+
json.logs = []
|
384
|
+
}
|
362
385
|
setupArgs(args, config, json.logs, hierarchy)
|
363
386
|
const toDo = [...contexts]
|
364
387
|
args.insert = (context) => toDo.unshift(context)
|
@@ -414,7 +437,13 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
414
437
|
continue
|
415
438
|
}
|
416
439
|
let assumed = { isResponse: true };
|
417
|
-
const generated = config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0]
|
440
|
+
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0] : ''
|
441
|
+
let generatedParenthesized = []
|
442
|
+
if (isTest) {
|
443
|
+
config.parenthesized = true
|
444
|
+
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0] : ''
|
445
|
+
config.parenthesized = false
|
446
|
+
}
|
418
447
|
// assumed = { paraphrase: true, response: false };
|
419
448
|
assumed = { paraphrase: true };
|
420
449
|
args.g = (c) => config.getGenerators(json.logs).apply(args, c, assumed)
|
@@ -423,7 +452,16 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
423
452
|
args.gs = gs(args.g)
|
424
453
|
args.gsp = gs(args.gsp)
|
425
454
|
args.gsr = gs(args.gr)
|
455
|
+
if (isTest) {
|
456
|
+
config.parenthesized = false
|
457
|
+
}
|
426
458
|
const paraphrases = config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0]
|
459
|
+
let paraphrasesParenthesized = []
|
460
|
+
if (isTest) {
|
461
|
+
config.parenthesized = true
|
462
|
+
paraphrasesParenthesized = config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0]
|
463
|
+
config.parenthesized = false
|
464
|
+
}
|
427
465
|
args.g = (c) => config.getGenerators(json.logs).apply(args, c)
|
428
466
|
args.gp = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: true, isResponse: false, response: false })
|
429
467
|
args.gr = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: false })
|
@@ -433,6 +471,10 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
433
471
|
contextsPrime.push(contextPrime)
|
434
472
|
generatedPrime.push(generated)
|
435
473
|
paraphrasesPrime.push(paraphrases)
|
474
|
+
if (isTest) {
|
475
|
+
paraphrasesParenthesizedPrime.push(paraphrasesParenthesized)
|
476
|
+
generatedParenthesizedPrime.push(generatedParenthesized)
|
477
|
+
}
|
436
478
|
if (contextPrime.isResponse) {
|
437
479
|
responsesPrime.push(generated)
|
438
480
|
} else {
|
@@ -442,7 +484,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
442
484
|
// add results to processed list
|
443
485
|
config.config.objects.processed = config.config.objects.processed || []
|
444
486
|
config.config.objects.processed = config.config.objects.processed.slice(0, 5)
|
445
|
-
config.config.objects.processed.unshift({ context: contextPrime, paraphrases: paraphrases, responses: responsesPrime })
|
487
|
+
config.config.objects.processed.unshift({ context: contextPrime, paraphrases: paraphrases, paraphrasesParenthesized, generatedParenthesized, responses: responsesPrime })
|
446
488
|
} catch (e) {
|
447
489
|
if (Array.isArray(e)) {
|
448
490
|
e = {
|
@@ -462,7 +504,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
462
504
|
throw e
|
463
505
|
}
|
464
506
|
}
|
465
|
-
return { contextsPrime, generatedPrime, paraphrasesPrime, responsesPrime }
|
507
|
+
return { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime }
|
466
508
|
}
|
467
509
|
|
468
510
|
const doWithRetries = async (n, url, queryParams, data) => {
|
@@ -484,17 +526,17 @@ const doWithRetries = async (n, url, queryParams, data) => {
|
|
484
526
|
}
|
485
527
|
if (result.status === 504) {
|
486
528
|
if (n === 0) {
|
487
|
-
throw `Error ${result.status} - ${result.statusText}`
|
529
|
+
throw new Error(`Error ${result.status} - ${result.statusText}`)
|
488
530
|
} else {
|
489
531
|
continue
|
490
532
|
}
|
491
533
|
}
|
492
534
|
if (result.status >= 500 && result.status < 600) {
|
493
|
-
throw `Error ${result.status} - ${result.statusText}.`
|
535
|
+
throw new Error(`Error ${result.status} - ${result.statusText}.`)
|
494
536
|
} if (result.status >= 404) {
|
495
|
-
throw `Error ${result.status} - ${result.statusText} - Trying it connect to ${url}`
|
537
|
+
throw new Error(`Error ${result.status} - ${result.statusText} - Trying it connect to ${url}`)
|
496
538
|
} else {
|
497
|
-
throw `Error ${result.status} - ${result.statusText}`
|
539
|
+
throw new Error(`Error ${result.status} - ${result.statusText}`)
|
498
540
|
}
|
499
541
|
}
|
500
542
|
}
|
@@ -589,6 +631,8 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
589
631
|
contexts: [],
|
590
632
|
generated: [],
|
591
633
|
paraphrases: [],
|
634
|
+
paraphrasesParenthesized: [],
|
635
|
+
generatedParenthesized: [],
|
592
636
|
responses: [],
|
593
637
|
associations: [],
|
594
638
|
}
|
@@ -624,7 +668,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
624
668
|
if (json.status !== 200) {
|
625
669
|
throw json
|
626
670
|
} else {
|
627
|
-
const { contextsPrime, generatedPrime, paraphrasesPrime, responsesPrime } =
|
671
|
+
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
628
672
|
processContextsB({ isTest, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
629
673
|
response.associations = json.associations
|
630
674
|
response.hierarchy = json.hierarchy
|
@@ -641,6 +685,8 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
641
685
|
response.contexts = response.contexts.concat(contextsPrime)
|
642
686
|
response.generated = response.generated.concat(generatedPrime)
|
643
687
|
response.paraphrases = response.paraphrases.concat(paraphrasesPrime)
|
688
|
+
response.paraphrasesParenthesized = response.paraphrasesParenthesized.concat(paraphrasesParenthesizedPrime)
|
689
|
+
response.generatedParenthesized = response.generatedParenthesized.concat(generatedParenthesizedPrime)
|
644
690
|
response.responses = response.responses.concat(responsesPrime)
|
645
691
|
queries = queries.slice(1)
|
646
692
|
}
|
@@ -648,13 +694,13 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
648
694
|
|
649
695
|
if (writeTests) {
|
650
696
|
const actual_config = getConfigForTest(config, testConfig)
|
651
|
-
writeTest(testsFN, query, config.config.objects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper)
|
697
|
+
writeTest(testsFN, query, config.config.objects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized)
|
652
698
|
}
|
653
699
|
|
654
700
|
return response
|
655
701
|
} catch(error) {
|
656
702
|
error.query = query
|
657
|
-
|
703
|
+
errorHandler(error)
|
658
704
|
}
|
659
705
|
}
|
660
706
|
|
@@ -688,11 +734,13 @@ const getConfigForTest = (config, testConfig) => {
|
|
688
734
|
return configForTest
|
689
735
|
}
|
690
736
|
|
691
|
-
const runTest = async (config, expected, { verbose, afterTest, testConfig, debug }) => {
|
737
|
+
const runTest = async (config, expected, { args, verbose, afterTest, testConfig, debug }) => {
|
692
738
|
const test = expected.query
|
693
739
|
// initialize in between test so state is not preserved since the test was adding without state
|
694
740
|
config.rebuild()
|
695
|
-
|
741
|
+
if (!args.dontAddAssociations) {
|
742
|
+
config.addAssociationsFromTests(config.tests)
|
743
|
+
}
|
696
744
|
// config.addAssocationsFromTests(
|
697
745
|
const errorHandler = (error) => {
|
698
746
|
if (error.metadata) {
|
@@ -727,8 +775,11 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
|
|
727
775
|
lines.log()
|
728
776
|
}
|
729
777
|
const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
|
778
|
+
delete expected_objects.nameToUUID
|
730
779
|
const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
|
731
780
|
const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
|
781
|
+
const failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
|
782
|
+
const failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
|
732
783
|
const failed_responses = !matching(result.responses, expected.responses)
|
733
784
|
const failed_contexts = !matching(result.contexts, expected.contexts)
|
734
785
|
const failed_objects = !matching(actual_objects, expected_objects)
|
@@ -773,7 +824,7 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
|
|
773
824
|
const actual_config = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
|
774
825
|
const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
|
775
826
|
const failed_config = !matching(actual_config, expected_config)
|
776
|
-
let failed = failed_paraphrases || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked
|
827
|
+
let failed = failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked
|
777
828
|
if (!failed) {
|
778
829
|
if (config.afterTest) {
|
779
830
|
failed = config.afterTest({ query: test, expected, actual: result, config })
|
@@ -781,8 +832,26 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
|
|
781
832
|
return {
|
782
833
|
utterance: test,
|
783
834
|
errorFromAfterTest: failed,
|
784
|
-
expected: {
|
785
|
-
|
835
|
+
expected: {
|
836
|
+
responses: expected.responses,
|
837
|
+
paraphrases: expected.paraphrases,
|
838
|
+
paraphrasesParenthesized: expected.paraphrasesParenthesized,
|
839
|
+
generatedParenthesized: expected.generatedParenthesized,
|
840
|
+
results: expected.contexts,
|
841
|
+
checked: expected_checked,
|
842
|
+
objects: expected_objects,
|
843
|
+
config: expected.config
|
844
|
+
},
|
845
|
+
actual: {
|
846
|
+
responses: result.responses,
|
847
|
+
paraphrases: result.paraphrases,
|
848
|
+
paraphrasesParenthesized: result.paraphrasesParenthesized,
|
849
|
+
generatedParenthesized: result.generatedParenthesized,
|
850
|
+
results: result.contexts,
|
851
|
+
checked: actual_checked,
|
852
|
+
objects: actual_objects,
|
853
|
+
config: actual_config
|
854
|
+
}
|
786
855
|
}
|
787
856
|
}
|
788
857
|
}
|
@@ -798,8 +867,26 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
|
|
798
867
|
if (failed) {
|
799
868
|
return {
|
800
869
|
utterance: test,
|
801
|
-
expected: {
|
802
|
-
|
870
|
+
expected: {
|
871
|
+
responses: expected.responses,
|
872
|
+
paraphrases: expected.paraphrases,
|
873
|
+
paraphrasesParenthesized: expected.paraphrasesParenthesized,
|
874
|
+
generatedParenthesized: expected.generatedParenthesized,
|
875
|
+
results: expected.contexts,
|
876
|
+
checked: expected_checked,
|
877
|
+
objects: expected_objects,
|
878
|
+
config: expected.config
|
879
|
+
},
|
880
|
+
actual: {
|
881
|
+
responses: result.responses,
|
882
|
+
paraphrases: result.paraphrases,
|
883
|
+
paraphrasesParenthesized: result.paraphrasesParenthesized,
|
884
|
+
generatedParenthesized: result.generatedParenthesized,
|
885
|
+
results: result.contexts,
|
886
|
+
checked: actual_checked,
|
887
|
+
objects: actual_objects,
|
888
|
+
config: actual_config
|
889
|
+
}
|
803
890
|
}
|
804
891
|
}
|
805
892
|
} catch(error) {
|
@@ -861,7 +948,7 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
|
|
861
948
|
for (let km of config.configs) {
|
862
949
|
saveObjects.nameToUUID[km.name] = km.uuid
|
863
950
|
}
|
864
|
-
writeTest(testFile, test, saveObjects, result.generated, result.paraphrases, result.responses, result.contexts, result.associations, result.metadata, actualConfig, saveDeveloper)
|
951
|
+
writeTest(testFile, test, saveObjects, result.generated, result.paraphrases, result.responses, result.contexts, result.associations, result.metadata, actualConfig, saveDeveloper, result.paraphrasesParenthesized, result.generatedParenthesized)
|
865
952
|
}
|
866
953
|
|
867
954
|
const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDeveloper) => {
|
@@ -1163,7 +1250,9 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
|
|
1163
1250
|
defaultInnerProcess(config, defaultErrorHandler, results)
|
1164
1251
|
}
|
1165
1252
|
if (results.contexts.length > 1) {
|
1166
|
-
console.log(`query ${query.query}. There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
1253
|
+
console.log(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
1254
|
+
} else if (results.paraphrases[0] != query.query) {
|
1255
|
+
console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}".`)
|
1167
1256
|
} else {
|
1168
1257
|
console.log(`query ${query.query}`)
|
1169
1258
|
}
|
@@ -1272,19 +1361,19 @@ const knowledgeModule = async ({
|
|
1272
1361
|
const testConfig = test
|
1273
1362
|
|
1274
1363
|
if (!moduleFromJSFile) {
|
1275
|
-
throw "'module' is a required parameter. The value should be either 'module' or a lambda that will be called when the file is acting as a module."
|
1364
|
+
throw new Error("'module' is a required parameter. The value should be either 'module' or a lambda that will be called when the file is acting as a module.")
|
1276
1365
|
}
|
1277
1366
|
if (!config) {
|
1278
|
-
throw "'config' is a required parameter. The value should the config that defines the knowledge module."
|
1367
|
+
throw new Error("'config' is a required parameter. The value should the config that defines the knowledge module.")
|
1279
1368
|
}
|
1280
1369
|
if (!config.name) {
|
1281
|
-
throw "config must have 'name' set to the knowledge module name."
|
1370
|
+
throw new Error("config must have 'name' set to the knowledge module name.")
|
1282
1371
|
}
|
1283
1372
|
if (!description) {
|
1284
|
-
throw "'description' is a required parameter. The value should the description of the knowledge module."
|
1373
|
+
throw new Error("'description' is a required parameter. The value should the description of the knowledge module.")
|
1285
1374
|
}
|
1286
1375
|
if (!test) {
|
1287
|
-
throw "'test' is a required parameter. The value should the path to the file used to store the tests of the knowledge module and the contents of the file in the form { name: <filePath>, contexts: <json> }."
|
1376
|
+
throw new Error("'test' is a required parameter. The value should the path to the file used to store the tests of the knowledge module and the contents of the file in the form { name: <filePath>, contexts: <json> }.")
|
1288
1377
|
}
|
1289
1378
|
|
1290
1379
|
const isProcess = require.main === moduleFromJSFile
|
@@ -1342,9 +1431,13 @@ const knowledgeModule = async ({
|
|
1342
1431
|
if (!isProcess) {
|
1343
1432
|
if (template) {
|
1344
1433
|
if (config.needsRebuild(template.template, template.instance)) {
|
1345
|
-
throw `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguements or the -rt argument to rebuild.`
|
1434
|
+
throw new Error(`This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguements or the -rt argument to rebuild.`)
|
1435
|
+
}
|
1436
|
+
try {
|
1437
|
+
config.load(template.template, template.instance)
|
1438
|
+
} catch( e ) {
|
1439
|
+
errorHandler(e)
|
1346
1440
|
}
|
1347
|
-
config.load(template.template, template.instance)
|
1348
1441
|
}
|
1349
1442
|
}
|
1350
1443
|
if (isProcess) {
|
@@ -1353,6 +1446,13 @@ const knowledgeModule = async ({
|
|
1353
1446
|
description: 'Entodicton knowledge module'
|
1354
1447
|
})
|
1355
1448
|
|
1449
|
+
const helpDebugAssociation = 'In order to get a debug break when a specific association is created set the DEBUG_ASSOCIATION environment variable to the JSON of the association to break on. For example DEBUG_ASSOCIATION=\'["the#0", "mammel#0"]\' })'
|
1450
|
+
const helpDebugHierarchy = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_HIERARCHY environment variable to the JSON of the child-parent pair to break on. For example DEBUG_HIERARCHY=\'["cat#1", "mammel#1"]\' })'
|
1451
|
+
const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'["verb#0", "article#0"]\' })'
|
1452
|
+
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\' })'
|
1453
|
+
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]))\' })'
|
1454
|
+
|
1455
|
+
|
1356
1456
|
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
1357
1457
|
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1358
1458
|
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' })
|
@@ -1370,6 +1470,7 @@ const knowledgeModule = async ({
|
|
1370
1470
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
1371
1471
|
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
1372
1472
|
parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
|
1473
|
+
parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
|
1373
1474
|
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
1374
1475
|
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
1375
1476
|
parser.add_argument('-daa', '--dontAddAssociations', { action: 'store_true', help: 'Do not add associations from the tests.' })
|
@@ -1379,30 +1480,38 @@ const knowledgeModule = async ({
|
|
1379
1480
|
parser.add_argument('-dic', '--debugIncludeConvolutions', { action: 'store_true', help: 'When running with the --debugIncludeConvolutions flag the logs will include convolutions which are somewhat annoying verbose. Default is false' })
|
1380
1481
|
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 '})
|
1381
1482
|
parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
|
1382
|
-
parser.add_argument('-da', '--debugAssociation', { help:
|
1383
|
-
parser.add_argument('-dh', '--debugHierarchy', { help:
|
1384
|
-
parser.add_argument('-
|
1385
|
-
parser.add_argument('-
|
1483
|
+
parser.add_argument('-da', '--debugAssociation', { help: helpDebugAssociation })
|
1484
|
+
parser.add_argument('-dh', '--debugHierarchy', { help: helpDebugHierarchy })
|
1485
|
+
parser.add_argument('-dp', '--debugPriority', { help: helpDebugPriority })
|
1486
|
+
parser.add_argument('-db', '--debugBridge', { help: helpDebugBridge })
|
1487
|
+
parser.add_argument('-do', '--debugOperator', { help: helpDebugOperator })
|
1386
1488
|
|
1387
1489
|
const args = parser.parse_args()
|
1388
1490
|
args.count = args.count || 1
|
1389
1491
|
|
1492
|
+
if (args.parenthesized) {
|
1493
|
+
config.parenthesized = true
|
1494
|
+
}
|
1495
|
+
|
1390
1496
|
if (args.debugAssociation) {
|
1391
|
-
|
1497
|
+
console.log(helpDebugAssociation)
|
1498
|
+
runtime.process.exit(-1)
|
1392
1499
|
}
|
1393
1500
|
if (args.debugHierarchy) {
|
1394
|
-
|
1501
|
+
console.log(helpDebugHierarchy)
|
1502
|
+
runtime.process.exit(-1)
|
1503
|
+
}
|
1504
|
+
if (args.debugPriority) {
|
1505
|
+
console.log(helpDebugPriority)
|
1506
|
+
runtime.process.exit(-1)
|
1395
1507
|
}
|
1396
1508
|
if (args.debugBridge) {
|
1397
|
-
|
1398
|
-
|
1399
|
-
if (global.entodictonDebugBridge.length !== 2) {
|
1400
|
-
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
|
1401
|
-
}
|
1509
|
+
console.log(helpDebugBridge)
|
1510
|
+
runtime.process.exit(-1)
|
1402
1511
|
}
|
1403
1512
|
if (args.debugOperator) {
|
1404
|
-
|
1405
|
-
|
1513
|
+
console.log(helpDebugOperator)
|
1514
|
+
runtime.process.exit(-1)
|
1406
1515
|
}
|
1407
1516
|
|
1408
1517
|
if (args.clean) {
|
@@ -1471,87 +1580,94 @@ const knowledgeModule = async ({
|
|
1471
1580
|
}
|
1472
1581
|
*/
|
1473
1582
|
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
for (const test of config.tests) {
|
1479
|
-
console.log(`${counter} - ${test.query}`)
|
1480
|
-
counter += 1
|
1481
|
-
}
|
1482
|
-
}
|
1483
|
-
if (args.print.includes('c')) {
|
1484
|
-
const { data } = setupProcessB({ config })
|
1485
|
-
console.log("Config as sent to server")
|
1486
|
-
console.log(JSON.stringify(data, null, 2));
|
1583
|
+
let configPrinted = false
|
1584
|
+
const printConfig = () => {
|
1585
|
+
if (configPrinted) {
|
1586
|
+
return
|
1487
1587
|
}
|
1588
|
+
configPrinted = true
|
1589
|
+
if (args.print) {
|
1590
|
+
if (args.print.includes('t')) {
|
1591
|
+
console.log("Test queries")
|
1592
|
+
let counter = 0
|
1593
|
+
for (const test of config.tests) {
|
1594
|
+
console.log(`${counter} - ${test.query}`)
|
1595
|
+
counter += 1
|
1596
|
+
}
|
1597
|
+
}
|
1598
|
+
if (args.print.includes('c')) {
|
1599
|
+
const { data } = setupProcessB({ config })
|
1600
|
+
console.log("Config as sent to server")
|
1601
|
+
console.log(JSON.stringify(data, null, 2));
|
1602
|
+
}
|
1488
1603
|
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1604
|
+
if (args.print.includes('l')) {
|
1605
|
+
console.log('Module load ordering')
|
1606
|
+
for (const km of config.configs) {
|
1607
|
+
console.log(` ${km.name}`)
|
1608
|
+
}
|
1493
1609
|
}
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1610
|
+
if (args.print.includes('w')) {
|
1611
|
+
for (const word in config.config.words) {
|
1612
|
+
console.log(word.concat(' ', ...config.config.words[word].map((def) => JSON.stringify(def))))
|
1613
|
+
}
|
1498
1614
|
}
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1615
|
+
if (args.print.includes('b')) {
|
1616
|
+
for (const bridge of config.config.bridges) {
|
1617
|
+
console.log(JSON.stringify(bridge))
|
1618
|
+
}
|
1503
1619
|
}
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1620
|
+
if (args.print.includes('o')) {
|
1621
|
+
for (const operator of config.config.operators) {
|
1622
|
+
console.log(JSON.stringify(operator))
|
1623
|
+
}
|
1508
1624
|
}
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1625
|
+
if (args.print.includes('j')) {
|
1626
|
+
const { data } = setupProcessB( { config } )
|
1627
|
+
console.log(JSON.stringify(data, null, 2))
|
1628
|
+
}
|
1629
|
+
if (args.print.includes('a')) {
|
1630
|
+
console.log('associations ================')
|
1631
|
+
const properties = ['negative', 'positive']
|
1632
|
+
for (let property of properties) {
|
1633
|
+
console.log(` ${property} ===============`)
|
1634
|
+
for (let association of config.config.associations[property]) {
|
1635
|
+
console.log(` ${JSON.stringify(association)}`)
|
1636
|
+
}
|
1521
1637
|
}
|
1522
1638
|
}
|
1523
|
-
|
1524
|
-
|
1525
|
-
console.log(JSON.stringify(config.config.objects, null, 2))
|
1526
|
-
}
|
1527
|
-
if (args.print.includes('p')) {
|
1528
|
-
for (let priority of config.config.priorities) {
|
1529
|
-
console.log(JSON.stringify(priority))
|
1639
|
+
if (args.print.includes('d')) {
|
1640
|
+
console.log(JSON.stringify(config.config.objects, null, 2))
|
1530
1641
|
}
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1642
|
+
if (args.print.includes('p')) {
|
1643
|
+
for (let priority of config.config.priorities) {
|
1644
|
+
console.log(JSON.stringify(priority))
|
1645
|
+
}
|
1535
1646
|
}
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
for (const semantic of easyToRead) {
|
1540
|
-
semantic.match = semantic.match.toString()
|
1541
|
-
semantic.apply = semantic.apply.toString()
|
1542
|
-
if (semantic.applyWrapped) {
|
1543
|
-
semantic.applyWrapped = semantic.applyWrapped.toString()
|
1647
|
+
if (args.print.includes('h')) {
|
1648
|
+
for (let edge of config.config.hierarchy) {
|
1649
|
+
console.log(JSON.stringify(edge))
|
1544
1650
|
}
|
1545
1651
|
}
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1652
|
+
if (args.print.includes('g')) {
|
1653
|
+
const easyToRead = _.cloneDeep(config.config.generators)
|
1654
|
+
for (const semantic of easyToRead) {
|
1655
|
+
semantic.match = semantic.match.toString()
|
1656
|
+
semantic.apply = semantic.apply.toString()
|
1657
|
+
if (semantic.applyWrapped) {
|
1658
|
+
semantic.applyWrapped = semantic.applyWrapped.toString()
|
1659
|
+
}
|
1660
|
+
}
|
1661
|
+
console.dir(easyToRead)
|
1662
|
+
}
|
1663
|
+
if (args.print.includes('s')) {
|
1664
|
+
const easyToRead = _.cloneDeep(config.config.semantics)
|
1665
|
+
for (const semantic of easyToRead) {
|
1666
|
+
semantic.match = semantic.match.toString()
|
1667
|
+
semantic.apply = semantic.apply.toString()
|
1668
|
+
}
|
1669
|
+
console.dir(easyToRead)
|
1553
1670
|
}
|
1554
|
-
console.dir(easyToRead)
|
1555
1671
|
}
|
1556
1672
|
}
|
1557
1673
|
|
@@ -1586,12 +1702,7 @@ const knowledgeModule = async ({
|
|
1586
1702
|
test = useTestConfig.name
|
1587
1703
|
|
1588
1704
|
}
|
1589
|
-
runTests(config, test, { debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1590
|
-
if (results.length > 0 && args.vimdiff) {
|
1591
|
-
for (const result of results) {
|
1592
|
-
vimdiff(result.actual, result.expected)
|
1593
|
-
}
|
1594
|
-
}
|
1705
|
+
runTests(config, test, { args, debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1595
1706
|
let newError = false
|
1596
1707
|
if (results.length > 0) {
|
1597
1708
|
let headerShown = false
|
@@ -1601,6 +1712,12 @@ const knowledgeModule = async ({
|
|
1601
1712
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1602
1713
|
hasError = true
|
1603
1714
|
}
|
1715
|
+
if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
|
1716
|
+
hasError = true
|
1717
|
+
}
|
1718
|
+
if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
|
1719
|
+
hasError = true
|
1720
|
+
}
|
1604
1721
|
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1605
1722
|
hasError = true
|
1606
1723
|
}
|
@@ -1613,6 +1730,22 @@ const knowledgeModule = async ({
|
|
1613
1730
|
console.log('**************************** ERRORS ************************')
|
1614
1731
|
for (const result of results) {
|
1615
1732
|
console.log('Utterance: ', result.utterance)
|
1733
|
+
const show = (label, expected, actual) => {
|
1734
|
+
if (JSON.stringify(expected) !== JSON.stringify(actual)) {
|
1735
|
+
if (!headerShown) {
|
1736
|
+
console.log(' Failure')
|
1737
|
+
}
|
1738
|
+
console.log(` expected ${label}`, expected)
|
1739
|
+
console.log(` actual ${label} `, actual)
|
1740
|
+
newError = true
|
1741
|
+
headerShown = true
|
1742
|
+
}
|
1743
|
+
}
|
1744
|
+
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1745
|
+
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
1746
|
+
show('responses', result.expected.responses, result.actual.responses)
|
1747
|
+
show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
|
1748
|
+
/*
|
1616
1749
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1617
1750
|
if (!headerShown) {
|
1618
1751
|
console.log(' Failure')
|
@@ -1631,6 +1764,7 @@ const knowledgeModule = async ({
|
|
1631
1764
|
newError = true
|
1632
1765
|
headerShown = true
|
1633
1766
|
}
|
1767
|
+
*/
|
1634
1768
|
if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
|
1635
1769
|
if (!headerShown) {
|
1636
1770
|
console.log(' Failure')
|
@@ -1650,6 +1784,12 @@ const knowledgeModule = async ({
|
|
1650
1784
|
headerShown = true
|
1651
1785
|
}
|
1652
1786
|
}
|
1787
|
+
} else {
|
1788
|
+
if (results.length > 0 && args.vimdiff) {
|
1789
|
+
for (const result of results) {
|
1790
|
+
vimdiff(result.actual, result.expected)
|
1791
|
+
}
|
1792
|
+
}
|
1653
1793
|
}
|
1654
1794
|
if (!headerShown) {
|
1655
1795
|
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
@@ -1686,7 +1826,7 @@ const knowledgeModule = async ({
|
|
1686
1826
|
console.log(results.responses.join(' '))
|
1687
1827
|
})
|
1688
1828
|
if (!('then' in promise)) {
|
1689
|
-
throw 'Return a promise from process in the definition of knowledgeModule'
|
1829
|
+
throw new Error('Return a promise from process in the definition of knowledgeModule')
|
1690
1830
|
}
|
1691
1831
|
promise
|
1692
1832
|
.then(() => {
|
@@ -1711,11 +1851,12 @@ const knowledgeModule = async ({
|
|
1711
1851
|
}
|
1712
1852
|
config.beforeQuery({ query: args.query, isModule: false, objects })
|
1713
1853
|
try {
|
1714
|
-
processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1854
|
+
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1715
1855
|
} catch( error ) {
|
1716
1856
|
console.log('Error', error);
|
1717
1857
|
}
|
1718
1858
|
}
|
1859
|
+
printConfig()
|
1719
1860
|
} else {
|
1720
1861
|
config.addAssociationsFromTests(config.tests);
|
1721
1862
|
//for (let query in config.tests) {
|
@@ -1723,6 +1864,7 @@ const knowledgeModule = async ({
|
|
1723
1864
|
//}
|
1724
1865
|
module()
|
1725
1866
|
}
|
1867
|
+
|
1726
1868
|
}
|
1727
1869
|
|
1728
1870
|
/*
|
package/lines.js
CHANGED
@@ -13,7 +13,7 @@ class Lines {
|
|
13
13
|
setElement (row, column, value) {
|
14
14
|
const values = value.toString().split('\n')
|
15
15
|
if (column >= this.widths.length) {
|
16
|
-
throw "Column out of range."
|
16
|
+
throw new Error("Column out of range.")
|
17
17
|
}
|
18
18
|
const width = this.widths[column]
|
19
19
|
let index = 0
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -5,6 +5,7 @@ const { Generators } = require('./generators')
|
|
5
5
|
const client = require('../client')
|
6
6
|
const DigraphInternal = require('./digraph_internal')
|
7
7
|
const helpers = require('./helpers')
|
8
|
+
const { ecatch } = require('./helpers')
|
8
9
|
const runtime = require('../runtime')
|
9
10
|
const _ = require('lodash')
|
10
11
|
|
@@ -22,102 +23,131 @@ const indent = (string, indent) => {
|
|
22
23
|
}
|
23
24
|
|
24
25
|
const handleBridgeProps = (config, bridge) => {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
bridge.level = 0
|
30
|
-
}
|
31
|
-
if (bridge.children) {
|
32
|
-
for (let child of bridge.children) {
|
33
|
-
config.addHierarchy(child, bridge.id)
|
34
|
-
}
|
35
|
-
}
|
36
|
-
if (bridge.parents) {
|
37
|
-
for (let parent of bridge.parents) {
|
38
|
-
config.addHierarchy(bridge.id, parent)
|
39
|
-
}
|
40
|
-
}
|
41
|
-
if (bridge.isA) {
|
42
|
-
for (let parent of bridge.isA) {
|
43
|
-
config.addHierarchy(bridge.id, parent)
|
44
|
-
}
|
45
|
-
}
|
46
|
-
if (bridge.before) {
|
47
|
-
for (let after of bridge.before) {
|
48
|
-
if (typeof after == 'string') {
|
49
|
-
after = [after, 0]
|
26
|
+
ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
|
27
|
+
() => {
|
28
|
+
if (!bridge.bridge) {
|
29
|
+
bridge.bridge = "{ ...next(operator) }"
|
50
30
|
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
31
|
+
if (!bridge.level) {
|
32
|
+
bridge.level = 0
|
33
|
+
}
|
34
|
+
if (bridge.children) {
|
35
|
+
for (let child of bridge.children) {
|
36
|
+
config.addHierarchy(child, bridge.id)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
if (bridge.parents) {
|
40
|
+
for (let parent of bridge.parents) {
|
41
|
+
config.addHierarchy(bridge.id, parent)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
if (bridge.isA) {
|
45
|
+
for (let parent of bridge.isA) {
|
46
|
+
config.addHierarchy(bridge.id, parent)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
if (bridge.before) {
|
50
|
+
for (let after of bridge.before) {
|
51
|
+
if (typeof after == 'string') {
|
52
|
+
after = [after, 0]
|
53
|
+
}
|
54
|
+
config.addPriorities([after, [bridge.id, bridge.level]])
|
55
|
+
}
|
56
|
+
}
|
57
|
+
if (bridge.after) {
|
58
|
+
for (let before of bridge.after) {
|
59
|
+
if (typeof before == 'string') {
|
60
|
+
before = [before, 0]
|
61
|
+
}
|
62
|
+
config.addPriorities([[bridge.id, bridge.level], before])
|
63
|
+
}
|
64
|
+
}
|
65
|
+
if (bridge.words) {
|
66
|
+
for (let def of bridge.words) {
|
67
|
+
if (typeof def == 'string') {
|
68
|
+
config.addWordInternal(def, {"id": bridge.id, "initial": `{ value: "${def}"}` })
|
69
|
+
} else {
|
70
|
+
const word = def.word
|
71
|
+
def = { initial: JSON.stringify(def), id: bridge.id, word: undefined }
|
72
|
+
config.addWordInternal(word, def)
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
if (bridge.generator) {
|
77
|
+
config.config.generators.unshift(bridge.generator)
|
78
|
+
}
|
79
|
+
if (bridge.generators) {
|
80
|
+
const generators = [...bridge.generators]
|
81
|
+
generators.reverse()
|
82
|
+
for (let generator of generators) {
|
83
|
+
config.config.generators.unshift(generator)
|
84
|
+
}
|
85
|
+
}
|
86
|
+
if (bridge.generatorpr) {
|
87
|
+
bridge.generatorp = bridge.generatorpr
|
88
|
+
bridge.generatorr = bridge.generatorpr
|
89
|
+
}
|
90
|
+
if (bridge.generatorp) {
|
91
|
+
const match = bridge.generatorp.match || (() => true)
|
92
|
+
const apply = typeof bridge.generatorp == 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
|
93
|
+
const level = bridge.generatorp.level >= 0 ? bridge.generatorp.level : bridge.level + 1
|
94
|
+
config.config.generators.unshift({
|
95
|
+
where: bridge.generatorp.where || bridge.where || client.where(4),
|
96
|
+
match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
|
97
|
+
apply: (args) => apply(args),
|
98
|
+
applyWrapped: apply,
|
99
|
+
property: 'generatorp',
|
100
|
+
})
|
101
|
+
}
|
102
|
+
if (bridge.generatorr) {
|
103
|
+
const match = bridge.generatorr.match || (() => true)
|
104
|
+
const apply = typeof bridge.generatorr == 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
|
105
|
+
const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
|
106
|
+
config.config.generators.unshift({
|
107
|
+
where: bridge.generatorr.where || bridge.where || client.where(4),
|
108
|
+
match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
|
109
|
+
apply: (args) => apply(args),
|
110
|
+
applyWrapped: apply,
|
111
|
+
property: 'generatorr',
|
112
|
+
})
|
113
|
+
}
|
114
|
+
/*
|
115
|
+
if (bridge.generatorr) {
|
116
|
+
config.config.generators.unshift({
|
117
|
+
// TODO merge response and isResponse
|
118
|
+
where: bridge.generatorr.where || bridge.where || client.where(3),
|
119
|
+
match: ({context}) => bridge.id == context.marker && !context.paraphrase && (context.response || context.isResponse),
|
120
|
+
apply: (args) => bridge.generatorr(args),
|
121
|
+
applyWrapped: bridge.generatorr,
|
122
|
+
property: 'generatorr',
|
123
|
+
})
|
124
|
+
}
|
125
|
+
*/
|
126
|
+
if (bridge.evaluator) {
|
127
|
+
config.config.semantics.unshift({
|
128
|
+
where: bridge.evaluator.where || bridge.where || client.where(3),
|
129
|
+
match: ({context}) => bridge.id == context.marker && context.evaluate,
|
130
|
+
apply: (args) => bridge.evaluator(args),
|
131
|
+
applyWrapped: bridge.evaluator,
|
132
|
+
property: 'evaluator',
|
133
|
+
})
|
134
|
+
}
|
135
|
+
if (bridge.semantic) {
|
136
|
+
config.config.semantics.unshift({
|
137
|
+
where: bridge.semantic.where || bridge.where || client.where(3),
|
138
|
+
match: ({context}) => bridge.id == context.marker,
|
139
|
+
apply: (args) => bridge.semantic(args),
|
140
|
+
applyWrapped: bridge.semantic,
|
141
|
+
property: 'semantic',
|
142
|
+
})
|
62
143
|
}
|
63
144
|
}
|
64
|
-
|
65
|
-
if (bridge.generator) {
|
66
|
-
config.config.generators.unshift(bridge.generator)
|
67
|
-
}
|
68
|
-
if (bridge.generators) {
|
69
|
-
const generators = [...bridge.generators]
|
70
|
-
generators.reverse()
|
71
|
-
for (let generator of generators) {
|
72
|
-
config.config.generators.unshift(generator)
|
73
|
-
}
|
74
|
-
}
|
75
|
-
if (bridge.generatorpr) {
|
76
|
-
bridge.generatorp = bridge.generatorpr
|
77
|
-
bridge.generatorr = bridge.generatorpr
|
78
|
-
}
|
79
|
-
if (bridge.generatorp) {
|
80
|
-
config.config.generators.unshift({
|
81
|
-
where: bridge.generatorp.where || bridge.where || client.where(4),
|
82
|
-
match: ({context}) => bridge.id == context.marker && context.paraphrase,
|
83
|
-
apply: (args) => bridge.generatorp(args),
|
84
|
-
applyWrapped: bridge.generatorp,
|
85
|
-
property: 'generatorp',
|
86
|
-
})
|
87
|
-
}
|
88
|
-
if (bridge.generatorr) {
|
89
|
-
config.config.generators.unshift({
|
90
|
-
// TODO merge response and isResponse
|
91
|
-
where: bridge.generatorr.where || bridge.where || client.where(3),
|
92
|
-
match: ({context}) => bridge.id == context.marker && !context.paraphrase && (context.response || context.isResponse),
|
93
|
-
apply: (args) => bridge.generatorr(args),
|
94
|
-
applyWrapped: bridge.generatorr,
|
95
|
-
property: 'generatorr',
|
96
|
-
})
|
97
|
-
}
|
98
|
-
if (bridge.evaluator) {
|
99
|
-
config.config.semantics.unshift({
|
100
|
-
where: bridge.evaluator.where || bridge.where || client.where(3),
|
101
|
-
match: ({context}) => bridge.id == context.marker && context.evaluate,
|
102
|
-
apply: (args) => bridge.evaluator(args),
|
103
|
-
applyWrapped: bridge.evaluator,
|
104
|
-
property: 'evaluator',
|
105
|
-
})
|
106
|
-
}
|
107
|
-
if (bridge.semantic) {
|
108
|
-
config.config.semantics.unshift({
|
109
|
-
where: bridge.semantic.where || bridge.where || client.where(3),
|
110
|
-
match: ({context}) => bridge.id == context.marker,
|
111
|
-
apply: (args) => bridge.semantic(args),
|
112
|
-
applyWrapped: bridge.semantic,
|
113
|
-
property: 'semantic',
|
114
|
-
})
|
115
|
-
}
|
145
|
+
)
|
116
146
|
}
|
117
147
|
|
118
148
|
const handleCalculatedProps = (baseConfig, moreConfig) => {
|
119
149
|
for (let bridge of moreConfig.bridges) {
|
120
|
-
const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
150
|
+
const valid = [ 'after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
121
151
|
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where' ]
|
122
152
|
helpers.validProps(valid, bridge, 'bridge')
|
123
153
|
handleBridgeProps(baseConfig, bridge)
|
@@ -137,13 +167,21 @@ if (runtime.process.env.DEBUG_HIERARCHY) {
|
|
137
167
|
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
138
168
|
}
|
139
169
|
|
170
|
+
if (runtime.process.env.DEBUG_PRIORITY) {
|
171
|
+
global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITY)
|
172
|
+
}
|
173
|
+
|
174
|
+
if (runtime.process.env.DEBUG_ASSOCIATION) {
|
175
|
+
global.entodictonDebugAssociation = JSON.parse(runtime.process.env.DEBUG_ASSOCIATION)
|
176
|
+
}
|
177
|
+
|
140
178
|
if (runtime.process.env.DEBUG_BRIDGE) {
|
141
179
|
// id/level
|
142
180
|
global.entodictonDebugBridge = runtime.process.env.DEBUG_BRIDGE.split('/')
|
143
181
|
if (global.entodictonDebugBridge.length !== 2) {
|
144
182
|
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
|
145
183
|
}
|
146
|
-
global.entodictonDebugBridge[1] =
|
184
|
+
global.entodictonDebugBridge[1] = parseInt(global.entodictonDebugBridge[1])
|
147
185
|
}
|
148
186
|
|
149
187
|
if (runtime.process.env.DEBUG_OPERATOR) {
|
@@ -161,7 +199,7 @@ const hierarchyCanonical = (element) => {
|
|
161
199
|
|
162
200
|
const isValidDef = (word, def, config) => {
|
163
201
|
if (!def.id) {
|
164
|
-
throw `In the KM "${config.name}", for the word ${word} the following definition is missing the "id" property: ${JSON.stringify(def)}`
|
202
|
+
throw new Error(`In the KM "${config.name}", for the word ${word} the following definition is missing the "id" property: ${JSON.stringify(def)}`)
|
165
203
|
}
|
166
204
|
/*
|
167
205
|
if (!def.initial) {
|
@@ -614,8 +652,9 @@ class Config {
|
|
614
652
|
return instance
|
615
653
|
}
|
616
654
|
*/
|
617
|
-
getEvaluator (s, log, context) {
|
655
|
+
getEvaluator (s, calls, log, context) {
|
618
656
|
const instance = s({ ...context, evaluate: true })
|
657
|
+
calls.touch(instance)
|
619
658
|
if (!instance.evalue && !instance.verbatim && !instance.value) {
|
620
659
|
this.warningNotEvaluated(log, context);
|
621
660
|
}
|
@@ -723,7 +762,7 @@ class Config {
|
|
723
762
|
"semantics",
|
724
763
|
"associations",
|
725
764
|
]
|
726
|
-
return !properties.find( (property) => instance[property].length > 0 )
|
765
|
+
return !properties.find( (property) => instance[property] && instance[property].length > 0 )
|
727
766
|
}
|
728
767
|
if (!isEmpty(instance)) {
|
729
768
|
instance.name = this.name
|
@@ -777,10 +816,15 @@ class Config {
|
|
777
816
|
if (!this.config.priorities) {
|
778
817
|
this.config.priorities = []
|
779
818
|
}
|
819
|
+
if (global.entodictonDebugPriority) {
|
820
|
+
if (helpers.safeEquals(entodictonDebugPriority, priorities)) {
|
821
|
+
debugger; // debug hierarchy hit
|
822
|
+
}
|
823
|
+
}
|
780
824
|
this.config.priorities.push(priorities)
|
781
825
|
this._delta.json.priorities.push({ action: 'add', priorities })
|
782
826
|
}
|
783
|
-
|
827
|
+
|
784
828
|
addHierarchy (child, parent) {
|
785
829
|
if (child && parent || !child || Array.isArray(child) || (typeof child == 'string' && !parent)) {
|
786
830
|
this.addHierarchyChildParent(child, parent)
|
@@ -793,13 +837,13 @@ class Config {
|
|
793
837
|
addHierarchyProperties (edge) {
|
794
838
|
const { child, parent } = edge
|
795
839
|
if (typeof child !== 'string') {
|
796
|
-
throw `addHierarchy expected child property to be a string. got ${JSON.stringify(child)}`
|
840
|
+
throw new Error(`addHierarchy expected child property to be a string. got ${JSON.stringify(child)}`)
|
797
841
|
}
|
798
842
|
if (typeof parent !== 'string') {
|
799
|
-
throw `addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`
|
843
|
+
throw new Error(`addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`)
|
800
844
|
}
|
801
845
|
if (global.entodictonDebugHierarchy) {
|
802
|
-
if (
|
846
|
+
if (helpers.safeEquals(entodictonDebugHierarchy, [child, parent])) {
|
803
847
|
debugger; // debug hierarchy hit
|
804
848
|
}
|
805
849
|
}
|
@@ -810,10 +854,10 @@ class Config {
|
|
810
854
|
|
811
855
|
addHierarchyChildParent (child, parent) {
|
812
856
|
if (typeof child !== 'string') {
|
813
|
-
throw `addHierarchy expected child to be a string. got ${JSON.stringify(child)}`
|
857
|
+
throw new Error(`addHierarchy expected child to be a string. got ${JSON.stringify(child)}`)
|
814
858
|
}
|
815
859
|
if (typeof parent !== 'string') {
|
816
|
-
throw `addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`
|
860
|
+
throw new Error(`addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`)
|
817
861
|
}
|
818
862
|
|
819
863
|
if (global.entodictonDebugHierarchy) {
|
@@ -846,7 +890,7 @@ class Config {
|
|
846
890
|
}
|
847
891
|
const bridges = this.config.bridges
|
848
892
|
const def = Object.assign({}, bridge, { uuid: this._uuid })
|
849
|
-
|
893
|
+
|
850
894
|
if (global.entodictonDebugBridge) {
|
851
895
|
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
852
896
|
debugger; // debug hierarchy hit
|
@@ -874,10 +918,10 @@ class Config {
|
|
874
918
|
}
|
875
919
|
|
876
920
|
if (!(typeof generator.match === 'function')) {
|
877
|
-
throw 'addGenerator: Expected matcher to be a function'
|
921
|
+
throw new Error('addGenerator: Expected matcher to be a function')
|
878
922
|
}
|
879
923
|
if (!(typeof generator.apply === 'function')) {
|
880
|
-
throw 'addGenerator: Expected action to be a function'
|
924
|
+
throw new Error('addGenerator: Expected action to be a function')
|
881
925
|
}
|
882
926
|
|
883
927
|
if (!this.config.generators) {
|
@@ -901,10 +945,10 @@ class Config {
|
|
901
945
|
}
|
902
946
|
|
903
947
|
if (!(typeof semantic.match === 'function')) {
|
904
|
-
throw 'addSemantic: Expected match to be a function'
|
948
|
+
throw new Error('addSemantic: Expected match to be a function')
|
905
949
|
}
|
906
950
|
if (!(typeof semantic.apply === 'function')) {
|
907
|
-
throw 'addSemantic: Expected apply to be a function'
|
951
|
+
throw new Error('addSemantic: Expected apply to be a function')
|
908
952
|
}
|
909
953
|
|
910
954
|
if (!this.config.semantics) {
|
@@ -1178,7 +1222,7 @@ class Config {
|
|
1178
1222
|
// configs = [ { config, namespace } ... ]
|
1179
1223
|
constructor (config, module) {
|
1180
1224
|
if (config instanceof Config) {
|
1181
|
-
throw 'Excepted the config argument to be a hash not a Config object'
|
1225
|
+
throw new Error('Excepted the config argument to be a hash not a Config object')
|
1182
1226
|
}
|
1183
1227
|
|
1184
1228
|
if (config) {
|
@@ -1259,7 +1303,7 @@ class Config {
|
|
1259
1303
|
}
|
1260
1304
|
duplicated = Array.from(duplicated)
|
1261
1305
|
if (duplicated.length > 0) {
|
1262
|
-
throw `In the KM ${config.name}, the following operators are duplicated in the bridges: ${duplicated}`
|
1306
|
+
throw new Error(`In the KM ${config.name}, the following operators are duplicated in the bridges: ${duplicated}`)
|
1263
1307
|
}
|
1264
1308
|
}
|
1265
1309
|
|
@@ -1374,13 +1418,13 @@ class Config {
|
|
1374
1418
|
if (this._api && this._api.multiApi) {
|
1375
1419
|
this._api.add(this, this._api, api)
|
1376
1420
|
} else {
|
1377
|
-
throw "Can only add apis to a multi-api"
|
1421
|
+
throw new Error("Can only add apis to a multi-api")
|
1378
1422
|
}
|
1379
1423
|
}
|
1380
1424
|
|
1381
1425
|
set api (value) {
|
1382
1426
|
if (!value.initialize) {
|
1383
|
-
throw `Expected the API to have an initialize function for ${this.name}.`
|
1427
|
+
throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
|
1384
1428
|
}
|
1385
1429
|
|
1386
1430
|
if (this._api && this._api.multiApi) {
|
@@ -1447,7 +1491,7 @@ class Config {
|
|
1447
1491
|
}
|
1448
1492
|
|
1449
1493
|
doMotivations (args, context) {
|
1450
|
-
args = Object.assign({}, args, { context })
|
1494
|
+
args = Object.assign({}, args, { context, api: this.api })
|
1451
1495
|
// console.log('src/config doMotivations this.uuid', this.uuid)
|
1452
1496
|
// args.objects = args.getObjects(this.uuid)
|
1453
1497
|
const motivations = this.motivations
|
@@ -1682,7 +1726,7 @@ class Config {
|
|
1682
1726
|
for (let option of Object.keys(options)) {
|
1683
1727
|
const validOptions = ['initAfterApi']
|
1684
1728
|
if (!['initAfterApi'].includes(option)) {
|
1685
|
-
throw `For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`
|
1729
|
+
throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
|
1686
1730
|
}
|
1687
1731
|
}
|
1688
1732
|
}
|
@@ -1919,7 +1963,20 @@ class Config {
|
|
1919
1963
|
// TODO change name of config: to baseConfig:
|
1920
1964
|
const kmFn = (name) => this.getConfig(name)
|
1921
1965
|
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
1922
|
-
const args = {
|
1966
|
+
const args = {
|
1967
|
+
isModule,
|
1968
|
+
addWord: aw,
|
1969
|
+
km: kmFn,
|
1970
|
+
hierarchy: this.hierarchy,
|
1971
|
+
config,
|
1972
|
+
baseConfig: this,
|
1973
|
+
currentConfig: config,
|
1974
|
+
uuid: config._uuid,
|
1975
|
+
objects: namespacedObjects,
|
1976
|
+
namespace,
|
1977
|
+
motivation: (m) => config.addMotivation(m),
|
1978
|
+
api: config.api
|
1979
|
+
}
|
1923
1980
|
config.initializerFn(args)
|
1924
1981
|
if (config.initAfterApi) {
|
1925
1982
|
// reverse the list
|
@@ -2307,14 +2364,14 @@ class Config {
|
|
2307
2364
|
|
2308
2365
|
set (property, value) {
|
2309
2366
|
if (!this.config.hasOwnProperty(property)) {
|
2310
|
-
throw `Setting invalid property ${property}`
|
2367
|
+
throw new Error(`Setting invalid property ${property}`)
|
2311
2368
|
}
|
2312
2369
|
|
2313
2370
|
if ('words' == property) {
|
2314
2371
|
for (let word in value) {
|
2315
2372
|
for (let def of value[word]) {
|
2316
2373
|
if (!def['uuid']) {
|
2317
|
-
throw `All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)} for the word '${word}'`
|
2374
|
+
throw new Error(`All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)} for the word '${word}'`)
|
2318
2375
|
}
|
2319
2376
|
}
|
2320
2377
|
}
|
@@ -2323,7 +2380,7 @@ class Config {
|
|
2323
2380
|
if (['operators', 'bridges'].includes(property)) {
|
2324
2381
|
for (let def of value) {
|
2325
2382
|
if (!def['uuid']) {
|
2326
|
-
throw `All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)}`
|
2383
|
+
throw new Error(`All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)}`)
|
2327
2384
|
}
|
2328
2385
|
}
|
2329
2386
|
}
|
@@ -2355,7 +2412,7 @@ class Config {
|
|
2355
2412
|
|
2356
2413
|
add (more) {
|
2357
2414
|
if (more === this) {
|
2358
|
-
throw 'Cannot add an object to itself.'
|
2415
|
+
throw new Error('Cannot add an object to itself.')
|
2359
2416
|
}
|
2360
2417
|
if (!(more instanceof Config)) {
|
2361
2418
|
more = new Config(more)
|
@@ -2523,7 +2580,7 @@ class Config {
|
|
2523
2580
|
this.config[key] = this.config[key].concat(more[key])
|
2524
2581
|
} else {
|
2525
2582
|
if (!(key in this.config)) {
|
2526
|
-
throw `Unexpected property in config ${key}`
|
2583
|
+
throw new Error(`Unexpected property in config ${key}`)
|
2527
2584
|
}
|
2528
2585
|
this.config[key] = more[key]
|
2529
2586
|
}
|
@@ -2641,7 +2698,7 @@ class Config {
|
|
2641
2698
|
this.config[key] = more[key].concat(this.config[key])
|
2642
2699
|
} else {
|
2643
2700
|
if (!(key in this.config)) {
|
2644
|
-
throw `Unexpected property in config ${key}`
|
2701
|
+
throw new Error(`Unexpected property in config ${key}`)
|
2645
2702
|
}
|
2646
2703
|
this.config[key] = more[key]
|
2647
2704
|
}
|
package/src/generators.js
CHANGED
@@ -75,7 +75,7 @@ class Generator {
|
|
75
75
|
|
76
76
|
apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
|
77
77
|
if (!log) {
|
78
|
-
throw 'generators.apply argument log is required'
|
78
|
+
throw new Error('generators.apply argument log is required')
|
79
79
|
}
|
80
80
|
if (baseArgs.call && config && sbaseArgs.calls.stack.length > config.maxDepth) {
|
81
81
|
throw new Error(`Max depth of ${config.maxDepth} for calls has been exceeded. maxDepth can be set on the config object. To see the calls run with the --dl or set the debugLoops property on the config`)
|
@@ -292,7 +292,7 @@ class Generators {
|
|
292
292
|
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
293
293
|
this.logs.push(lines.toString())
|
294
294
|
}
|
295
|
-
contextsPrime.push(generated)
|
295
|
+
contextsPrime.push((config || {}).parenthesized ? "(" + generated + ")" : generated)
|
296
296
|
}
|
297
297
|
return contextsPrime
|
298
298
|
}
|
package/src/helpers.js
CHANGED
@@ -54,6 +54,9 @@ const safeEquals = (v1, v2) => {
|
|
54
54
|
} else if (type == 'function') {
|
55
55
|
return v1.toString() == v2.toString()
|
56
56
|
} else {
|
57
|
+
if (v1.length != v2.length) {
|
58
|
+
return false
|
59
|
+
}
|
57
60
|
for (let key in v1) {
|
58
61
|
if (!safeEquals(v1[key], v2[key])) {
|
59
62
|
return false
|
@@ -235,13 +238,17 @@ const validProps = (valids, object, type) => {
|
|
235
238
|
for (let prop of Object.keys(object)) {
|
236
239
|
let okay = false
|
237
240
|
for (valid of valids) {
|
238
|
-
if (
|
239
|
-
okay =
|
241
|
+
if (typeof valid == 'string') {
|
242
|
+
okay = prop == valid
|
243
|
+
} else {
|
244
|
+
okay = prop.match(valid)
|
245
|
+
}
|
246
|
+
if (okay) {
|
240
247
|
break
|
241
248
|
}
|
242
249
|
}
|
243
250
|
if (!okay) {
|
244
|
-
throw `Unknown property "${prop}" in the ${type}. Valid properties are ${valids}. The ${type} is ${JSON.stringify(object)}`
|
251
|
+
throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids}. The ${type} is ${JSON.stringify(object)}`)
|
245
252
|
}
|
246
253
|
}
|
247
254
|
}
|
@@ -309,7 +316,16 @@ const functionsToStrings = (config) => {
|
|
309
316
|
return config
|
310
317
|
}
|
311
318
|
|
319
|
+
const ecatch = (where, call) => {
|
320
|
+
try {
|
321
|
+
return call()
|
322
|
+
} catch( e ) {
|
323
|
+
throw new Error(`${where} ${e}`)
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
312
327
|
module.exports = {
|
328
|
+
ecatch,
|
313
329
|
functionsToStrings,
|
314
330
|
updateQueries,
|
315
331
|
mapInPlace,
|
package/src/semantics.js
CHANGED
@@ -89,7 +89,7 @@ class Semantic {
|
|
89
89
|
// const ask = baseArgs.getAsk(this.uuid)
|
90
90
|
if (!log) {
|
91
91
|
console.trace()
|
92
|
-
throw 'log is a required argument'
|
92
|
+
throw new Error('log is a required argument')
|
93
93
|
}
|
94
94
|
const contextPrime = Object.assign({}, context)
|
95
95
|
let n = (id) => id
|