theprogrammablemind 7.5.8-beta.2 → 7.5.8-beta.3
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 +131 -25
- package/lines.js +1 -1
- package/package.json +1 -1
- package/src/config.js +66 -29
- package/src/generators.js +2 -2
- package/src/helpers.js +10 -3
- package/src/semantics.js +1 -1
package/client.js
CHANGED
@@ -288,7 +288,7 @@ const writeTestFile = (fn, tests) => {
|
|
288
288
|
runtime.fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
289
289
|
}
|
290
290
|
|
291
|
-
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) => {
|
292
292
|
let tests = []
|
293
293
|
if (runtime.fs.existsSync(fn)) {
|
294
294
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
@@ -298,7 +298,19 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
298
298
|
}
|
299
299
|
associations.sort()
|
300
300
|
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
301
|
-
|
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 })
|
302
314
|
let wasSet = false;
|
303
315
|
tests.forEach( (test, index) => {
|
304
316
|
if (test.query == query) {
|
@@ -360,6 +372,8 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
360
372
|
const contextsPrime = []
|
361
373
|
const generatedPrime = []
|
362
374
|
const paraphrasesPrime = []
|
375
|
+
const paraphrasesParenthesizedPrime = []
|
376
|
+
const generatedParenthesizedPrime = []
|
363
377
|
const responsesPrime = []
|
364
378
|
const contexts = setupContexts(json.contexts)
|
365
379
|
|
@@ -423,7 +437,13 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
423
437
|
continue
|
424
438
|
}
|
425
439
|
let assumed = { isResponse: true };
|
426
|
-
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
|
+
}
|
427
447
|
// assumed = { paraphrase: true, response: false };
|
428
448
|
assumed = { paraphrase: true };
|
429
449
|
args.g = (c) => config.getGenerators(json.logs).apply(args, c, assumed)
|
@@ -432,7 +452,16 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
432
452
|
args.gs = gs(args.g)
|
433
453
|
args.gsp = gs(args.gsp)
|
434
454
|
args.gsr = gs(args.gr)
|
455
|
+
if (isTest) {
|
456
|
+
config.parenthesized = false
|
457
|
+
}
|
435
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
|
+
}
|
436
465
|
args.g = (c) => config.getGenerators(json.logs).apply(args, c)
|
437
466
|
args.gp = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: true, isResponse: false, response: false })
|
438
467
|
args.gr = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: false })
|
@@ -442,6 +471,10 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
442
471
|
contextsPrime.push(contextPrime)
|
443
472
|
generatedPrime.push(generated)
|
444
473
|
paraphrasesPrime.push(paraphrases)
|
474
|
+
if (isTest) {
|
475
|
+
paraphrasesParenthesizedPrime.push(paraphrasesParenthesized)
|
476
|
+
generatedParenthesizedPrime.push(generatedParenthesized)
|
477
|
+
}
|
445
478
|
if (contextPrime.isResponse) {
|
446
479
|
responsesPrime.push(generated)
|
447
480
|
} else {
|
@@ -451,7 +484,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
451
484
|
// add results to processed list
|
452
485
|
config.config.objects.processed = config.config.objects.processed || []
|
453
486
|
config.config.objects.processed = config.config.objects.processed.slice(0, 5)
|
454
|
-
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 })
|
455
488
|
} catch (e) {
|
456
489
|
if (Array.isArray(e)) {
|
457
490
|
e = {
|
@@ -471,7 +504,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
471
504
|
throw e
|
472
505
|
}
|
473
506
|
}
|
474
|
-
return { contextsPrime, generatedPrime, paraphrasesPrime, responsesPrime }
|
507
|
+
return { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime }
|
475
508
|
}
|
476
509
|
|
477
510
|
const doWithRetries = async (n, url, queryParams, data) => {
|
@@ -493,17 +526,17 @@ const doWithRetries = async (n, url, queryParams, data) => {
|
|
493
526
|
}
|
494
527
|
if (result.status === 504) {
|
495
528
|
if (n === 0) {
|
496
|
-
throw `Error ${result.status} - ${result.statusText}`
|
529
|
+
throw new Error(`Error ${result.status} - ${result.statusText}`)
|
497
530
|
} else {
|
498
531
|
continue
|
499
532
|
}
|
500
533
|
}
|
501
534
|
if (result.status >= 500 && result.status < 600) {
|
502
|
-
throw `Error ${result.status} - ${result.statusText}.`
|
535
|
+
throw new Error(`Error ${result.status} - ${result.statusText}.`)
|
503
536
|
} if (result.status >= 404) {
|
504
|
-
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}`)
|
505
538
|
} else {
|
506
|
-
throw `Error ${result.status} - ${result.statusText}`
|
539
|
+
throw new Error(`Error ${result.status} - ${result.statusText}`)
|
507
540
|
}
|
508
541
|
}
|
509
542
|
}
|
@@ -598,6 +631,8 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
598
631
|
contexts: [],
|
599
632
|
generated: [],
|
600
633
|
paraphrases: [],
|
634
|
+
paraphrasesParenthesized: [],
|
635
|
+
generatedParenthesized: [],
|
601
636
|
responses: [],
|
602
637
|
associations: [],
|
603
638
|
}
|
@@ -633,7 +668,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
633
668
|
if (json.status !== 200) {
|
634
669
|
throw json
|
635
670
|
} else {
|
636
|
-
const { contextsPrime, generatedPrime, paraphrasesPrime, responsesPrime } =
|
671
|
+
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
637
672
|
processContextsB({ isTest, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
638
673
|
response.associations = json.associations
|
639
674
|
response.hierarchy = json.hierarchy
|
@@ -650,6 +685,8 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
650
685
|
response.contexts = response.contexts.concat(contextsPrime)
|
651
686
|
response.generated = response.generated.concat(generatedPrime)
|
652
687
|
response.paraphrases = response.paraphrases.concat(paraphrasesPrime)
|
688
|
+
response.paraphrasesParenthesized = response.paraphrasesParenthesized.concat(paraphrasesParenthesizedPrime)
|
689
|
+
response.generatedParenthesized = response.generatedParenthesized.concat(generatedParenthesizedPrime)
|
653
690
|
response.responses = response.responses.concat(responsesPrime)
|
654
691
|
queries = queries.slice(1)
|
655
692
|
}
|
@@ -657,7 +694,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
657
694
|
|
658
695
|
if (writeTests) {
|
659
696
|
const actual_config = getConfigForTest(config, testConfig)
|
660
|
-
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)
|
661
698
|
}
|
662
699
|
|
663
700
|
return response
|
@@ -738,8 +775,11 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
738
775
|
lines.log()
|
739
776
|
}
|
740
777
|
const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
|
778
|
+
delete expected_objects.nameToUUID
|
741
779
|
const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
|
742
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)
|
743
783
|
const failed_responses = !matching(result.responses, expected.responses)
|
744
784
|
const failed_contexts = !matching(result.contexts, expected.contexts)
|
745
785
|
const failed_objects = !matching(actual_objects, expected_objects)
|
@@ -784,7 +824,7 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
784
824
|
const actual_config = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
|
785
825
|
const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
|
786
826
|
const failed_config = !matching(actual_config, expected_config)
|
787
|
-
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
|
788
828
|
if (!failed) {
|
789
829
|
if (config.afterTest) {
|
790
830
|
failed = config.afterTest({ query: test, expected, actual: result, config })
|
@@ -792,8 +832,26 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
792
832
|
return {
|
793
833
|
utterance: test,
|
794
834
|
errorFromAfterTest: failed,
|
795
|
-
expected: {
|
796
|
-
|
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
|
+
}
|
797
855
|
}
|
798
856
|
}
|
799
857
|
}
|
@@ -809,8 +867,26 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
809
867
|
if (failed) {
|
810
868
|
return {
|
811
869
|
utterance: test,
|
812
|
-
expected: {
|
813
|
-
|
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
|
+
}
|
814
890
|
}
|
815
891
|
}
|
816
892
|
} catch(error) {
|
@@ -872,7 +948,7 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
|
|
872
948
|
for (let km of config.configs) {
|
873
949
|
saveObjects.nameToUUID[km.name] = km.uuid
|
874
950
|
}
|
875
|
-
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)
|
876
952
|
}
|
877
953
|
|
878
954
|
const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDeveloper) => {
|
@@ -1174,7 +1250,9 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
|
|
1174
1250
|
defaultInnerProcess(config, defaultErrorHandler, results)
|
1175
1251
|
}
|
1176
1252
|
if (results.contexts.length > 1) {
|
1177
|
-
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]}".`)
|
1178
1256
|
} else {
|
1179
1257
|
console.log(`query ${query.query}`)
|
1180
1258
|
}
|
@@ -1283,19 +1361,19 @@ const knowledgeModule = async ({
|
|
1283
1361
|
const testConfig = test
|
1284
1362
|
|
1285
1363
|
if (!moduleFromJSFile) {
|
1286
|
-
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.")
|
1287
1365
|
}
|
1288
1366
|
if (!config) {
|
1289
|
-
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.")
|
1290
1368
|
}
|
1291
1369
|
if (!config.name) {
|
1292
|
-
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.")
|
1293
1371
|
}
|
1294
1372
|
if (!description) {
|
1295
|
-
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.")
|
1296
1374
|
}
|
1297
1375
|
if (!test) {
|
1298
|
-
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> }.")
|
1299
1377
|
}
|
1300
1378
|
|
1301
1379
|
const isProcess = require.main === moduleFromJSFile
|
@@ -1353,7 +1431,7 @@ const knowledgeModule = async ({
|
|
1353
1431
|
if (!isProcess) {
|
1354
1432
|
if (template) {
|
1355
1433
|
if (config.needsRebuild(template.template, template.instance)) {
|
1356
|
-
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.`)
|
1357
1435
|
}
|
1358
1436
|
try {
|
1359
1437
|
config.load(template.template, template.instance)
|
@@ -1392,6 +1470,7 @@ const knowledgeModule = async ({
|
|
1392
1470
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
1393
1471
|
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
1394
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.' })
|
1395
1474
|
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
1396
1475
|
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
1397
1476
|
parser.add_argument('-daa', '--dontAddAssociations', { action: 'store_true', help: 'Do not add associations from the tests.' })
|
@@ -1410,6 +1489,10 @@ const knowledgeModule = async ({
|
|
1410
1489
|
const args = parser.parse_args()
|
1411
1490
|
args.count = args.count || 1
|
1412
1491
|
|
1492
|
+
if (args.parenthesized) {
|
1493
|
+
config.parenthesized = true
|
1494
|
+
}
|
1495
|
+
|
1413
1496
|
if (args.debugAssociation) {
|
1414
1497
|
console.log(helpDebugAssociation)
|
1415
1498
|
runtime.process.exit(-1)
|
@@ -1629,6 +1712,12 @@ const knowledgeModule = async ({
|
|
1629
1712
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1630
1713
|
hasError = true
|
1631
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
|
+
}
|
1632
1721
|
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1633
1722
|
hasError = true
|
1634
1723
|
}
|
@@ -1641,6 +1730,22 @@ const knowledgeModule = async ({
|
|
1641
1730
|
console.log('**************************** ERRORS ************************')
|
1642
1731
|
for (const result of results) {
|
1643
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
|
+
/*
|
1644
1749
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1645
1750
|
if (!headerShown) {
|
1646
1751
|
console.log(' Failure')
|
@@ -1659,6 +1764,7 @@ const knowledgeModule = async ({
|
|
1659
1764
|
newError = true
|
1660
1765
|
headerShown = true
|
1661
1766
|
}
|
1767
|
+
*/
|
1662
1768
|
if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
|
1663
1769
|
if (!headerShown) {
|
1664
1770
|
console.log(' Failure')
|
@@ -1720,7 +1826,7 @@ const knowledgeModule = async ({
|
|
1720
1826
|
console.log(results.responses.join(' '))
|
1721
1827
|
})
|
1722
1828
|
if (!('then' in promise)) {
|
1723
|
-
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')
|
1724
1830
|
}
|
1725
1831
|
promise
|
1726
1832
|
.then(() => {
|
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
@@ -54,6 +54,14 @@ const handleBridgeProps = (config, bridge) => {
|
|
54
54
|
config.addPriorities([after, [bridge.id, bridge.level]])
|
55
55
|
}
|
56
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
|
+
}
|
57
65
|
if (bridge.words) {
|
58
66
|
for (let def of bridge.words) {
|
59
67
|
if (typeof def == 'string') {
|
@@ -80,15 +88,30 @@ const handleBridgeProps = (config, bridge) => {
|
|
80
88
|
bridge.generatorr = bridge.generatorpr
|
81
89
|
}
|
82
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
|
83
94
|
config.config.generators.unshift({
|
84
95
|
where: bridge.generatorp.where || bridge.where || client.where(4),
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
applyWrapped: bridge.generatorp,
|
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,
|
89
99
|
property: 'generatorp',
|
90
100
|
})
|
91
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
|
+
/*
|
92
115
|
if (bridge.generatorr) {
|
93
116
|
config.config.generators.unshift({
|
94
117
|
// TODO merge response and isResponse
|
@@ -99,6 +122,7 @@ const handleBridgeProps = (config, bridge) => {
|
|
99
122
|
property: 'generatorr',
|
100
123
|
})
|
101
124
|
}
|
125
|
+
*/
|
102
126
|
if (bridge.evaluator) {
|
103
127
|
config.config.semantics.unshift({
|
104
128
|
where: bridge.evaluator.where || bridge.where || client.where(3),
|
@@ -123,7 +147,7 @@ const handleBridgeProps = (config, bridge) => {
|
|
123
147
|
|
124
148
|
const handleCalculatedProps = (baseConfig, moreConfig) => {
|
125
149
|
for (let bridge of moreConfig.bridges) {
|
126
|
-
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',
|
127
151
|
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where' ]
|
128
152
|
helpers.validProps(valid, bridge, 'bridge')
|
129
153
|
handleBridgeProps(baseConfig, bridge)
|
@@ -157,7 +181,7 @@ if (runtime.process.env.DEBUG_BRIDGE) {
|
|
157
181
|
if (global.entodictonDebugBridge.length !== 2) {
|
158
182
|
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
|
159
183
|
}
|
160
|
-
global.entodictonDebugBridge[1] =
|
184
|
+
global.entodictonDebugBridge[1] = parseInt(global.entodictonDebugBridge[1])
|
161
185
|
}
|
162
186
|
|
163
187
|
if (runtime.process.env.DEBUG_OPERATOR) {
|
@@ -175,7 +199,7 @@ const hierarchyCanonical = (element) => {
|
|
175
199
|
|
176
200
|
const isValidDef = (word, def, config) => {
|
177
201
|
if (!def.id) {
|
178
|
-
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)}`)
|
179
203
|
}
|
180
204
|
/*
|
181
205
|
if (!def.initial) {
|
@@ -738,7 +762,7 @@ class Config {
|
|
738
762
|
"semantics",
|
739
763
|
"associations",
|
740
764
|
]
|
741
|
-
return !properties.find( (property) => instance[property].length > 0 )
|
765
|
+
return !properties.find( (property) => instance[property] && instance[property].length > 0 )
|
742
766
|
}
|
743
767
|
if (!isEmpty(instance)) {
|
744
768
|
instance.name = this.name
|
@@ -813,10 +837,10 @@ class Config {
|
|
813
837
|
addHierarchyProperties (edge) {
|
814
838
|
const { child, parent } = edge
|
815
839
|
if (typeof child !== 'string') {
|
816
|
-
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)}`)
|
817
841
|
}
|
818
842
|
if (typeof parent !== 'string') {
|
819
|
-
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)}`)
|
820
844
|
}
|
821
845
|
if (global.entodictonDebugHierarchy) {
|
822
846
|
if (helpers.safeEquals(entodictonDebugHierarchy, [child, parent])) {
|
@@ -830,10 +854,10 @@ class Config {
|
|
830
854
|
|
831
855
|
addHierarchyChildParent (child, parent) {
|
832
856
|
if (typeof child !== 'string') {
|
833
|
-
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)}`)
|
834
858
|
}
|
835
859
|
if (typeof parent !== 'string') {
|
836
|
-
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)}`)
|
837
861
|
}
|
838
862
|
|
839
863
|
if (global.entodictonDebugHierarchy) {
|
@@ -894,10 +918,10 @@ class Config {
|
|
894
918
|
}
|
895
919
|
|
896
920
|
if (!(typeof generator.match === 'function')) {
|
897
|
-
throw 'addGenerator: Expected matcher to be a function'
|
921
|
+
throw new Error('addGenerator: Expected matcher to be a function')
|
898
922
|
}
|
899
923
|
if (!(typeof generator.apply === 'function')) {
|
900
|
-
throw 'addGenerator: Expected action to be a function'
|
924
|
+
throw new Error('addGenerator: Expected action to be a function')
|
901
925
|
}
|
902
926
|
|
903
927
|
if (!this.config.generators) {
|
@@ -921,10 +945,10 @@ class Config {
|
|
921
945
|
}
|
922
946
|
|
923
947
|
if (!(typeof semantic.match === 'function')) {
|
924
|
-
throw 'addSemantic: Expected match to be a function'
|
948
|
+
throw new Error('addSemantic: Expected match to be a function')
|
925
949
|
}
|
926
950
|
if (!(typeof semantic.apply === 'function')) {
|
927
|
-
throw 'addSemantic: Expected apply to be a function'
|
951
|
+
throw new Error('addSemantic: Expected apply to be a function')
|
928
952
|
}
|
929
953
|
|
930
954
|
if (!this.config.semantics) {
|
@@ -1198,7 +1222,7 @@ class Config {
|
|
1198
1222
|
// configs = [ { config, namespace } ... ]
|
1199
1223
|
constructor (config, module) {
|
1200
1224
|
if (config instanceof Config) {
|
1201
|
-
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')
|
1202
1226
|
}
|
1203
1227
|
|
1204
1228
|
if (config) {
|
@@ -1279,7 +1303,7 @@ class Config {
|
|
1279
1303
|
}
|
1280
1304
|
duplicated = Array.from(duplicated)
|
1281
1305
|
if (duplicated.length > 0) {
|
1282
|
-
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}`)
|
1283
1307
|
}
|
1284
1308
|
}
|
1285
1309
|
|
@@ -1394,13 +1418,13 @@ class Config {
|
|
1394
1418
|
if (this._api && this._api.multiApi) {
|
1395
1419
|
this._api.add(this, this._api, api)
|
1396
1420
|
} else {
|
1397
|
-
throw "Can only add apis to a multi-api"
|
1421
|
+
throw new Error("Can only add apis to a multi-api")
|
1398
1422
|
}
|
1399
1423
|
}
|
1400
1424
|
|
1401
1425
|
set api (value) {
|
1402
1426
|
if (!value.initialize) {
|
1403
|
-
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}.`)
|
1404
1428
|
}
|
1405
1429
|
|
1406
1430
|
if (this._api && this._api.multiApi) {
|
@@ -1467,7 +1491,7 @@ class Config {
|
|
1467
1491
|
}
|
1468
1492
|
|
1469
1493
|
doMotivations (args, context) {
|
1470
|
-
args = Object.assign({}, args, { context })
|
1494
|
+
args = Object.assign({}, args, { context, api: this.api })
|
1471
1495
|
// console.log('src/config doMotivations this.uuid', this.uuid)
|
1472
1496
|
// args.objects = args.getObjects(this.uuid)
|
1473
1497
|
const motivations = this.motivations
|
@@ -1702,7 +1726,7 @@ class Config {
|
|
1702
1726
|
for (let option of Object.keys(options)) {
|
1703
1727
|
const validOptions = ['initAfterApi']
|
1704
1728
|
if (!['initAfterApi'].includes(option)) {
|
1705
|
-
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}`)
|
1706
1730
|
}
|
1707
1731
|
}
|
1708
1732
|
}
|
@@ -1939,7 +1963,20 @@ class Config {
|
|
1939
1963
|
// TODO change name of config: to baseConfig:
|
1940
1964
|
const kmFn = (name) => this.getConfig(name)
|
1941
1965
|
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
1942
|
-
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
|
+
}
|
1943
1980
|
config.initializerFn(args)
|
1944
1981
|
if (config.initAfterApi) {
|
1945
1982
|
// reverse the list
|
@@ -2327,14 +2364,14 @@ class Config {
|
|
2327
2364
|
|
2328
2365
|
set (property, value) {
|
2329
2366
|
if (!this.config.hasOwnProperty(property)) {
|
2330
|
-
throw `Setting invalid property ${property}`
|
2367
|
+
throw new Error(`Setting invalid property ${property}`)
|
2331
2368
|
}
|
2332
2369
|
|
2333
2370
|
if ('words' == property) {
|
2334
2371
|
for (let word in value) {
|
2335
2372
|
for (let def of value[word]) {
|
2336
2373
|
if (!def['uuid']) {
|
2337
|
-
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}'`)
|
2338
2375
|
}
|
2339
2376
|
}
|
2340
2377
|
}
|
@@ -2343,7 +2380,7 @@ class Config {
|
|
2343
2380
|
if (['operators', 'bridges'].includes(property)) {
|
2344
2381
|
for (let def of value) {
|
2345
2382
|
if (!def['uuid']) {
|
2346
|
-
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)}`)
|
2347
2384
|
}
|
2348
2385
|
}
|
2349
2386
|
}
|
@@ -2375,7 +2412,7 @@ class Config {
|
|
2375
2412
|
|
2376
2413
|
add (more) {
|
2377
2414
|
if (more === this) {
|
2378
|
-
throw 'Cannot add an object to itself.'
|
2415
|
+
throw new Error('Cannot add an object to itself.')
|
2379
2416
|
}
|
2380
2417
|
if (!(more instanceof Config)) {
|
2381
2418
|
more = new Config(more)
|
@@ -2543,7 +2580,7 @@ class Config {
|
|
2543
2580
|
this.config[key] = this.config[key].concat(more[key])
|
2544
2581
|
} else {
|
2545
2582
|
if (!(key in this.config)) {
|
2546
|
-
throw `Unexpected property in config ${key}`
|
2583
|
+
throw new Error(`Unexpected property in config ${key}`)
|
2547
2584
|
}
|
2548
2585
|
this.config[key] = more[key]
|
2549
2586
|
}
|
@@ -2661,7 +2698,7 @@ class Config {
|
|
2661
2698
|
this.config[key] = more[key].concat(this.config[key])
|
2662
2699
|
} else {
|
2663
2700
|
if (!(key in this.config)) {
|
2664
|
-
throw `Unexpected property in config ${key}`
|
2701
|
+
throw new Error(`Unexpected property in config ${key}`)
|
2665
2702
|
}
|
2666
2703
|
this.config[key] = more[key]
|
2667
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
|
}
|
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
|