entodicton 9.7.1 → 9.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +72 -54
- package/index.js +6 -2
- package/package.json +1 -1
- package/src/config.js +33 -3
- package/src/configHelpers.js +31 -13
- package/src/debug.js +17 -2
- package/src/digraph.js +18 -16
- package/src/digraph_internal.js +20 -12
- package/src/flatten.js +15 -19
- package/src/fragments.js +28 -2
- package/src/generators.js +36 -16
- package/src/helpers.js +126 -22
- package/src/project2.js +4 -0
- package/src/semantics.js +38 -24
package/client.js
CHANGED
|
@@ -12,7 +12,7 @@ const _ = require('lodash')
|
|
|
12
12
|
const stringify = require('json-stable-stringify')
|
|
13
13
|
const Lines = require('./lines')
|
|
14
14
|
const flattens = require('./src/flatten')
|
|
15
|
-
const { sortJson, appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
|
|
15
|
+
const { helpDebugHierarchy, sortJson, appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps, OverrideCheck, removeProp, } = require('./src/helpers')
|
|
16
16
|
const runtime = require('./runtime')
|
|
17
17
|
const db = require('./src/debug')
|
|
18
18
|
|
|
@@ -59,20 +59,11 @@ const pickObjects = (config, testConfig, getObjects) => {
|
|
|
59
59
|
throw new Error(`In the checks for ${config.name} the KM ${km} does not exist`)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} else {
|
|
66
|
-
projection[km] = project(objects, checks[km])
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const lastIndex = contextChecks.length - 1
|
|
70
|
-
const last = contextChecks[lastIndex]
|
|
71
|
-
contextChecks[lastIndex] = { match: last.match, apply: () => [...new Set([...(checks[km] || []), ...last.apply()])] }
|
|
62
|
+
const lastIndex = contextChecks.length - 1
|
|
63
|
+
const last = contextChecks[lastIndex]
|
|
64
|
+
contextChecks[lastIndex] = { match: last.match, apply: () => [...new Set([...(checks[km] || []), ...last.apply()])] }
|
|
72
65
|
|
|
73
|
-
|
|
74
|
-
projection[km] = project2(objects, contextChecks)
|
|
75
|
-
}
|
|
66
|
+
projection[km] = project2(objects, contextChecks)
|
|
76
67
|
}
|
|
77
68
|
return projection
|
|
78
69
|
}
|
|
@@ -167,10 +158,12 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
167
158
|
if (runtime.fs.existsSync(fn)) {
|
|
168
159
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
|
169
160
|
}
|
|
161
|
+
/*
|
|
170
162
|
for (const association of associations) {
|
|
171
163
|
association.sort()
|
|
172
164
|
}
|
|
173
165
|
associations.sort()
|
|
166
|
+
*/
|
|
174
167
|
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
|
175
168
|
const results = sortJson({
|
|
176
169
|
query,
|
|
@@ -265,7 +258,7 @@ const throwErrorHandler = (error) => {
|
|
|
265
258
|
throw error
|
|
266
259
|
}
|
|
267
260
|
|
|
268
|
-
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
261
|
+
const _process = async (config, query, { queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
269
262
|
if (credentials) {
|
|
270
263
|
config.server(credentials.server, credentials.key)
|
|
271
264
|
}
|
|
@@ -296,11 +289,12 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
296
289
|
// '\\n' from tests of '\n' from users. the former is because newline is not a valid json character so the testfile has it encoded
|
|
297
290
|
let queries = query.split(/\\n|\n/)
|
|
298
291
|
const summaries = [] // for error
|
|
292
|
+
logs = logs || []
|
|
299
293
|
try {
|
|
300
294
|
const response = {
|
|
301
295
|
hierarchy: [],
|
|
302
296
|
load_cache_time: 0.0,
|
|
303
|
-
logs:
|
|
297
|
+
logs: logs,
|
|
304
298
|
metadata: {
|
|
305
299
|
opChoices: []
|
|
306
300
|
},
|
|
@@ -334,6 +328,9 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
334
328
|
data.utterance = queries[0]
|
|
335
329
|
data.start_counter = startCounter
|
|
336
330
|
let json = await doWithRetries(retries, url, queryParams, data)
|
|
331
|
+
if (json.logs) {
|
|
332
|
+
logs.push(...json.logs)
|
|
333
|
+
}
|
|
337
334
|
let resetData = false
|
|
338
335
|
if (json.code === 'NOT_IN_CACHE') {
|
|
339
336
|
resetData = true
|
|
@@ -367,28 +364,27 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
367
364
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
|
368
365
|
summaries.push(summary)
|
|
369
366
|
const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
|
370
|
-
await processContextsB({ contextIdCounter, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
367
|
+
await processContextsB({ contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
371
368
|
contextIdCounter = updatedContextIdCounter
|
|
372
369
|
if (isTest) {
|
|
373
370
|
const end = runtime.performance.performance.now()
|
|
374
371
|
clientSideTime = end - start
|
|
375
372
|
}
|
|
376
|
-
response.associations = json.associations
|
|
373
|
+
// response.associations = json.associations
|
|
377
374
|
response.learned_contextual_priorities = json.learned_contextual_priorities
|
|
378
375
|
response.hierarchy = json.hierarchy
|
|
379
376
|
response.load_cache_time += json.load_cache_time
|
|
380
|
-
appendNoDups(response.logs, json.logs)
|
|
381
377
|
response.memory_free_percent = json.memory_free_percent
|
|
382
|
-
// appendNoDups(response.metadata.associations, json.metadata.associations)
|
|
383
|
-
// appendNoDups(response.metadata.priorities, json.metadata.priorities)
|
|
384
378
|
appendNoDups(response.metadata.opChoices, json.metadata.opChoices)
|
|
385
379
|
response.times += json.times
|
|
386
380
|
response.clientSideTimes += clientSideTime
|
|
387
381
|
response.trace = response.trace.concat(json.trace)
|
|
388
382
|
response.version = json.version
|
|
389
383
|
response.explain_priorities = json.explain_priorities
|
|
384
|
+
response.explain_associations_details = (response.explain_associations_details || []).concat(json.explain_associations_details)
|
|
385
|
+
response.explain_associations_trie = json.explain_associations_trie
|
|
390
386
|
response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
|
|
391
|
-
response.rtf_associations = json.rtf_associations
|
|
387
|
+
// response.rtf_associations = json.rtf_associations
|
|
392
388
|
|
|
393
389
|
response.contexts = response.contexts.concat(contextsPrime)
|
|
394
390
|
response.generated = response.generated.concat(generatedPrime)
|
|
@@ -414,6 +410,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
414
410
|
return response
|
|
415
411
|
} catch (error) {
|
|
416
412
|
error.summaries = summaries
|
|
413
|
+
error.queryNumber = queryNumber
|
|
417
414
|
error.query = query
|
|
418
415
|
errorHandler(error)
|
|
419
416
|
}
|
|
@@ -479,7 +476,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
|
479
476
|
return configForTest
|
|
480
477
|
}
|
|
481
478
|
|
|
482
|
-
const runTest = async (config, expected, { args, verbose, testConfig, debug, timings = { server: 0, client: 0 } }) => {
|
|
479
|
+
const runTest = async (config, expected, { args, verbose, testConfig, debug, timings = { server: 0, client: 0 }, index = 0 }) => {
|
|
483
480
|
const test = expected.query
|
|
484
481
|
if (args.query && args.query != test) {
|
|
485
482
|
// no run this
|
|
@@ -506,16 +503,17 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
|
506
503
|
setupArgs(args, config)
|
|
507
504
|
await testConfig.initializer(args)
|
|
508
505
|
}
|
|
509
|
-
const result = await _process(config, test, { errorHandler, isTest: true, isProcess: true, isModule: false })
|
|
506
|
+
const result = await _process(config, test, { queryNumber: args.queryNumber, errorHandler, isTest: true, isProcess: true, isModule: false })
|
|
510
507
|
result.query = test
|
|
511
508
|
if (debug) {
|
|
512
509
|
defaultInnerProcess(config, errorHandler, result)
|
|
513
510
|
}
|
|
514
511
|
if (verbose) {
|
|
515
|
-
const widths = [100, 60]
|
|
512
|
+
const widths = [4, 100, 60]
|
|
516
513
|
const lines = new Lines(widths)
|
|
517
|
-
lines.setElement(0, 0,
|
|
518
|
-
lines.setElement(0, 1,
|
|
514
|
+
lines.setElement(0, 0, index)
|
|
515
|
+
lines.setElement(0, 1, test)
|
|
516
|
+
lines.setElement(0, 2, `time on server: ${result.times.toFixed(2)} client: ${(result.clientSideTimes / 1000).toFixed(2)}`)
|
|
519
517
|
timings.server += result.times
|
|
520
518
|
timings.client += result.clientSideTimes / 1000
|
|
521
519
|
lines.log()
|
|
@@ -618,18 +616,23 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
|
618
616
|
|
|
619
617
|
const runTestsHelper = async (config, tests, failed, juicyBits) => {
|
|
620
618
|
const { stopAtFirstError } = juicyBits
|
|
619
|
+
let index = 0
|
|
621
620
|
while (true) {
|
|
622
621
|
if (tests.length === 0) {
|
|
623
622
|
return Promise.resolve(failed)
|
|
624
623
|
}
|
|
625
624
|
const test = tests.shift()
|
|
625
|
+
juicyBits.index = index
|
|
626
|
+
juicyBits.args.queryNumber = index
|
|
626
627
|
const result = await runTest(config, test, juicyBits)
|
|
627
628
|
if (result != null) {
|
|
629
|
+
result.index = index
|
|
628
630
|
failed.push(result)
|
|
629
631
|
if (stopAtFirstError) {
|
|
630
632
|
return failed
|
|
631
633
|
}
|
|
632
634
|
}
|
|
635
|
+
index += 1
|
|
633
636
|
}
|
|
634
637
|
}
|
|
635
638
|
|
|
@@ -678,13 +681,6 @@ const saveTests = (config, testFile, testConfig) => {
|
|
|
678
681
|
return saveTestsHelper(testFile, config, tests, tests.map((test) => test.query), testConfig)
|
|
679
682
|
}
|
|
680
683
|
|
|
681
|
-
/*
|
|
682
|
-
const showExamples = (testFile) => {
|
|
683
|
-
const tests = JSON.parse(fs.readFileSync(testFile))
|
|
684
|
-
Object.keys(tests).forEach((test) => console.log(test))
|
|
685
|
-
}
|
|
686
|
-
*/
|
|
687
|
-
|
|
688
684
|
const showInfo = (description, section, config) => {
|
|
689
685
|
console.log(JSON.stringify(config.getInfo(), null, 2))
|
|
690
686
|
}
|
|
@@ -798,7 +794,7 @@ const defaultErrorHandler = async (error) => {
|
|
|
798
794
|
}
|
|
799
795
|
|
|
800
796
|
if (error.query) {
|
|
801
|
-
console.log(
|
|
797
|
+
console.log(`query: #${error.queryNumber} ${error.query}`)
|
|
802
798
|
doErrorExit = true
|
|
803
799
|
}
|
|
804
800
|
|
|
@@ -890,6 +886,14 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
|
890
886
|
console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
|
|
891
887
|
}
|
|
892
888
|
}
|
|
889
|
+
|
|
890
|
+
if (responses.explain_associations_details) {
|
|
891
|
+
console.log(responses.explain_associations_trie)
|
|
892
|
+
for (const l of responses.explain_associations_details) {
|
|
893
|
+
console.log(l)
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
893
897
|
// const objects = config.get('objects').namespaced[config.uuid]
|
|
894
898
|
const actualGetObjects = (name) => {
|
|
895
899
|
if (!name) {
|
|
@@ -1066,7 +1070,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1066
1070
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
|
1067
1071
|
}
|
|
1068
1072
|
accumulators.summaries = accumulators.summaries.concat(results.summaries)
|
|
1069
|
-
accumulators.associations = accumulators.associations.concat(results.associations)
|
|
1073
|
+
// accumulators.associations = accumulators.associations.concat(results.associations)
|
|
1070
1074
|
accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
|
|
1071
1075
|
await looper(configs)
|
|
1072
1076
|
} catch (e) {
|
|
@@ -1102,7 +1106,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1102
1106
|
await looper([])
|
|
1103
1107
|
} else {
|
|
1104
1108
|
try {
|
|
1105
|
-
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true })
|
|
1109
|
+
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true, addFirst: true })
|
|
1106
1110
|
} catch (e) {
|
|
1107
1111
|
const where = extraConfig.where ? ` ${extraConfig.where}` : ''
|
|
1108
1112
|
throw new Error(`Error processing extra config${where}: ${e.stack}}`)
|
|
@@ -1124,8 +1128,9 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1124
1128
|
associations.sort()
|
|
1125
1129
|
}
|
|
1126
1130
|
const stabilizeOutput = (template) => {
|
|
1127
|
-
stabilizeAssociations(template.associations)
|
|
1131
|
+
// stabilizeAssociations(template.associations)
|
|
1128
1132
|
const stabilize = (results) => {
|
|
1133
|
+
removeProp(results, (_, k) => k === "context_id")
|
|
1129
1134
|
for (let i = 0; i < results.length; ++i) {
|
|
1130
1135
|
const result = results[i]
|
|
1131
1136
|
if (result.apply) {
|
|
@@ -1138,8 +1143,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1138
1143
|
delete result.memory_free_percent
|
|
1139
1144
|
delete result.logs
|
|
1140
1145
|
delete result.version
|
|
1141
|
-
result.
|
|
1142
|
-
stabilizeAssociations(result.associations)
|
|
1146
|
+
// stabilizeAssociations(result.associations)
|
|
1143
1147
|
result.learned_contextual_priorities = safeNoDups(result.learned_contextual_priorities)
|
|
1144
1148
|
}
|
|
1145
1149
|
}
|
|
@@ -1314,7 +1318,6 @@ const knowledgeModuleImpl = async ({
|
|
|
1314
1318
|
|
|
1315
1319
|
const helpDebugWord = 'In order to get a debug break when a specific word is created set the DEBUG_WORD environment variable to the JSON of the association to break on. For example DEBUG_WORD=\'"the"\''
|
|
1316
1320
|
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], ["mammal", 1]]\''
|
|
1317
|
-
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]]\''
|
|
1318
1321
|
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]]\''
|
|
1319
1322
|
const helpDebugContextualPriority = 'In order to get a debug break when a specific set of contextual priorities is created set set DEBUG_CONTEXTUAL_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_CONTEXTUAL_PRIORITY=\'{ context: [["verb", 0], ["article", 0], select: 1}\''
|
|
1320
1323
|
const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id to break on. For example DEBUG_BRIDGE=\'car\''
|
|
@@ -1337,6 +1340,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1337
1340
|
parser.add_argument('-cl', '--checkForLoop', { nargs: '?', help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
|
|
1338
1341
|
parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
|
|
1339
1342
|
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
|
1343
|
+
parser.add_argument('-qn', '--queryNumber', { help: 'Run the query specified by the given index' })
|
|
1340
1344
|
parser.add_argument('-f', '--filter', { help: 'for -pd only the data for the knowledge modules that start with this string will be shown' })
|
|
1341
1345
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
|
1342
1346
|
parser.add_argument('--trace', { action: 'store_true', help: 'Trace the semantics and generator calls.' })
|
|
@@ -1376,6 +1380,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1376
1380
|
parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
|
|
1377
1381
|
parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
|
|
1378
1382
|
parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
|
|
1383
|
+
parser.add_argument('-ea', '--explainAssociations', { action: 'store_true', help: 'The server will return information about the associations used to decide on the interpretation.' })
|
|
1379
1384
|
parser.add_argument('-ep', '--explainPriorities', { action: 'store_true', help: 'The server will return all priorities including the generated one along with an explanation of there they came from' })
|
|
1380
1385
|
parser.add_argument('-dic', '--debugIncludeConvolutions', { nargs: '?', help: 'When running with the --debugIncludeConvolutions flag the logs will include convolutions which are somewhat annoyingly verbose. Default is false' })
|
|
1381
1386
|
parser.add_argument('-bc', '--bypassCache', { action: 'store_true', help: 'Bypass the cache on the server side and rebuild' })
|
|
@@ -1383,6 +1388,10 @@ const knowledgeModuleImpl = async ({
|
|
|
1383
1388
|
const args = parser.parse_args()
|
|
1384
1389
|
args.count = args.count || 1
|
|
1385
1390
|
|
|
1391
|
+
if (args.queryNumber) {
|
|
1392
|
+
args.query = test.contents[args.queryNumber].query
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1386
1395
|
if (args.rebuildTemplateFull) {
|
|
1387
1396
|
args.rebuildTemplate = true
|
|
1388
1397
|
}
|
|
@@ -1476,9 +1485,10 @@ const knowledgeModuleImpl = async ({
|
|
|
1476
1485
|
|
|
1477
1486
|
if (args.deleteTest) {
|
|
1478
1487
|
let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
|
1488
|
+
const nTests = tests.length
|
|
1479
1489
|
tests = tests.filter((test) => test.query !== args.deleteTest)
|
|
1480
1490
|
writeTestFile(testConfig.name, tests)
|
|
1481
|
-
console.log(`
|
|
1491
|
+
console.log(`Deleted ${nTests - tests.length} tests for "${args.deleteTest}"`)
|
|
1482
1492
|
return
|
|
1483
1493
|
}
|
|
1484
1494
|
|
|
@@ -1509,6 +1519,10 @@ const knowledgeModuleImpl = async ({
|
|
|
1509
1519
|
config.config.explain_priorities = true
|
|
1510
1520
|
}
|
|
1511
1521
|
|
|
1522
|
+
if (args.explainAssociations) {
|
|
1523
|
+
config.config.explain_associations = true
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1512
1526
|
config.config.debugIncludeConvolutions = args.debugIncludeConvolutions || process.argv.includes('--debugIncludeConvolutions') || process.argv.includes('-dic')
|
|
1513
1527
|
|
|
1514
1528
|
let configPrinted = false
|
|
@@ -1528,7 +1542,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1528
1542
|
console.log('Test queries')
|
|
1529
1543
|
let counter = 0
|
|
1530
1544
|
for (const test of config.tests) {
|
|
1531
|
-
console.log(
|
|
1545
|
+
console.log(`#${counter} - ${test.query}`)
|
|
1532
1546
|
counter += 1
|
|
1533
1547
|
}
|
|
1534
1548
|
}
|
|
@@ -1541,7 +1555,10 @@ const knowledgeModuleImpl = async ({
|
|
|
1541
1555
|
if (hasArg('c')) {
|
|
1542
1556
|
const { data } = setupProcessB({ config })
|
|
1543
1557
|
console.log('Config as sent to server')
|
|
1544
|
-
|
|
1558
|
+
const toPrint = { ...data }
|
|
1559
|
+
toPrint['priorities'] = toPrint['priorities'].map((value) => JSON.stringify(value).replace(/\\"/g, '"'))
|
|
1560
|
+
toPrint['associations']['positive'] = toPrint['associations']['positive'].map((value) => JSON.stringify(value).replace(/\\"/g, '"'))
|
|
1561
|
+
console.log(JSON.stringify(toPrint, null, 2).replace(/\\"/g, '"'))
|
|
1545
1562
|
}
|
|
1546
1563
|
if (hasArg('l')) {
|
|
1547
1564
|
console.log('Module load ordering')
|
|
@@ -1635,12 +1652,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1635
1652
|
}
|
|
1636
1653
|
|
|
1637
1654
|
if (hasArg('s')) {
|
|
1638
|
-
|
|
1639
|
-
for (const semantic of easyToRead) {
|
|
1640
|
-
semantic.match = semantic.match.toString()
|
|
1641
|
-
semantic.apply = semantic.apply.toString()
|
|
1642
|
-
}
|
|
1643
|
-
console.dir(easyToRead)
|
|
1655
|
+
config.printSemantics()
|
|
1644
1656
|
}
|
|
1645
1657
|
}
|
|
1646
1658
|
}
|
|
@@ -1757,7 +1769,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1757
1769
|
if (hasError) {
|
|
1758
1770
|
console.log('**************************** ERRORS ************************')
|
|
1759
1771
|
for (const result of results) {
|
|
1760
|
-
console.log(
|
|
1772
|
+
console.log(`Utterance: #${result.index} ${result.utterance}`)
|
|
1761
1773
|
if (!result.hasError) {
|
|
1762
1774
|
continue
|
|
1763
1775
|
}
|
|
@@ -1773,7 +1785,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1773
1785
|
newError = true
|
|
1774
1786
|
headerShown = true
|
|
1775
1787
|
if (args.vimdiff) {
|
|
1776
|
-
vimdiff(actual, expected, `"${label} - ${result.utterance}"`)
|
|
1788
|
+
vimdiff(actual, expected, `"${label} - #${result.index} ${result.utterance}"`)
|
|
1777
1789
|
}
|
|
1778
1790
|
result.hasError = true
|
|
1779
1791
|
}
|
|
@@ -1916,12 +1928,17 @@ const knowledgeModuleImpl = async ({
|
|
|
1916
1928
|
console.log('use -v arg to write files expected.json and actual.json in the current directory for detailed comparison. Or do -s and then git diff the changes.')
|
|
1917
1929
|
// console.log(JSON.stringify(contexts))
|
|
1918
1930
|
let errorCount = 0
|
|
1931
|
+
const failedTests = []
|
|
1919
1932
|
for (const result of results) {
|
|
1920
1933
|
if (result.hasError) {
|
|
1921
|
-
console.log(`FAILED ${result.utterance}`)
|
|
1934
|
+
console.log(`FAILED #${result.index} ${result.utterance}`)
|
|
1935
|
+
failedTests.push({ index: result.index, utterance: result.utterance })
|
|
1922
1936
|
errorCount += 1
|
|
1923
1937
|
}
|
|
1924
1938
|
}
|
|
1939
|
+
const failedFile = './FAILED.json'
|
|
1940
|
+
console.log(`Failed tests are written to ${failedFile}`)
|
|
1941
|
+
runtime.fs.writeFileSync(failedFile, JSON.stringify(failedTests, 0, 2))
|
|
1925
1942
|
console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
|
|
1926
1943
|
}
|
|
1927
1944
|
}
|
|
@@ -1980,7 +1997,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1980
1997
|
global.beforeObjects = _.cloneDeep(objects)
|
|
1981
1998
|
}
|
|
1982
1999
|
try {
|
|
1983
|
-
await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
|
2000
|
+
await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, logs: [], isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
|
1984
2001
|
} catch (error) {
|
|
1985
2002
|
printConfig()
|
|
1986
2003
|
console.log('Error', error)
|
|
@@ -2104,4 +2121,5 @@ module.exports = {
|
|
|
2104
2121
|
writeTest,
|
|
2105
2122
|
getConfigForTest,
|
|
2106
2123
|
debug: db,
|
|
2124
|
+
OverrideCheck,
|
|
2107
2125
|
}
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Semantics, Semantic } = require('./src/semantics')
|
|
2
2
|
const { Generators, Generator } = require('./src/generators')
|
|
3
3
|
const { Config } = require('./src/config')
|
|
4
|
-
const { w, where } = require('./src/helpers')
|
|
4
|
+
const { w, where, OverrideCheck, setByPath, getByPath, removeProp } = require('./src/helpers')
|
|
5
5
|
const Digraph = require('./src/digraph')
|
|
6
6
|
const client = require('./client')
|
|
7
7
|
const flattens = require('./src/flatten')
|
|
@@ -16,6 +16,8 @@ module.exports = {
|
|
|
16
16
|
runTests: client.runTests,
|
|
17
17
|
knowledgeModule: client.knowledgeModule,
|
|
18
18
|
ensureTestFile: client.ensureTestFile,
|
|
19
|
+
setByPath,
|
|
20
|
+
getByPath,
|
|
19
21
|
where,
|
|
20
22
|
stableId: client.stableId,
|
|
21
23
|
w,
|
|
@@ -28,5 +30,7 @@ module.exports = {
|
|
|
28
30
|
flattens: flattens.flattens,
|
|
29
31
|
flatten: flattens.flatten,
|
|
30
32
|
unflatten: unflatten.unflatten,
|
|
31
|
-
debug
|
|
33
|
+
debug,
|
|
34
|
+
OverrideCheck,
|
|
35
|
+
removeProp,
|
|
32
36
|
}
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -454,7 +454,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
454
454
|
// match: async (args) => bridge.id === args.context.marker && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
|
|
455
455
|
match: async (args) => {
|
|
456
456
|
if (bridge.callId == args.callId) {
|
|
457
|
-
debugger
|
|
457
|
+
debugger // eslint-disable-line no-debugger
|
|
458
458
|
}
|
|
459
459
|
return args.isA(args.context.marker, bridge.id) && args.context.level === level && !args.context.paraphrase && (args.context.response != null || args.context.isResponse) && await match(args)
|
|
460
460
|
},
|
|
@@ -563,7 +563,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
563
563
|
'generatorr',
|
|
564
564
|
'generators',
|
|
565
565
|
'id',
|
|
566
|
-
'
|
|
566
|
+
'initial',
|
|
567
567
|
'inverted',
|
|
568
568
|
'isA',
|
|
569
569
|
'level',
|
|
@@ -572,6 +572,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
572
572
|
'operator',
|
|
573
573
|
'optional',
|
|
574
574
|
'parents',
|
|
575
|
+
'preferOver',
|
|
575
576
|
'return_type_selector',
|
|
576
577
|
'scope',
|
|
577
578
|
'selector',
|
|
@@ -601,7 +602,12 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
601
602
|
}
|
|
602
603
|
|
|
603
604
|
if (runtime.process.env.DEBUG_HIERARCHY) {
|
|
604
|
-
|
|
605
|
+
try {
|
|
606
|
+
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
|
607
|
+
} catch( e ) {
|
|
608
|
+
console.error("Invalid valid for DEBUG_HIERARCHY")
|
|
609
|
+
console.error(helpers.helpDebugHierarchy)
|
|
610
|
+
}
|
|
605
611
|
}
|
|
606
612
|
|
|
607
613
|
// i keep randomly doing one of the other so I will just make both work the same way
|
|
@@ -975,6 +981,15 @@ class Config {
|
|
|
975
981
|
return config_toServer(config)
|
|
976
982
|
}
|
|
977
983
|
|
|
984
|
+
printSemantics() {
|
|
985
|
+
const easyToRead = _.cloneDeep(this.config.semantics)
|
|
986
|
+
for (const semantic of easyToRead) {
|
|
987
|
+
semantic.match = semantic.match.toString()
|
|
988
|
+
semantic.apply = semantic.apply.toString()
|
|
989
|
+
}
|
|
990
|
+
console.dir(easyToRead)
|
|
991
|
+
}
|
|
992
|
+
|
|
978
993
|
async run(handler) {
|
|
979
994
|
return configHelpers.run(this, handler)
|
|
980
995
|
}
|
|
@@ -1285,6 +1300,8 @@ class Config {
|
|
|
1285
1300
|
} else {
|
|
1286
1301
|
return fi
|
|
1287
1302
|
}
|
|
1303
|
+
} else {
|
|
1304
|
+
throw new Error(`The fragment for '${query} was not found.`)
|
|
1288
1305
|
}
|
|
1289
1306
|
}
|
|
1290
1307
|
|
|
@@ -1655,6 +1672,7 @@ class Config {
|
|
|
1655
1672
|
}
|
|
1656
1673
|
}
|
|
1657
1674
|
|
|
1675
|
+
// handler/listener
|
|
1658
1676
|
updateBridge(id, updater) {
|
|
1659
1677
|
const bridge = this.config.bridges.find((b) => b.id === id)
|
|
1660
1678
|
updater({ config: this, bridge })
|
|
@@ -1674,6 +1692,7 @@ class Config {
|
|
|
1674
1692
|
return
|
|
1675
1693
|
}
|
|
1676
1694
|
}
|
|
1695
|
+
|
|
1677
1696
|
if (global.transitoryMode) {
|
|
1678
1697
|
def.transitoryMode = true
|
|
1679
1698
|
}
|
|
@@ -2313,6 +2332,7 @@ class Config {
|
|
|
2313
2332
|
}
|
|
2314
2333
|
}
|
|
2315
2334
|
|
|
2335
|
+
// TODO Api or API -> pick one and do that
|
|
2316
2336
|
async setMultiApi (initializer) {
|
|
2317
2337
|
await this.setApi(() => multiApiImpl(initializer))
|
|
2318
2338
|
}
|
|
@@ -2420,11 +2440,17 @@ class Config {
|
|
|
2420
2440
|
if (!api.initialize) {
|
|
2421
2441
|
throw new Error(`Expected the API for ${this.name} to have an initialize function.`)
|
|
2422
2442
|
}
|
|
2443
|
+
if (api.baseAPI) {
|
|
2444
|
+
new helpers.OverrideCheck(api.baseAPI).check(api)
|
|
2445
|
+
}
|
|
2423
2446
|
}
|
|
2424
2447
|
} else {
|
|
2425
2448
|
if (!value.initialize) {
|
|
2426
2449
|
throw new Error(`Expected the API to have an initialize function for ${this.name}. If you are trying to pass in multiple API configs at once use setApiKMs to set the names of the configs that you want set.`)
|
|
2427
2450
|
}
|
|
2451
|
+
if (value.baseAPI) {
|
|
2452
|
+
new helpers.OverrideCheck(value.baseAPI).check(value)
|
|
2453
|
+
}
|
|
2428
2454
|
}
|
|
2429
2455
|
|
|
2430
2456
|
if (this._api && this._api.multiApi) {
|
|
@@ -3368,6 +3394,10 @@ class Config {
|
|
|
3368
3394
|
let duplicated = new Set()
|
|
3369
3395
|
const seen = new Set()
|
|
3370
3396
|
for (const bridge of this.config.bridges) {
|
|
3397
|
+
if (typeof bridge.id !== 'string') {
|
|
3398
|
+
throw new Error('Config.addBridge: expected the bridge id to be a non-empty string.')
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3371
3401
|
const id = `${bridge.id}/${bridge.level} (namespace: ${bridge.uuid || this.uuid})`
|
|
3372
3402
|
if (seen.has(id)) {
|
|
3373
3403
|
duplicated.add(id)
|
package/src/configHelpers.js
CHANGED
|
@@ -145,6 +145,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
145
145
|
args.objects = config.get('objects')
|
|
146
146
|
args.getObjects = getObjects(args.objects)
|
|
147
147
|
}
|
|
148
|
+
args.debug = debug
|
|
148
149
|
args.enable = (key) => {
|
|
149
150
|
config.addEnable(key)
|
|
150
151
|
}
|
|
@@ -163,7 +164,23 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
args.contextHierarchy = new ContextHierarchy()
|
|
166
|
-
args.
|
|
167
|
+
args.namespaced = {
|
|
168
|
+
get: (km, context, property, _default) => {
|
|
169
|
+
context.namespaced ??= {}
|
|
170
|
+
context.namespaced[km] ??= {}
|
|
171
|
+
const value = context.namespaced[km][property]
|
|
172
|
+
if (value == undefined) {
|
|
173
|
+
return _default
|
|
174
|
+
}
|
|
175
|
+
return value
|
|
176
|
+
},
|
|
177
|
+
set: (km, context, property, value) => {
|
|
178
|
+
context.namespaced ??= {}
|
|
179
|
+
context.namespaced[km] ??= {}
|
|
180
|
+
return context.namespaced[km][property] = value
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
args.stack = new HandlerStack()
|
|
167
184
|
args.cleanAssign = cleanAssign
|
|
168
185
|
args.km = (name) => config.getConfig(name)
|
|
169
186
|
args.api = (name) => config.getConfig(name).api
|
|
@@ -332,9 +349,11 @@ const processContext = async (context, { objects = {}, config, logs = [] }) => {
|
|
|
332
349
|
const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemplate = false } = {}) => {
|
|
333
350
|
const key = config._key
|
|
334
351
|
const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
|
|
352
|
+
/*
|
|
335
353
|
if (rebuildingTemplate) {
|
|
336
354
|
data.return_rtf_associations = true
|
|
337
355
|
}
|
|
356
|
+
*/
|
|
338
357
|
if (allowDelta && config.allowDelta && config.hasDelta()) {
|
|
339
358
|
// console.log('config', config)
|
|
340
359
|
data.delta = config.delta()
|
|
@@ -392,7 +411,7 @@ const setupContexts = (rawContexts) => {
|
|
|
392
411
|
return contexts
|
|
393
412
|
}
|
|
394
413
|
|
|
395
|
-
const processContextsB = async ({ config, calls, hierarchy, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
414
|
+
const processContextsB = async ({ config, calls, hierarchy, logs, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
396
415
|
// TODO fix this name to contextsPrime
|
|
397
416
|
const contextsPrime = []
|
|
398
417
|
const generatedPrime = []
|
|
@@ -404,10 +423,7 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
404
423
|
|
|
405
424
|
const objects = config.get('objects')
|
|
406
425
|
const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts, isProcess, isModule, calls }
|
|
407
|
-
|
|
408
|
-
json.logs = []
|
|
409
|
-
}
|
|
410
|
-
setupArgs(args, config, json.logs, hierarchy)
|
|
426
|
+
setupArgs(args, config, logs, hierarchy)
|
|
411
427
|
const toDo = [...contexts]
|
|
412
428
|
args.insert = (context) => toDo.unshift(context)
|
|
413
429
|
let overlap, lastRange
|
|
@@ -425,7 +441,7 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
425
441
|
}
|
|
426
442
|
const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
|
|
427
443
|
if (!config.get('skipSemantics')) {
|
|
428
|
-
const semantics = config.getSemantics(
|
|
444
|
+
const semantics = config.getSemantics(logs)
|
|
429
445
|
try {
|
|
430
446
|
contextPrime = await semantics.apply(args, context)
|
|
431
447
|
// contextPrime.greg = 'yes'
|
|
@@ -468,11 +484,11 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
468
484
|
// noop
|
|
469
485
|
} else {
|
|
470
486
|
let assumed = { isResponse: true }
|
|
471
|
-
const generated = contextPrime.isResponse ? await config.getGenerators(
|
|
487
|
+
const generated = contextPrime.isResponse ? await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
|
472
488
|
let generatedParenthesized = []
|
|
473
489
|
if (generateParenthesized) {
|
|
474
490
|
config.setParenthesized(true)
|
|
475
|
-
generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(
|
|
491
|
+
generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
|
476
492
|
config.setParenthesized(false)
|
|
477
493
|
}
|
|
478
494
|
// assumed = { paraphrase: true, response: false };
|
|
@@ -480,11 +496,11 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
480
496
|
if (generateParenthesized) {
|
|
481
497
|
config.setParenthesized(false)
|
|
482
498
|
}
|
|
483
|
-
const paraphrases = await config.getGenerators(
|
|
499
|
+
const paraphrases = await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed)
|
|
484
500
|
let paraphrasesParenthesized = []
|
|
485
501
|
if (generateParenthesized) {
|
|
486
502
|
config.setParenthesized(true)
|
|
487
|
-
paraphrasesParenthesized = await config.getGenerators(
|
|
503
|
+
paraphrasesParenthesized = await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed)
|
|
488
504
|
config.setParenthesized(false)
|
|
489
505
|
}
|
|
490
506
|
contextsPrime.push(contextPrime)
|
|
@@ -513,9 +529,9 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
513
529
|
}
|
|
514
530
|
e.context = contextPrime
|
|
515
531
|
if (e.logs) {
|
|
516
|
-
e.logs = e.logs.concat(
|
|
532
|
+
e.logs = e.logs.concat(logs)
|
|
517
533
|
} else {
|
|
518
|
-
e.logs =
|
|
534
|
+
e.logs = logs
|
|
519
535
|
}
|
|
520
536
|
e.metadata = json.metadata
|
|
521
537
|
if (json.trace) {
|
|
@@ -532,10 +548,12 @@ const loadInstance = async (config, instance) => {
|
|
|
532
548
|
const transitoryMode = global.transitoryMode
|
|
533
549
|
global.transitoryMode = false
|
|
534
550
|
|
|
551
|
+
/*
|
|
535
552
|
const rl = instance.resultss.length
|
|
536
553
|
if (rl > 0) {
|
|
537
554
|
config.addAssociations(instance.resultss[instance.resultss.length - 1].rtf_associations || [])
|
|
538
555
|
}
|
|
556
|
+
*/
|
|
539
557
|
/*
|
|
540
558
|
TODO needs updating if still wanted
|
|
541
559
|
if (instance && (instance.associations || instance.learned_contextual_priorities)) {
|