theprogrammablemind 8.0.0-beta.9 → 8.0.0-beta.91
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 +565 -949
- package/index.js +3 -2
- package/package.json +2 -1
- package/src/config.js +231 -251
- package/src/configHelpers.js +455 -0
- package/src/generators.js +8 -8
- package/src/helpers.js +34 -1
- package/src/project.js +1 -1
- package/src/semantics.js +63 -69
package/client.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
const { Semantics, Semantic } = require('./src/semantics')
|
2
2
|
const { Generators, Generator } = require('./src/generators')
|
3
|
+
const { Config } = require('./src/config')
|
4
|
+
const { loadInstance, ErrorReason, listable, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB } = require('./src/configHelpers')
|
3
5
|
const DigraphInternal = require('./src/digraph_internal')
|
4
6
|
const Digraph = require('./src/digraph')
|
5
7
|
const { project } = require('./src/project')
|
@@ -10,36 +12,10 @@ const _ = require('lodash')
|
|
10
12
|
const stringify = require('json-stable-stringify')
|
11
13
|
const Lines = require('./lines')
|
12
14
|
const flattens = require('./src/flatten')
|
13
|
-
const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId } = require('./src/helpers')
|
15
|
+
const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where } = require('./src/helpers')
|
14
16
|
const runtime = require('./runtime')
|
15
17
|
const sortJson = runtime.sortJson
|
16
18
|
|
17
|
-
function where (goUp = 2) {
|
18
|
-
const e = new Error()
|
19
|
-
const regexForm1 = /\((.*):(\d+):(\d+)\)$/
|
20
|
-
const regexForm2 = /at (.*):(\d+):(\d+)$/
|
21
|
-
const lines = e.stack.split('\n')
|
22
|
-
let line
|
23
|
-
let match
|
24
|
-
for (line of lines.slice(1)) {
|
25
|
-
// if (!(line.includes('config.js:') || line.includes('client.js:') || line.includes('<anonymous>'))) {
|
26
|
-
if (!(line.includes('config.js:') || line.includes('client.js:'))) {
|
27
|
-
match = regexForm1.exec(line) || regexForm2.exec(line)
|
28
|
-
if (!match) {
|
29
|
-
continue
|
30
|
-
}
|
31
|
-
break
|
32
|
-
}
|
33
|
-
}
|
34
|
-
// const line = e.stack.split("\n")[goUp];
|
35
|
-
// const match = regexForm1.exec(line) || regexForm2.exec(line)
|
36
|
-
if (match) {
|
37
|
-
return `${match[1]}:${match[2]}`
|
38
|
-
} else {
|
39
|
-
return 'running in browser'
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
19
|
const getConfig_getObjectsCheck = (config, testConfig) => {
|
44
20
|
let testConfigName = config.name
|
45
21
|
if (testConfig.testModuleName) {
|
@@ -108,164 +84,6 @@ const vimdiff = (actualJSON, expectedJSON, title) => {
|
|
108
84
|
}
|
109
85
|
}
|
110
86
|
|
111
|
-
const listable = (hierarchy) => (c, type) => {
|
112
|
-
if (!c) {
|
113
|
-
return false
|
114
|
-
}
|
115
|
-
if (hierarchy.isA(c.marker, type)) {
|
116
|
-
return true
|
117
|
-
}
|
118
|
-
if (c.marker === 'list') {
|
119
|
-
for (const t of c.types) {
|
120
|
-
if (hierarchy.isA(t, type)) {
|
121
|
-
return true
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}
|
125
|
-
return false
|
126
|
-
}
|
127
|
-
|
128
|
-
const isA = (hierarchy) => (child, parent) => {
|
129
|
-
if (!child || !parent) {
|
130
|
-
return false
|
131
|
-
}
|
132
|
-
if (child.marker) {
|
133
|
-
child = child.marker
|
134
|
-
}
|
135
|
-
if (parent.marker) {
|
136
|
-
parent = parent.marker
|
137
|
-
}
|
138
|
-
return hierarchy.isA(child, parent)
|
139
|
-
}
|
140
|
-
|
141
|
-
const asList = (context) => {
|
142
|
-
if (context.marker === 'list') {
|
143
|
-
return context
|
144
|
-
}
|
145
|
-
return {
|
146
|
-
marker: 'list',
|
147
|
-
types: [context.marker],
|
148
|
-
value: [context]
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
class ErrorReason extends Error {
|
153
|
-
constructor (context) {
|
154
|
-
super(JSON.stringify(context))
|
155
|
-
this.reason = context
|
156
|
-
}
|
157
|
-
}
|
158
|
-
|
159
|
-
const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
160
|
-
|
161
|
-
// callId
|
162
|
-
args.calls = new InitCalls(args.isInstance ? `${args.isInstance}#${config.name}` : config.name)
|
163
|
-
if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
|
164
|
-
args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
|
165
|
-
}
|
166
|
-
args.km = (name) => config.getConfig(name)
|
167
|
-
args.api = (name) => config.getConfig(name).api
|
168
|
-
args.error = (context) => {
|
169
|
-
throw new ErrorReason(context)
|
170
|
-
}
|
171
|
-
args.kms = config.getConfigs()
|
172
|
-
args.config = config
|
173
|
-
args.hierarchy = hierarchy
|
174
|
-
args.isA = isA(hierarchy)
|
175
|
-
args.listable = listable(hierarchy)
|
176
|
-
args.asList = asList
|
177
|
-
args.retry = () => { throw new RetryError() }
|
178
|
-
args.fragments = (query) => config.fragment(query)
|
179
|
-
args.breakOnSemantics = false
|
180
|
-
args.theDebugger = {
|
181
|
-
breakOnSemantics: (value) => args.breakOnSemantics = value
|
182
|
-
}
|
183
|
-
if (!logs) {
|
184
|
-
}
|
185
|
-
args.log = (message) => logs.push(message)
|
186
|
-
|
187
|
-
args.addAssumedScoped = (args, assumed) => {
|
188
|
-
const addAssumed = (args, ...moreAssumed) => {
|
189
|
-
return { ...args, assumed: Object.assign({}, assumed, (args.assumed || {}), ...moreAssumed) }
|
190
|
-
}
|
191
|
-
|
192
|
-
args.s = (c) => config.getSemantics(logs).apply(args, c)
|
193
|
-
args.g = (c, a = {}) => {
|
194
|
-
return config.getGenerators(logs).apply(addAssumed(args, a), c, a)
|
195
|
-
}
|
196
|
-
args.gp = (c, a = {}) => {
|
197
|
-
return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: true, isResponse: false, response: false }), c, { paraphrase: true, isResponse: false, response: false })
|
198
|
-
}
|
199
|
-
args.gr = (c, a = {}) => {
|
200
|
-
return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true })
|
201
|
-
}
|
202
|
-
args.e = (c) => {
|
203
|
-
return config.getEvaluator(args.s, args.calls, logs, c)
|
204
|
-
}
|
205
|
-
args.gs = gs(args.g)
|
206
|
-
args.gsp = gs(args.gp)
|
207
|
-
args.gsr = gs(args.gr)
|
208
|
-
}
|
209
|
-
// for semantics
|
210
|
-
args.addAssumedScoped(args, {})
|
211
|
-
|
212
|
-
const getAPI = (uuid) => {
|
213
|
-
if (config && config.getAPI) {
|
214
|
-
return config.getAPI(uuid)
|
215
|
-
}
|
216
|
-
}
|
217
|
-
const getAPIs = (uuid) => {
|
218
|
-
if (config && config.getAPIs) {
|
219
|
-
return config.getAPIs(uuid)
|
220
|
-
}
|
221
|
-
}
|
222
|
-
args.getUUIDScoped = (uuid) => {
|
223
|
-
return {
|
224
|
-
api: getAPI(uuid),
|
225
|
-
apis: getAPIs(uuid)
|
226
|
-
}
|
227
|
-
}
|
228
|
-
config.getAddedArgs(args)
|
229
|
-
|
230
|
-
Object.assign(args, args.getUUIDScoped(uuidForScoping || config.uuid))
|
231
|
-
/*
|
232
|
-
if (uuidForScoping) {
|
233
|
-
Object.assign(args, args.getUUIDScoped(uuidForScoping))
|
234
|
-
}
|
235
|
-
*/
|
236
|
-
// sets args for all the API. that make a copy so the args must be fully setup by here except for scoped
|
237
|
-
config.setArgs(args)
|
238
|
-
}
|
239
|
-
|
240
|
-
const gs = (g) => (contexts, separator, lastSeparator) => {
|
241
|
-
if (!Array.isArray(contexts)) {
|
242
|
-
debugger
|
243
|
-
throw new Error('Expected a list')
|
244
|
-
}
|
245
|
-
|
246
|
-
let s = ''
|
247
|
-
if (!separator) {
|
248
|
-
separator = ' '
|
249
|
-
}
|
250
|
-
if (!lastSeparator) {
|
251
|
-
lastSeparator = separator
|
252
|
-
}
|
253
|
-
let nextSeparator = ''
|
254
|
-
for (let i = 0; i < contexts.length; ++i) {
|
255
|
-
const context = contexts[i]
|
256
|
-
const value = g(context)
|
257
|
-
if (i > 0) {
|
258
|
-
if (i === contexts.length - 1) {
|
259
|
-
nextSeparator = lastSeparator
|
260
|
-
} else {
|
261
|
-
nextSeparator = separator
|
262
|
-
}
|
263
|
-
}
|
264
|
-
s += nextSeparator + value
|
265
|
-
}
|
266
|
-
return s
|
267
|
-
}
|
268
|
-
|
269
87
|
const matching = (actual, expected) => {
|
270
88
|
if (!deepEqual(stringify(sortJson(actual, { depth: 25 })), stringify(sortJson(expected, { depth: 25 })))) {
|
271
89
|
return false
|
@@ -290,56 +108,18 @@ const analyzeMetaData = (right, wrong) => {
|
|
290
108
|
return []
|
291
109
|
}
|
292
110
|
|
293
|
-
const processContexts = (contexts, params) => {
|
111
|
+
const processContexts = async (contexts, params) => {
|
294
112
|
const contextsPrime = []
|
295
113
|
const generated = []
|
296
114
|
const logs = []
|
297
115
|
for (const context of contexts) {
|
298
|
-
const result = processContext(context, Object.assign({}, params, { logs }))
|
116
|
+
const result = await processContext(context, Object.assign({}, params, { logs }))
|
299
117
|
contextsPrime.push(result.context)
|
300
118
|
generated.push(result.generated)
|
301
119
|
}
|
302
120
|
return { contexts: contextsPrime, generated, logs }
|
303
121
|
}
|
304
122
|
|
305
|
-
const getObjects = (objects) => {
|
306
|
-
return (uuid) => {
|
307
|
-
if (objects && objects.namespaced) {
|
308
|
-
return objects.namespaced[uuid]
|
309
|
-
}
|
310
|
-
return objects
|
311
|
-
}
|
312
|
-
}
|
313
|
-
|
314
|
-
const processContext = (context, { objects = {}, config, logs = [] }) => {
|
315
|
-
const generators = config.getGenerators(logs)
|
316
|
-
const semantics = config.getSemantics(logs)
|
317
|
-
|
318
|
-
// map to hash
|
319
|
-
config = config || {}
|
320
|
-
if (config.config) {
|
321
|
-
config = config
|
322
|
-
}
|
323
|
-
|
324
|
-
const response = {} // NA but passed in
|
325
|
-
// generators = new Generators(generators.map((g) => new Generator(normalizeGenerator(g))))
|
326
|
-
// semantics = new Semantics(semantics.map((g) => new Semantic(normalizeSemantic(g))))
|
327
|
-
const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
|
328
|
-
|
329
|
-
const args = { objects, response, getObjects: getObjects(objects) }
|
330
|
-
setupArgs(args, config, logs, hierarchy)
|
331
|
-
|
332
|
-
context = semantics.apply(args, context)
|
333
|
-
const generated = generators.apply(args, context)
|
334
|
-
const assumed = { paraphrase: true, response: false, isResponse: false }
|
335
|
-
const paraphrases = generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
|
336
|
-
let responses = []
|
337
|
-
if (context.isResponse) {
|
338
|
-
responses = generated
|
339
|
-
}
|
340
|
-
return { context, generated, paraphrases, responses }
|
341
|
-
}
|
342
|
-
|
343
123
|
const convertToStable = (objects) => {
|
344
124
|
if (true) {
|
345
125
|
return objects
|
@@ -431,139 +211,6 @@ const overlaps = (r1, context) => {
|
|
431
211
|
return false
|
432
212
|
}
|
433
213
|
|
434
|
-
const setupContexts = (rawContexts) => {
|
435
|
-
let first = true
|
436
|
-
const contexts = []
|
437
|
-
contexts.push({ marker: 'controlStart', controlRemove: true })
|
438
|
-
for (const context of rawContexts) {
|
439
|
-
if (first) {
|
440
|
-
first = false
|
441
|
-
} else {
|
442
|
-
contexts.push({ marker: 'controlBetween', controlRemove: true })
|
443
|
-
}
|
444
|
-
contexts.push(context)
|
445
|
-
}
|
446
|
-
contexts.push({ marker: 'controlEnd', controlRemove: true })
|
447
|
-
return contexts
|
448
|
-
}
|
449
|
-
|
450
|
-
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
451
|
-
// TODO fix this name to contextsPrime
|
452
|
-
const contextsPrime = []
|
453
|
-
const generatedPrime = []
|
454
|
-
const paraphrasesPrime = []
|
455
|
-
const paraphrasesParenthesizedPrime = []
|
456
|
-
const generatedParenthesizedPrime = []
|
457
|
-
const responsesPrime = []
|
458
|
-
const contexts = setupContexts(json.contexts)
|
459
|
-
|
460
|
-
const objects = config.get('objects')
|
461
|
-
const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance }
|
462
|
-
if (!json.logs) {
|
463
|
-
json.logs = []
|
464
|
-
}
|
465
|
-
setupArgs(args, config, json.logs, hierarchy)
|
466
|
-
const toDo = [...contexts]
|
467
|
-
args.insert = (context) => toDo.unshift(context)
|
468
|
-
let overlap, lastRange
|
469
|
-
config.debugLoops = commandLineArgs && commandLineArgs.debugLoops
|
470
|
-
while (toDo.length > 0) {
|
471
|
-
const context = toDo.shift()
|
472
|
-
args.calls.next()
|
473
|
-
let contextPrime = context
|
474
|
-
context.topLevel = true
|
475
|
-
try {
|
476
|
-
if (json.has_errors) {
|
477
|
-
throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
|
478
|
-
}
|
479
|
-
const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
|
480
|
-
if (!config.get('skipSemantics')) {
|
481
|
-
const semantics = config.getSemantics(json.logs)
|
482
|
-
try {
|
483
|
-
contextPrime = semantics.apply(args, context)
|
484
|
-
} catch (e) {
|
485
|
-
if (e.message == 'Maximum call stack size exceeded') {
|
486
|
-
const mostCalled = semantics.getMostCalled()
|
487
|
-
e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
|
488
|
-
}
|
489
|
-
// contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
|
490
|
-
if (isInstance) {
|
491
|
-
console.log('error', e.error)
|
492
|
-
}
|
493
|
-
contextPrime = semantics.apply(args, {
|
494
|
-
marker: 'error',
|
495
|
-
context,
|
496
|
-
text: e ? e.toString() : 'not available',
|
497
|
-
reason: e.reason,
|
498
|
-
error: e.stack || e.error
|
499
|
-
})
|
500
|
-
if (rebuildingTemplate) {
|
501
|
-
throw e
|
502
|
-
}
|
503
|
-
}
|
504
|
-
}
|
505
|
-
if (contextPrime.controlRemove) {
|
506
|
-
continue
|
507
|
-
}
|
508
|
-
let assumed = { isResponse: true }
|
509
|
-
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
510
|
-
let generatedParenthesized = []
|
511
|
-
if (generateParenthesized) {
|
512
|
-
config.parenthesized = true
|
513
|
-
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
514
|
-
config.parenthesized = false
|
515
|
-
}
|
516
|
-
// assumed = { paraphrase: true, response: false };
|
517
|
-
assumed = { paraphrase: true, isResponse: false, response: false }
|
518
|
-
if (generateParenthesized) {
|
519
|
-
config.parenthesized = false
|
520
|
-
}
|
521
|
-
const paraphrases = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
522
|
-
let paraphrasesParenthesized = []
|
523
|
-
if (generateParenthesized) {
|
524
|
-
config.parenthesized = true
|
525
|
-
paraphrasesParenthesized = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
526
|
-
config.parenthesized = false
|
527
|
-
}
|
528
|
-
contextsPrime.push(contextPrime)
|
529
|
-
generatedPrime.push(generated)
|
530
|
-
paraphrasesPrime.push(paraphrases)
|
531
|
-
if (generateParenthesized) {
|
532
|
-
paraphrasesParenthesizedPrime.push(paraphrasesParenthesized)
|
533
|
-
generatedParenthesizedPrime.push(generatedParenthesized)
|
534
|
-
}
|
535
|
-
if (contextPrime.isResponse) {
|
536
|
-
responsesPrime.push(generated)
|
537
|
-
} else {
|
538
|
-
responsesPrime.push('')
|
539
|
-
}
|
540
|
-
|
541
|
-
// add results to processed list
|
542
|
-
config.config.objects.processed = config.config.objects.processed || []
|
543
|
-
config.config.objects.processed = config.config.objects.processed.slice(0, 5)
|
544
|
-
config.config.objects.processed.unshift({ context: contextPrime, paraphrases: paraphrases, paraphrasesParenthesized, generatedParenthesized, responses: responsesPrime })
|
545
|
-
} catch (e) {
|
546
|
-
if (Array.isArray(e)) {
|
547
|
-
e = {
|
548
|
-
errors: e
|
549
|
-
}
|
550
|
-
}
|
551
|
-
e.context = contextPrime
|
552
|
-
if (e.logs) {
|
553
|
-
e.logs = e.logs.concat(json.logs)
|
554
|
-
} else {
|
555
|
-
e.logs = json.logs
|
556
|
-
}
|
557
|
-
e.metadata = json.metadata
|
558
|
-
if (json.trace) {
|
559
|
-
e.trace = json.trace
|
560
|
-
}
|
561
|
-
throw e
|
562
|
-
}
|
563
|
-
}
|
564
|
-
return { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime }
|
565
|
-
}
|
566
|
-
|
567
214
|
const doWithRetries = async (n, url, queryParams, data) => {
|
568
215
|
if (!queryParams) {
|
569
216
|
queryParams = ''
|
@@ -598,93 +245,6 @@ const doWithRetries = async (n, url, queryParams, data) => {
|
|
598
245
|
}
|
599
246
|
}
|
600
247
|
|
601
|
-
const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
|
602
|
-
const key = config._key
|
603
|
-
|
604
|
-
const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
|
605
|
-
if (allowDelta && config.allowDelta && config.hasDelta()) {
|
606
|
-
// console.log('config', config)
|
607
|
-
data.delta = config.delta()
|
608
|
-
} else {
|
609
|
-
config.toData(data)
|
610
|
-
// Object.assign(data, config.config)
|
611
|
-
}
|
612
|
-
|
613
|
-
// config.toServer(data)
|
614
|
-
|
615
|
-
if (data.namespaces) {
|
616
|
-
for (const uuid of Object.keys(data.namespaces)) {
|
617
|
-
const km = config.configs.find((km) => km.uuid === uuid)
|
618
|
-
data.namespaces[uuid].name = km.name
|
619
|
-
}
|
620
|
-
}
|
621
|
-
|
622
|
-
// const generators = new Generators((data.generators || []).map((g) => new Generator(normalizeGenerator(g))))
|
623
|
-
delete data.generators
|
624
|
-
// const semantics = new Semantics((data.semantics || []).map((g) => new Semantic(normalizeSemantic(g))))
|
625
|
-
delete data.semantics
|
626
|
-
const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
|
627
|
-
|
628
|
-
return {
|
629
|
-
data,
|
630
|
-
// generators,
|
631
|
-
// semantics,
|
632
|
-
hierarchy
|
633
|
-
}
|
634
|
-
}
|
635
|
-
|
636
|
-
// instance template loadTemplate
|
637
|
-
const loadInstance = (config, instance) => {
|
638
|
-
const transitoryMode = global.transitoryMode
|
639
|
-
global.transitoryMode = false
|
640
|
-
|
641
|
-
if (instance && (instance.associations || instance.learned_contextual_priorities)) {
|
642
|
-
if (!config.config.retrain) {
|
643
|
-
if (instance.associations) {
|
644
|
-
config.addAssociations(instance.associations)
|
645
|
-
}
|
646
|
-
if (instance.learned_contextual_priorities && instance.learned_contextual_priorities.length > 0) {
|
647
|
-
config.addPriorities(instance.learned_contextual_priorities)
|
648
|
-
}
|
649
|
-
}
|
650
|
-
}
|
651
|
-
|
652
|
-
const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
|
653
|
-
// for (const results of (instance.resultss || [])) {
|
654
|
-
for (const i in (instance.resultss || [])) {
|
655
|
-
const results = instance.resultss[i]
|
656
|
-
if (results.extraConfig) {
|
657
|
-
// config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
|
658
|
-
const uuid = config.nameToUUID(instance.name)
|
659
|
-
// used to do a CLONE
|
660
|
-
config.addInternal(instance.template.configs[i], { uuid, addFirst: true, handleCalculatedProps: true })
|
661
|
-
} else if (results.apply) {
|
662
|
-
const objects = config.get('objects')
|
663
|
-
const args = { objects, getObjects: getObjects(objects) }
|
664
|
-
if (instance.configs) {
|
665
|
-
args.isInstance = `instance${i}`
|
666
|
-
args.instance = instance.configs[i]
|
667
|
-
}
|
668
|
-
|
669
|
-
const uuid = config.nameToUUID(instance.name)
|
670
|
-
setupArgs(args, config, config.logs, hierarchy, uuid)
|
671
|
-
results.apply(args)
|
672
|
-
} else {
|
673
|
-
if (results.skipSemantics) {
|
674
|
-
config.config.skipSemantics = results.skipSemantics
|
675
|
-
}
|
676
|
-
const args = { config, hierarchy, json: results, commandLineArgs: {} }
|
677
|
-
args.isInstance = `instance${i}`
|
678
|
-
args.instance = ''
|
679
|
-
processContextsB(args)
|
680
|
-
if (results.skipSemantics) {
|
681
|
-
config.config.skipSemantics = null
|
682
|
-
}
|
683
|
-
}
|
684
|
-
}
|
685
|
-
global.transitoryMode = transitoryMode
|
686
|
-
}
|
687
|
-
|
688
248
|
const throwErrorHandler = (error) => {
|
689
249
|
throw error
|
690
250
|
}
|
@@ -701,7 +261,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
701
261
|
// ensure same start state
|
702
262
|
try {
|
703
263
|
if (writeTests) {
|
704
|
-
config.rebuild()
|
264
|
+
await config.rebuild()
|
705
265
|
const objects = getObjects(config.config.objects)(config.uuid)
|
706
266
|
}
|
707
267
|
} catch (error) {
|
@@ -737,12 +297,14 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
737
297
|
associations: []
|
738
298
|
}
|
739
299
|
|
300
|
+
let startCounter = 0
|
740
301
|
while (true) {
|
741
302
|
if (queries.length === 0) {
|
742
303
|
break
|
743
304
|
}
|
744
305
|
|
745
306
|
data.utterance = queries[0]
|
307
|
+
data.start_counter = startCounter
|
746
308
|
let json = await doWithRetries(retries, url, queryParams, data)
|
747
309
|
let resetData = false
|
748
310
|
if (json.code == 'NOT_IN_CACHE') {
|
@@ -764,6 +326,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
764
326
|
}
|
765
327
|
}
|
766
328
|
json.contexts = json.results
|
329
|
+
startCounter= json.end_counter + 1
|
767
330
|
delete json.results
|
768
331
|
if (json.status !== 200) {
|
769
332
|
throw json
|
@@ -773,7 +336,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
773
336
|
start = runtime.performance.performance.now()
|
774
337
|
}
|
775
338
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
776
|
-
processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
339
|
+
await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
777
340
|
if (isTest) {
|
778
341
|
end = runtime.performance.performance.now()
|
779
342
|
clientSideTime = end - start
|
@@ -801,6 +364,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
801
364
|
response.generatedParenthesized = response.generatedParenthesized.concat(generatedParenthesizedPrime)
|
802
365
|
response.responses = response.responses.concat(responsesPrime)
|
803
366
|
queries = queries.slice(1)
|
367
|
+
|
804
368
|
}
|
805
369
|
}
|
806
370
|
|
@@ -828,7 +392,6 @@ const getConfigForTest = (config, testConfig) => {
|
|
828
392
|
}
|
829
393
|
const configForTest = {}
|
830
394
|
for (const key of Object.keys(includes)) {
|
831
|
-
// configForTest[key] = config.config[key]
|
832
395
|
if (key === 'words') {
|
833
396
|
const words = config.config.words
|
834
397
|
configForTest.words = {
|
@@ -838,7 +401,14 @@ const getConfigForTest = (config, testConfig) => {
|
|
838
401
|
}
|
839
402
|
|
840
403
|
const literals = config.config.words.literals
|
404
|
+
let includesWord = (word) => true
|
405
|
+
if (Array.isArray(includes.words)) {
|
406
|
+
includesWord = (word) => includes.words.includes(word)
|
407
|
+
}
|
841
408
|
for (const key in literals) {
|
409
|
+
if (!includesWord(key)) {
|
410
|
+
continue
|
411
|
+
}
|
842
412
|
const defs = []
|
843
413
|
for (const def of literals[key]) {
|
844
414
|
// TODO handle thie uuids the right way
|
@@ -847,15 +417,23 @@ const getConfigForTest = (config, testConfig) => {
|
|
847
417
|
configForTest.words.literals[key] = defs
|
848
418
|
}
|
849
419
|
|
850
|
-
const patterns = config.config.words.patterns
|
420
|
+
const patterns = config.config.words.patterns || []
|
851
421
|
configForTest.words.patterns = patterns.map((pattern) => Object.assign({}, pattern, { uuid: undefined }))
|
852
422
|
|
853
|
-
const hierarchy = config.config.words.hierarchy
|
423
|
+
const hierarchy = config.config.words.hierarchy || []
|
854
424
|
configForTest.words.hierarchy = hierarchy.map((hierarchy) => Object.assign({}, hierarchy, { uuid: undefined }))
|
855
425
|
} else if (key === 'operators') {
|
856
|
-
|
426
|
+
let include = (operator) => true
|
427
|
+
if (Array.isArray(includes.operators)) {
|
428
|
+
include = (operator) => includes.operators.includes(operator.pattern)
|
429
|
+
}
|
430
|
+
configForTest.operators = config.config.operators.filter( include ).map((operator) => Object.assign({}, operator, { uuid: undefined }))
|
857
431
|
} else if (key === 'bridges') {
|
858
|
-
|
432
|
+
let include = (operator) => true
|
433
|
+
if (Array.isArray(includes.bridges)) {
|
434
|
+
include = (bridge) => includes.bridges.includes(bridge.id)
|
435
|
+
}
|
436
|
+
configForTest.bridges = config.config.bridges.filter(include).map((bridge) => Object.assign({}, bridge, { uuid: undefined }))
|
859
437
|
} else {
|
860
438
|
configForTest[key] = config.config[key]
|
861
439
|
}
|
@@ -865,8 +443,12 @@ const getConfigForTest = (config, testConfig) => {
|
|
865
443
|
|
866
444
|
const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
|
867
445
|
const test = expected.query
|
446
|
+
if (args.query && args.query != test) {
|
447
|
+
// no run this
|
448
|
+
return
|
449
|
+
}
|
868
450
|
// initialize in between test so state is not preserved since the test was adding without state
|
869
|
-
config.rebuild()
|
451
|
+
await config.rebuild()
|
870
452
|
const errorHandler = (error) => {
|
871
453
|
if (error.metadata) {
|
872
454
|
const priorities = analyzeMetaData(expected.metadata, error.metadata)
|
@@ -1012,7 +594,7 @@ const runTests = async (config, testFile, juicyBits) => {
|
|
1012
594
|
}
|
1013
595
|
|
1014
596
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
1015
|
-
config.rebuild()
|
597
|
+
await config.rebuild()
|
1016
598
|
const objects = getObjects(config.config.objects)(config.uuid)
|
1017
599
|
console.log(test)
|
1018
600
|
const result = await _process(config, test, { isTest: true })
|
@@ -1033,11 +615,11 @@ const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDe
|
|
1033
615
|
return
|
1034
616
|
}
|
1035
617
|
const test = todo.pop()
|
1036
|
-
config.rebuild()
|
618
|
+
await config.rebuild()
|
1037
619
|
const result = await saveTest(testFile, config, test, tests[test], testConfig, saveDeveloper)
|
1038
620
|
// initialize in between test so state is not preserved since the test was adding without state
|
1039
621
|
// config.initialize({force: true})
|
1040
|
-
config.rebuild()
|
622
|
+
await config.rebuild()
|
1041
623
|
return saveTestsHelper(testFile, config, tests, todo, testConfig, saveDeveloper)
|
1042
624
|
}
|
1043
625
|
|
@@ -1324,6 +906,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1324
906
|
associations: [],
|
1325
907
|
learned_contextual_priorities: []
|
1326
908
|
}
|
909
|
+
config.fragmentsBeingBuilt = []
|
1327
910
|
const looper = async (configs) => {
|
1328
911
|
if (configs.length === 0) {
|
1329
912
|
finish()
|
@@ -1331,14 +914,15 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1331
914
|
}
|
1332
915
|
const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = configs.shift()
|
1333
916
|
// queries are strings or { query: "blah", development: true/false }
|
1334
|
-
if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query) {
|
917
|
+
if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query || queryOrExtraConfig.isFragment) {
|
1335
918
|
let query = queryOrExtraConfig
|
919
|
+
let isFragment = queryOrExtraConfig.isFragment
|
1336
920
|
if (typeof queryOrExtraConfig === 'string') {
|
1337
921
|
query = { query }
|
1338
922
|
}
|
1339
|
-
config.config.skipSemantics = skipSemantics
|
923
|
+
config.config.skipSemantics = skipSemantics && !isFragment
|
1340
924
|
const transitoryMode = global.transitoryMode
|
1341
|
-
if (property == 'fragments') {
|
925
|
+
if (isFragment || property == 'fragments') {
|
1342
926
|
global.transitoryMode = true
|
1343
927
|
}
|
1344
928
|
if (hierarchy) {
|
@@ -1356,7 +940,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1356
940
|
if (previousResults && previousResults.query == query.query) {
|
1357
941
|
results = previousResults
|
1358
942
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
1359
|
-
loadInstance(config, { resultss: [results] })
|
943
|
+
await loadInstance(config, { resultss: [results] })
|
1360
944
|
} else {
|
1361
945
|
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
1362
946
|
}
|
@@ -1367,18 +951,22 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1367
951
|
if (results.contexts.length > 1) {
|
1368
952
|
console.log(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
1369
953
|
throw new Error(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
1370
|
-
} else if (results.paraphrases[0]
|
954
|
+
} else if (results.paraphrases[0].toLowerCase() !== query.query.toLowerCase()) {
|
1371
955
|
console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}".${prMessage}`)
|
1372
956
|
} else {
|
1373
|
-
console.log(`query "${query.query}".${prMessage}`)
|
957
|
+
console.log(`query ${isFragment ? 'fragment' : ''}"${query.query}".${prMessage}`)
|
1374
958
|
}
|
1375
959
|
global.transitoryMode = transitoryMode
|
1376
960
|
config.config.skipSemantics = null
|
1377
961
|
results.query = query.query
|
962
|
+
results.isFragment = isFragment
|
1378
963
|
results.skipSemantics = skipSemantics
|
1379
964
|
results.development = query.development
|
1380
965
|
results.key = { query: query.query, hierarchy }
|
1381
966
|
accumulators[property].push(results)
|
967
|
+
if (isFragment) {
|
968
|
+
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
969
|
+
}
|
1382
970
|
accumulators.associations = accumulators.associations.concat(results.associations)
|
1383
971
|
accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
|
1384
972
|
await looper(configs)
|
@@ -1392,8 +980,8 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1392
980
|
const initFunction = queryOrExtraConfig
|
1393
981
|
const objects = config.get('objects')
|
1394
982
|
const args = { objects, getObjects: getObjects(objects) }
|
1395
|
-
setupArgs(args, config, config.logs, hierarchy)
|
1396
|
-
initFunction(args)
|
983
|
+
setupArgs(args, config, config.logs, config.hierarchy)
|
984
|
+
await initFunction(args)
|
1397
985
|
accumulators[property].push({ apply: queryOrExtraConfig })
|
1398
986
|
await looper(configs)
|
1399
987
|
} else {
|
@@ -1417,6 +1005,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1417
1005
|
}
|
1418
1006
|
|
1419
1007
|
const finish = () => {
|
1008
|
+
config.fragmentsBeingBuilt = []
|
1420
1009
|
const instanceName = `${target}.instance.json`
|
1421
1010
|
console.log(`Writing instance file ${instanceName}`)
|
1422
1011
|
const stabilizeAssociations = (associations) => {
|
@@ -1505,11 +1094,16 @@ const checkTest = (testConfig) => {
|
|
1505
1094
|
}
|
1506
1095
|
|
1507
1096
|
const knowledgeModuleImpl = async ({
|
1097
|
+
includes,
|
1098
|
+
config : configStruct,
|
1099
|
+
api,
|
1100
|
+
initializer,
|
1101
|
+
terminator,
|
1102
|
+
multiApiInitializer,
|
1103
|
+
|
1508
1104
|
module: moduleFromJSFile,
|
1509
1105
|
description,
|
1510
1106
|
section,
|
1511
|
-
// config, createConfig,
|
1512
|
-
createConfig,
|
1513
1107
|
newWay,
|
1514
1108
|
demo,
|
1515
1109
|
test,
|
@@ -1517,7 +1111,6 @@ const knowledgeModuleImpl = async ({
|
|
1517
1111
|
errorHandler = defaultErrorHandler,
|
1518
1112
|
process: processResults = defaultProcess,
|
1519
1113
|
stopAtFirstFailure = true,
|
1520
|
-
acceptsAdditionalConfig = false,
|
1521
1114
|
...rest
|
1522
1115
|
} = {}) => {
|
1523
1116
|
const unknownArgs = Object.keys(rest)
|
@@ -1530,10 +1123,29 @@ const knowledgeModuleImpl = async ({
|
|
1530
1123
|
if (!moduleFromJSFile) {
|
1531
1124
|
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.")
|
1532
1125
|
}
|
1533
|
-
|
1534
|
-
if (!
|
1126
|
+
|
1127
|
+
if (!configStruct) {
|
1535
1128
|
throw new Error("'config' or 'createConfig' is a required parameter. The value should the config that defines the knowledge module.")
|
1536
1129
|
}
|
1130
|
+
|
1131
|
+
const createConfig = async () => {
|
1132
|
+
const config = new Config(configStruct, moduleFromJSFile, _process)
|
1133
|
+
config.setTerminator(terminator)
|
1134
|
+
config.stop_auto_rebuild()
|
1135
|
+
await config.add(...(includes || []))
|
1136
|
+
if (api) {
|
1137
|
+
config.setApi(api)
|
1138
|
+
}
|
1139
|
+
if (multiApiInitializer) {
|
1140
|
+
await config.setMultiApi(multiApiInitializer)
|
1141
|
+
}
|
1142
|
+
if (initializer) {
|
1143
|
+
config.initializer(initializer)
|
1144
|
+
}
|
1145
|
+
await config.restart_auto_rebuild()
|
1146
|
+
return config
|
1147
|
+
}
|
1148
|
+
|
1537
1149
|
if (!description) {
|
1538
1150
|
throw new Error("'description' is a required parameter. The value should the description of the knowledge module.")
|
1539
1151
|
}
|
@@ -1566,548 +1178,562 @@ const knowledgeModuleImpl = async ({
|
|
1566
1178
|
}
|
1567
1179
|
|
1568
1180
|
if (isProcess) {
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
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]]\''
|
1575
|
-
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]]\''
|
1576
|
-
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]]\''
|
1577
|
-
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}\''
|
1578
|
-
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\''
|
1579
|
-
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]))\''
|
1580
|
-
|
1581
|
-
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
1582
|
-
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1583
|
-
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' })
|
1584
|
-
// parser.add_argument('-ttr', '--testToRun', { help: 'Only the specified test will be run' })
|
1585
|
-
parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag' })
|
1586
|
-
parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
|
1587
|
-
parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
|
1588
|
-
// parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
|
1589
|
-
parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild. Using optimization where if the query/config has not changed it will use the previous value. One there is a change all subsequence query/configs will be run.' })
|
1590
|
-
parser.add_argument('-rtf', '--rebuildTemplateFull', { action: 'store_true', help: 'Force a template rebuild. Skip the optimization' })
|
1591
|
-
parser.add_argument('-l', '--loop', { action: 'store_true', help: 'Run a loop so that multiply queries may be run' })
|
1592
|
-
parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
|
1593
|
-
parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
|
1594
|
-
parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
|
1595
|
-
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]]' })
|
1596
|
-
parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
|
1597
|
-
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
1598
|
-
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
1599
|
-
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
1600
|
-
parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
|
1601
|
-
parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
|
1602
|
-
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
1603
|
-
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
1604
|
-
parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, g === generators, s === semantics, l === load t=tests ordering p === priorities a == associations j == JSON sent to server. for example --print wb' })
|
1605
|
-
parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
|
1606
|
-
parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
|
1607
|
-
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 ' })
|
1608
|
-
parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
|
1609
|
-
parser.add_argument('-da', '--debugAssociation', { action: 'store_true', help: helpDebugAssociation })
|
1610
|
-
parser.add_argument('-dw', '--debugWord', { action: 'store_true', help: helpDebugWord })
|
1611
|
-
parser.add_argument('-dh', '--debugHierarchy', { action: 'store_true', help: helpDebugHierarchy })
|
1612
|
-
parser.add_argument('-dp', '--debugPriority', { action: 'store_true', help: helpDebugPriority })
|
1613
|
-
parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
|
1614
|
-
parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
|
1615
|
-
parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
|
1616
|
-
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' })
|
1617
|
-
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' })
|
1618
|
-
|
1619
|
-
const args = parser.parse_args()
|
1620
|
-
args.count = args.count || 1
|
1621
|
-
|
1622
|
-
if (args.rebuildTemplateFull) {
|
1623
|
-
args.rebuildTemplate = true
|
1624
|
-
}
|
1181
|
+
let config
|
1182
|
+
try {
|
1183
|
+
const parser = new runtime.ArgumentParser({
|
1184
|
+
description: 'Entodicton knowledge module'
|
1185
|
+
})
|
1625
1186
|
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1187
|
+
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"\''
|
1188
|
+
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]]\''
|
1189
|
+
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]]\''
|
1190
|
+
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]]\''
|
1191
|
+
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}\''
|
1192
|
+
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\''
|
1193
|
+
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]))\''
|
1194
|
+
|
1195
|
+
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
1196
|
+
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1197
|
+
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' })
|
1198
|
+
// parser.add_argument('-ttr', '--testToRun', { help: 'Only the specified test will be run' })
|
1199
|
+
parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag. if -q is specified the tests will be run for just the specified query.' })
|
1200
|
+
parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
|
1201
|
+
parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
|
1202
|
+
// parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
|
1203
|
+
parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild. Using optimization where if the query/config has not changed it will use the previous value. One there is a change all subsequence query/configs will be run.' })
|
1204
|
+
parser.add_argument('-rtf', '--rebuildTemplateFull', { action: 'store_true', help: 'Force a template rebuild. Skip the optimization' })
|
1205
|
+
parser.add_argument('-l', '--loop', { action: 'store_true', help: 'Run a loop so that multiply queries may be run' })
|
1206
|
+
parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
|
1207
|
+
parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
|
1208
|
+
parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
|
1209
|
+
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]]' })
|
1210
|
+
parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
|
1211
|
+
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
1212
|
+
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
1213
|
+
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
1214
|
+
parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
|
1215
|
+
parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
|
1216
|
+
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
1217
|
+
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
1218
|
+
parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, g === generators, s === semantics, l === load t=tests ordering p === priorities a == associations j == JSON sent to server. for example --print wb' })
|
1219
|
+
parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
|
1220
|
+
parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
|
1221
|
+
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 ' })
|
1222
|
+
parser.add_argument('-d', '--debug', { action: 'store_true', help: 'When running with the --debug flag this set the debug flag in the config' })
|
1223
|
+
parser.add_argument('-da', '--debugAssociation', { action: 'store_true', help: helpDebugAssociation })
|
1224
|
+
parser.add_argument('-dw', '--debugWord', { action: 'store_true', help: helpDebugWord })
|
1225
|
+
parser.add_argument('-dh', '--debugHierarchy', { action: 'store_true', help: helpDebugHierarchy })
|
1226
|
+
parser.add_argument('-dp', '--debugPriority', { action: 'store_true', help: helpDebugPriority })
|
1227
|
+
parser.add_argument('-dcp', '--debugContextualPriority', { action: 'store_true', help: helpDebugContextualPriority })
|
1228
|
+
parser.add_argument('-db', '--debugBridge', { action: 'store_true', help: helpDebugBridge })
|
1229
|
+
parser.add_argument('-do', '--debugOperator', { action: 'store_true', help: helpDebugOperator })
|
1230
|
+
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' })
|
1231
|
+
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' })
|
1232
|
+
|
1233
|
+
const args = parser.parse_args()
|
1234
|
+
args.count = args.count || 1
|
1235
|
+
|
1236
|
+
if (args.rebuildTemplateFull) {
|
1237
|
+
args.rebuildTemplate = true
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
config = await createConfig()
|
1241
|
+
|
1242
|
+
// dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
|
1243
|
+
if (args.rebuildTemplate) {
|
1244
|
+
global.pauseDebugging = true
|
1245
|
+
}
|
1630
1246
|
|
1631
|
-
|
1632
|
-
|
1633
|
-
processResults = processResults({ config, errorHandler })
|
1247
|
+
setupConfig(config)
|
1248
|
+
processResults = processResults({ config, errorHandler })
|
1634
1249
|
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1250
|
+
if (args.rebuildTemplate) {
|
1251
|
+
global.pauseDebugging = false
|
1252
|
+
}
|
1638
1253
|
|
1639
|
-
|
1254
|
+
// setup();
|
1640
1255
|
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1256
|
+
if (args.parenthesized) {
|
1257
|
+
config.parenthesized = true
|
1258
|
+
}
|
1259
|
+
if (args.checkForLoop) {
|
1260
|
+
try {
|
1261
|
+
args.checkForLoop = JSON.parse(args.checkForLoop)
|
1262
|
+
const isKey = (what) => {
|
1263
|
+
if (!Array.isArray(what)) {
|
1264
|
+
return false
|
1265
|
+
}
|
1266
|
+
if (what.length !== 2) {
|
1267
|
+
return false
|
1268
|
+
}
|
1269
|
+
if (!typeof what[0] == 'string') {
|
1270
|
+
return false
|
1271
|
+
}
|
1272
|
+
if (!typeof what[1] == 'number') {
|
1273
|
+
return false
|
1274
|
+
}
|
1275
|
+
return true
|
1656
1276
|
}
|
1657
|
-
if (!
|
1658
|
-
|
1277
|
+
if (!Array.isArray(args.checkForLoop) || args.checkForLoop.some((value) => !isKey(value))) {
|
1278
|
+
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1659
1279
|
}
|
1660
|
-
|
1661
|
-
}
|
1662
|
-
if (!Array.isArray(args.checkForLoop) || args.checkForLoop.some((value) => !isKey(value))) {
|
1280
|
+
} catch (e) {
|
1663
1281
|
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1664
1282
|
}
|
1665
|
-
}
|
1666
|
-
|
1283
|
+
} else {
|
1284
|
+
if (process.argv.includes('--checkForLoop') || process.argv.includes('-cl')) {
|
1285
|
+
args.checkForLoop = true
|
1286
|
+
}
|
1667
1287
|
}
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1288
|
+
if (args.debugAssociation) {
|
1289
|
+
console.log(helpDebugAssociation)
|
1290
|
+
runtime.process.exit(-1)
|
1291
|
+
}
|
1292
|
+
if (args.debugWord) {
|
1293
|
+
console.log(helpDebugWord)
|
1294
|
+
runtime.process.exit(-1)
|
1295
|
+
}
|
1296
|
+
if (args.debugHierarchy) {
|
1297
|
+
console.log(helpDebugHierarchy)
|
1298
|
+
runtime.process.exit(-1)
|
1299
|
+
}
|
1300
|
+
if (args.debugPriority) {
|
1301
|
+
console.log(helpDebugPriority)
|
1302
|
+
runtime.process.exit(-1)
|
1303
|
+
}
|
1304
|
+
if (args.debugBridge) {
|
1305
|
+
console.log(helpDebugBridge)
|
1306
|
+
runtime.process.exit(-1)
|
1307
|
+
}
|
1308
|
+
if (args.debugOperator) {
|
1309
|
+
console.log(helpDebugOperator)
|
1310
|
+
runtime.process.exit(-1)
|
1671
1311
|
}
|
1672
|
-
}
|
1673
|
-
if (args.debugAssociation) {
|
1674
|
-
console.log(helpDebugAssociation)
|
1675
|
-
runtime.process.exit(-1)
|
1676
|
-
}
|
1677
|
-
if (args.debugWord) {
|
1678
|
-
console.log(helpDebugWord)
|
1679
|
-
runtime.process.exit(-1)
|
1680
|
-
}
|
1681
|
-
if (args.debugHierarchy) {
|
1682
|
-
console.log(helpDebugHierarchy)
|
1683
|
-
runtime.process.exit(-1)
|
1684
|
-
}
|
1685
|
-
if (args.debugPriority) {
|
1686
|
-
console.log(helpDebugPriority)
|
1687
|
-
runtime.process.exit(-1)
|
1688
|
-
}
|
1689
|
-
if (args.debugBridge) {
|
1690
|
-
console.log(helpDebugBridge)
|
1691
|
-
runtime.process.exit(-1)
|
1692
|
-
}
|
1693
|
-
if (args.debugOperator) {
|
1694
|
-
console.log(helpDebugOperator)
|
1695
|
-
runtime.process.exit(-1)
|
1696
|
-
}
|
1697
1312
|
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1313
|
+
if (args.clean) {
|
1314
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1315
|
+
for (const test of tests) {
|
1316
|
+
delete test.associations
|
1317
|
+
}
|
1318
|
+
writeTestFile(testConfig.name, tests)
|
1319
|
+
console.log(`Cleaned ${testConfig.name}`)
|
1320
|
+
return
|
1702
1321
|
}
|
1703
|
-
writeTestFile(testConfig.name, tests)
|
1704
|
-
console.log(`Cleaned ${testConfig.name}`)
|
1705
|
-
return
|
1706
|
-
}
|
1707
1322
|
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1323
|
+
if (args.deleteTest) {
|
1324
|
+
let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1325
|
+
tests = tests.filter((test) => test.query !== args.deleteTest)
|
1326
|
+
writeTestFile(testConfig.name, tests)
|
1327
|
+
console.log(`Remove the test for "${args.deleteTest}"`)
|
1328
|
+
return
|
1329
|
+
}
|
1715
1330
|
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1331
|
+
const options = { rebuild: false }
|
1332
|
+
if (args.rebuildTemplate) {
|
1333
|
+
options.rebuild = true
|
1334
|
+
}
|
1335
|
+
if (args.greg) {
|
1336
|
+
config.server('http://localhost:3000', '6804954f-e56d-471f-bbb8-08e3c54d9321')
|
1337
|
+
}
|
1338
|
+
if (args.server) {
|
1339
|
+
config.server(args.server)
|
1340
|
+
}
|
1726
1341
|
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1342
|
+
if (args.queryParams) {
|
1343
|
+
config.setQueryParams(args.queryParams)
|
1344
|
+
}
|
1730
1345
|
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1346
|
+
if (args.debug) {
|
1347
|
+
config.config.debug = true
|
1348
|
+
}
|
1734
1349
|
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1350
|
+
if (args.reset) {
|
1351
|
+
config.config.skip_cache = true
|
1352
|
+
}
|
1738
1353
|
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1354
|
+
if (args.explainPriorities) {
|
1355
|
+
config.config.explain_priorities = true
|
1356
|
+
}
|
1742
1357
|
|
1743
|
-
|
1358
|
+
config.config.debugIncludeConvolutions = args.debugIncludeConvolutions || process.argv.includes('--debugIncludeConvolutions') || process.argv.includes('-dic')
|
1744
1359
|
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
}
|
1750
|
-
configPrinted = true
|
1751
|
-
if (args.print) {
|
1752
|
-
if (args.print.includes('t')) {
|
1753
|
-
console.log('Test queries')
|
1754
|
-
let counter = 0
|
1755
|
-
for (const test of config.tests) {
|
1756
|
-
console.log(`${counter} - ${test.query}`)
|
1757
|
-
counter += 1
|
1758
|
-
}
|
1759
|
-
}
|
1760
|
-
if (args.print.includes('c')) {
|
1761
|
-
const { data } = setupProcessB({ config })
|
1762
|
-
console.log('Config as sent to server')
|
1763
|
-
console.log(JSON.stringify(data, null, 2))
|
1360
|
+
let configPrinted = false
|
1361
|
+
const printConfig = () => {
|
1362
|
+
if (configPrinted) {
|
1363
|
+
return
|
1764
1364
|
}
|
1365
|
+
configPrinted = true
|
1366
|
+
if (args.print) {
|
1367
|
+
if (args.print.includes('t')) {
|
1368
|
+
console.log('Test queries')
|
1369
|
+
let counter = 0
|
1370
|
+
for (const test of config.tests) {
|
1371
|
+
console.log(`${counter} - ${test.query}`)
|
1372
|
+
counter += 1
|
1373
|
+
}
|
1374
|
+
}
|
1375
|
+
if (args.print.includes('c')) {
|
1376
|
+
const { data } = setupProcessB({ config })
|
1377
|
+
console.log('Config as sent to server')
|
1378
|
+
console.log(JSON.stringify(data, null, 2))
|
1379
|
+
}
|
1765
1380
|
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1381
|
+
if (args.print.includes('l')) {
|
1382
|
+
console.log('Module load ordering')
|
1383
|
+
for (const km of config.configs) {
|
1384
|
+
console.log(` ${km.name}`)
|
1385
|
+
}
|
1770
1386
|
}
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1387
|
+
if (args.print.includes('w')) {
|
1388
|
+
// { literals: Object, patterns: Array(2), hierarchy: Array(97) }
|
1389
|
+
console.log('literals')
|
1390
|
+
for (const word in config.config.words.literals) {
|
1391
|
+
console.log(' ' + word.concat(...config.config.words.literals[word].map((def, i) => ((i > 0) ? ' '.repeat(4+word.length) : ' ') + JSON.stringify(def) + '\n')))
|
1392
|
+
}
|
1393
|
+
console.log('patterns')
|
1394
|
+
for (const pattern of config.config.words.patterns) {
|
1395
|
+
console.log(' ' + JSON.stringify(pattern))
|
1396
|
+
}
|
1777
1397
|
}
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1398
|
+
if (args.print.includes('b')) {
|
1399
|
+
for (const bridge of config.config.bridges) {
|
1400
|
+
console.log(JSON.stringify(bridge))
|
1401
|
+
}
|
1781
1402
|
}
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1403
|
+
if (args.print.includes('o')) {
|
1404
|
+
for (const operator of config.config.operators) {
|
1405
|
+
console.log(JSON.stringify(operator))
|
1406
|
+
}
|
1786
1407
|
}
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
console.log(JSON.stringify(operator))
|
1408
|
+
if (args.print.includes('j')) {
|
1409
|
+
const { data } = setupProcessB({ config })
|
1410
|
+
console.log(JSON.stringify(data, null, 2))
|
1791
1411
|
}
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
for (const property of properties) {
|
1801
|
-
console.log(` ${property} ===============`)
|
1802
|
-
for (const association of config.config.associations[property]) {
|
1803
|
-
console.log(` ${JSON.stringify(association)}`)
|
1412
|
+
if (args.print.includes('a')) {
|
1413
|
+
console.log('associations ================')
|
1414
|
+
const properties = ['negative', 'positive']
|
1415
|
+
for (const property of properties) {
|
1416
|
+
console.log(` ${property} ===============`)
|
1417
|
+
for (const association of config.config.associations[property]) {
|
1418
|
+
console.log(` ${JSON.stringify(association)}`)
|
1419
|
+
}
|
1804
1420
|
}
|
1805
1421
|
}
|
1806
|
-
|
1807
|
-
|
1808
|
-
console.log(JSON.stringify(config.config.objects, null, 2))
|
1809
|
-
}
|
1810
|
-
if (args.print.includes('p')) {
|
1811
|
-
for (const priority of config.config.priorities) {
|
1812
|
-
console.log(JSON.stringify(priority))
|
1422
|
+
if (args.print.includes('d')) {
|
1423
|
+
console.log(JSON.stringify(config.config.objects, null, 2))
|
1813
1424
|
}
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1425
|
+
if (args.print.includes('p')) {
|
1426
|
+
for (const priority of config.config.priorities) {
|
1427
|
+
console.log(JSON.stringify(priority))
|
1428
|
+
}
|
1818
1429
|
}
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
for (const semantic of easyToRead) {
|
1823
|
-
semantic.match = semantic.match.toString()
|
1824
|
-
semantic.apply = semantic.apply.toString()
|
1825
|
-
if (semantic.applyWrapped) {
|
1826
|
-
semantic.applyWrapped = semantic.applyWrapped.toString()
|
1430
|
+
if (args.print.includes('h')) {
|
1431
|
+
for (const edge of config.config.hierarchy) {
|
1432
|
+
console.log(JSON.stringify(edge))
|
1827
1433
|
}
|
1828
1434
|
}
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1435
|
+
if (args.print.includes('g')) {
|
1436
|
+
const easyToRead = _.cloneDeep(config.config.generators)
|
1437
|
+
for (const semantic of easyToRead) {
|
1438
|
+
semantic.match = semantic.match.toString()
|
1439
|
+
semantic.apply = semantic.apply.toString()
|
1440
|
+
if (semantic.applyWrapped) {
|
1441
|
+
semantic.applyWrapped = semantic.applyWrapped.toString()
|
1442
|
+
}
|
1443
|
+
}
|
1444
|
+
console.dir(easyToRead)
|
1445
|
+
}
|
1446
|
+
if (args.print.includes('s')) {
|
1447
|
+
const easyToRead = _.cloneDeep(config.config.semantics)
|
1448
|
+
for (const semantic of easyToRead) {
|
1449
|
+
semantic.match = semantic.match.toString()
|
1450
|
+
semantic.apply = semantic.apply.toString()
|
1451
|
+
}
|
1452
|
+
console.dir(easyToRead)
|
1836
1453
|
}
|
1837
|
-
console.dir(easyToRead)
|
1838
1454
|
}
|
1839
1455
|
}
|
1840
|
-
}
|
1841
1456
|
|
1842
|
-
|
1457
|
+
checkTemplate(template)
|
1843
1458
|
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1459
|
+
if (template) {
|
1460
|
+
let needsRebuild
|
1461
|
+
if (args.rebuildTemplate && !args.rebuildTemplateFull) {
|
1462
|
+
// get the startOfChanges for the partial rebuild
|
1463
|
+
needsRebuild = config.needsRebuild(template.template, template.instance, { ...options, rebuild: false })
|
1464
|
+
} else {
|
1465
|
+
// do a check or full rebuild
|
1466
|
+
needsRebuild = config.needsRebuild(template.template, template.instance, options)
|
1467
|
+
}
|
1853
1468
|
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1469
|
+
if (needsRebuild.needsRebuild) {
|
1470
|
+
if (needsRebuild.previousResultss) {
|
1471
|
+
console.log('Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf')
|
1472
|
+
}
|
1473
|
+
console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
|
1474
|
+
options.rebuild = true
|
1475
|
+
config.config.rebuild = true
|
1476
|
+
}
|
1477
|
+
try {
|
1478
|
+
await config.load(rebuildTemplate, template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1479
|
+
} catch (e) {
|
1480
|
+
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1481
|
+
runtime.process.exit(-1)
|
1482
|
+
}
|
1483
|
+
if (!args.query) {
|
1484
|
+
printConfig()
|
1485
|
+
}
|
1486
|
+
if (needsRebuild.needsRebuild) {
|
1487
|
+
return
|
1857
1488
|
}
|
1858
|
-
console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
|
1859
|
-
options.rebuild = true
|
1860
|
-
config.config.rebuild = true
|
1861
1489
|
}
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1866
|
-
runtime.process.exit(-1)
|
1490
|
+
|
1491
|
+
if (args.retrain) {
|
1492
|
+
config.config.retrain = true
|
1867
1493
|
}
|
1868
|
-
|
1869
|
-
|
1494
|
+
|
1495
|
+
if (args.saveDeveloper) {
|
1496
|
+
args.save = true
|
1870
1497
|
}
|
1871
|
-
if (
|
1872
|
-
|
1498
|
+
if (args.test || args.testVerbose || args.testAllVerbose || args.save) {
|
1499
|
+
global.transitoryMode = true
|
1873
1500
|
}
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
} else if (args.test || args.testVerbose || args.testAllVerbose) {
|
1890
|
-
// TODO make test always a string
|
1891
|
-
if (typeof test === 'string') {
|
1892
|
-
const l = (n, hasError) => {
|
1893
|
-
if (n === 0) {
|
1894
|
-
if (hasError) {
|
1895
|
-
runtime.process.exit(-1)
|
1501
|
+
if (!args.query && !args.test && !args.info && (args.save || args.saveDeveloper)) {
|
1502
|
+
global.transitoryMode = true
|
1503
|
+
await saveTests(config, test, testConfig, args.saveDeveloper)
|
1504
|
+
// } else if (args.build) {
|
1505
|
+
} else if (args.info) {
|
1506
|
+
showInfo(description, section, config)
|
1507
|
+
} else if (args.test || args.testVerbose || args.testAllVerbose) {
|
1508
|
+
// TODO make test always a string
|
1509
|
+
if (typeof test === 'string') {
|
1510
|
+
const l = async (n, hasError) => {
|
1511
|
+
if (n === 0) {
|
1512
|
+
if (hasError) {
|
1513
|
+
runtime.process.exit(-1)
|
1514
|
+
}
|
1515
|
+
return
|
1896
1516
|
}
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
test
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
for (const result of results) {
|
1912
|
-
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1913
|
-
result.hasError = true
|
1914
|
-
}
|
1915
|
-
if (!args.testNoParenthesized) {
|
1916
|
-
if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
|
1517
|
+
let useTestConfig = testConfig
|
1518
|
+
if (args.testModuleName) {
|
1519
|
+
useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
|
1520
|
+
useTestConfig.testModuleName = args.testModuleName
|
1521
|
+
test = useTestConfig.name
|
1522
|
+
}
|
1523
|
+
await runTests(config, test, { args, debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1524
|
+
let newError = false
|
1525
|
+
if (results.length > 0) {
|
1526
|
+
let headerShown = false
|
1527
|
+
|
1528
|
+
let hasError = false
|
1529
|
+
for (const result of results) {
|
1530
|
+
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1917
1531
|
result.hasError = true
|
1918
1532
|
}
|
1919
|
-
if (
|
1533
|
+
if (!args.testNoParenthesized) {
|
1534
|
+
if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
|
1535
|
+
result.hasError = true
|
1536
|
+
}
|
1537
|
+
if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
|
1538
|
+
result.hasError = true
|
1539
|
+
}
|
1540
|
+
}
|
1541
|
+
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1920
1542
|
result.hasError = true
|
1921
1543
|
}
|
1544
|
+
if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
|
1545
|
+
result.hasError = true
|
1546
|
+
}
|
1547
|
+
if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
|
1548
|
+
result.hasError = true
|
1549
|
+
}
|
1550
|
+
if (result.hasError) {
|
1551
|
+
hasError = true
|
1552
|
+
}
|
1922
1553
|
}
|
1923
|
-
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1924
|
-
result.hasError = true
|
1925
|
-
}
|
1926
|
-
if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
|
1927
|
-
result.hasError = true
|
1928
|
-
}
|
1929
|
-
if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
|
1930
|
-
result.hasError = true
|
1931
|
-
}
|
1932
|
-
if (result.hasError) {
|
1933
|
-
hasError = true
|
1934
|
-
}
|
1935
|
-
}
|
1936
1554
|
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1555
|
+
if (hasError) {
|
1556
|
+
console.log('**************************** ERRORS ************************')
|
1557
|
+
for (const result of results) {
|
1558
|
+
console.log('Utterance: ', result.utterance)
|
1559
|
+
const show = (label, expected, actual) => {
|
1560
|
+
if (JSON.stringify(expected) !== JSON.stringify(actual)) {
|
1561
|
+
if (!headerShown) {
|
1562
|
+
console.log(' Failure')
|
1563
|
+
}
|
1564
|
+
console.log(` expected ${label}`, expected)
|
1565
|
+
console.log(` actual ${label} `, actual)
|
1566
|
+
newError = true
|
1567
|
+
headerShown = true
|
1568
|
+
if (args.vimdiff) {
|
1569
|
+
vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
|
1570
|
+
}
|
1571
|
+
result.hasError = true
|
1572
|
+
}
|
1573
|
+
}
|
1574
|
+
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1575
|
+
if (!args.testNoParenthesized) {
|
1576
|
+
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
1577
|
+
}
|
1578
|
+
show('responses', result.expected.responses, result.actual.responses)
|
1579
|
+
if (!args.testNoParenthesized) {
|
1580
|
+
show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
|
1581
|
+
}
|
1582
|
+
/*
|
1583
|
+
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1943
1584
|
if (!headerShown) {
|
1944
1585
|
console.log(' Failure')
|
1945
1586
|
}
|
1946
|
-
console.log(
|
1947
|
-
console.log(
|
1587
|
+
console.log(' expected paraphrases', result.expected.paraphrases)
|
1588
|
+
console.log(' actual paraphrases ', result.actual.paraphrases)
|
1948
1589
|
newError = true
|
1949
1590
|
headerShown = true
|
1950
|
-
if (args.vimdiff) {
|
1951
|
-
vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
|
1952
|
-
}
|
1953
|
-
result.hasError = true
|
1954
|
-
}
|
1955
|
-
}
|
1956
|
-
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1957
|
-
if (!args.testNoParenthesized) {
|
1958
|
-
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
1959
|
-
}
|
1960
|
-
show('responses', result.expected.responses, result.actual.responses)
|
1961
|
-
if (!args.testNoParenthesized) {
|
1962
|
-
show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
|
1963
|
-
}
|
1964
|
-
/*
|
1965
|
-
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1966
|
-
if (!headerShown) {
|
1967
|
-
console.log(' Failure')
|
1968
1591
|
}
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1592
|
+
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1593
|
+
if (!headerShown) {
|
1594
|
+
console.log(' Failure')
|
1595
|
+
}
|
1596
|
+
console.log(' expected responses ', result.expected.responses)
|
1597
|
+
console.log(' actual responses ', result.actual.responses)
|
1598
|
+
newError = true
|
1599
|
+
headerShown = true
|
1977
1600
|
}
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1601
|
+
*/
|
1602
|
+
if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
|
1603
|
+
if (!headerShown) {
|
1604
|
+
console.log(' Failure')
|
1605
|
+
}
|
1606
|
+
const widths = [4, 18, 72]
|
1607
|
+
const lines = new Lines(widths)
|
1608
|
+
lines.setElement(1, 1, 'expected checked objects')
|
1609
|
+
lines.setElement(2, 2, JSON.stringify(result.expected.checked, null, 2))
|
1610
|
+
lines.log()
|
1611
|
+
lines.setElement(1, 1, 'actual checked objects')
|
1612
|
+
lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
|
1613
|
+
lines.log()
|
1614
|
+
if (args.vimdiff) {
|
1615
|
+
show('checked properties for objects', result.expected.checked, result.actual.checked)
|
1616
|
+
}
|
1617
|
+
newError = true
|
1618
|
+
headerShown = true
|
1987
1619
|
}
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1620
|
+
if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
|
1621
|
+
if (!headerShown) {
|
1622
|
+
console.log(' Failure')
|
1623
|
+
}
|
1624
|
+
const widths = [4, 18, 72]
|
1625
|
+
const lines = new Lines(widths)
|
1626
|
+
lines.setElement(1, 1, 'expected checked contexts', true)
|
1627
|
+
lines.setElement(2, 2, JSON.stringify(result.expected.checkedContexts, null, 2))
|
1628
|
+
lines.log()
|
1629
|
+
lines.setElement(1, 1, 'actual checked contexts', true)
|
1630
|
+
lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
|
1631
|
+
lines.log()
|
1632
|
+
if (args.vimdiff) {
|
1633
|
+
show('checked properties for context', result.expected.checkedContexts, result.actual.checkedContexts)
|
1634
|
+
}
|
1635
|
+
newError = true
|
1636
|
+
headerShown = true
|
1998
1637
|
}
|
1999
|
-
newError = true
|
2000
|
-
headerShown = true
|
2001
1638
|
}
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
1639
|
+
} else {
|
1640
|
+
if (results.length > 0 && args.vimdiff) {
|
1641
|
+
for (const result of results) {
|
1642
|
+
vimdiff(result.actual, result.expected)
|
2005
1643
|
}
|
2006
|
-
const widths = [4, 18, 72]
|
2007
|
-
const lines = new Lines(widths)
|
2008
|
-
lines.setElement(1, 1, 'expected checked contexts', true)
|
2009
|
-
lines.setElement(2, 2, JSON.stringify(result.expected.checkedContexts, null, 2))
|
2010
|
-
lines.log()
|
2011
|
-
lines.setElement(1, 1, 'actual checked contexts', true)
|
2012
|
-
lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
|
2013
|
-
lines.log()
|
2014
|
-
if (args.vimdiff) {
|
2015
|
-
vimdiff(result.actual.checkedContexts, result.expected.checkedContexts)
|
2016
|
-
}
|
2017
|
-
newError = true
|
2018
|
-
headerShown = true
|
2019
1644
|
}
|
2020
1645
|
}
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
1646
|
+
if (hasError) {
|
1647
|
+
if (!headerShown) {
|
1648
|
+
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1649
|
+
console.log('There are failures due to things other than paraphrases, responses and checked properties being different. They are not shown because you ran -tv or -tva which only shows difference in paraphrase and results. Usually what I do is -s and do a diff to make sure there are no other problems. If the paraphrases or results were different they would have shown here.')
|
1650
|
+
}
|
2025
1651
|
}
|
2026
|
-
}
|
2027
|
-
}
|
2028
|
-
if (hasError) {
|
2029
|
-
if (!headerShown) {
|
2030
1652
|
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
2031
|
-
console.log('
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
if (result.hasError) {
|
2040
|
-
errorCount += 1
|
1653
|
+
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.')
|
1654
|
+
// console.log(JSON.stringify(contexts))
|
1655
|
+
let errorCount = 0
|
1656
|
+
for (const result of results) {
|
1657
|
+
if (result.hasError) {
|
1658
|
+
console.log(`FAILED ${result.utterance}`)
|
1659
|
+
errorCount += 1
|
1660
|
+
}
|
2041
1661
|
}
|
1662
|
+
console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
|
2042
1663
|
}
|
2043
|
-
console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
|
2044
1664
|
}
|
2045
1665
|
}
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
1666
|
+
// const contexts = { failures: results }
|
1667
|
+
l(n - 1, hasError || newError)
|
1668
|
+
}).catch((error) => {
|
1669
|
+
console.error(error)
|
1670
|
+
runtime.process.exit(-1)
|
1671
|
+
errorHandler(error)
|
1672
|
+
})
|
1673
|
+
}
|
1674
|
+
await l(args.count, false)
|
1675
|
+
} else {
|
1676
|
+
test()
|
1677
|
+
}
|
1678
|
+
} else if (args.loop) {
|
1679
|
+
const readline = runtime.readline.createInterface({ input: runtime.process.stdin, output: runtime.process.stdout })
|
1680
|
+
const f = () => readline.question('Enter query? (newline to quit) ', query => {
|
1681
|
+
query = query.trim()
|
1682
|
+
if (query.length === 0) {
|
1683
|
+
return readline.close()
|
1684
|
+
}
|
1685
|
+
const promise = _process(config, query, { testsFN: test }).then((results) => {
|
1686
|
+
console.log(results.responses.join(' '))
|
2053
1687
|
})
|
1688
|
+
if (!('then' in promise)) {
|
1689
|
+
throw new Error('Return a promise from process in the definition of knowledgeModule')
|
1690
|
+
}
|
1691
|
+
promise
|
1692
|
+
.then(() => {
|
1693
|
+
f()
|
1694
|
+
})
|
1695
|
+
.catch((e) => {
|
1696
|
+
if (e.errno == 'ECONNREFUSED') {
|
1697
|
+
console.log(e)
|
1698
|
+
readline.close()
|
1699
|
+
} else {
|
1700
|
+
console.log(e)
|
1701
|
+
f()
|
1702
|
+
}
|
1703
|
+
})
|
1704
|
+
})
|
1705
|
+
f()
|
1706
|
+
} else if (args.query) {
|
1707
|
+
let useTestConfig = testConfig
|
1708
|
+
if (args.testModuleName) {
|
1709
|
+
config.testConfig.testModuleName = args.testModuleName
|
1710
|
+
config.testConfig.checks = config.getConfigs()[args.testModuleName].getTestConfig().checks
|
1711
|
+
// useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
|
1712
|
+
// useTestConfig.testModuleName = args.testModuleName
|
2054
1713
|
}
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
} else if (args.loop) {
|
2060
|
-
const readline = runtime.readline.createInterface({ input: runtime.process.stdin, output: runtime.process.stdout })
|
2061
|
-
const f = () => readline.question('Enter query? (newline to quit) ', query => {
|
2062
|
-
query = query.trim()
|
2063
|
-
if (query.length === 0) {
|
2064
|
-
return readline.close()
|
1714
|
+
const objects = getObjects(config.config.objects)(config.uuid)
|
1715
|
+
// for the compare
|
1716
|
+
if (args.objectDiff) {
|
1717
|
+
global.beforeObjects = _.cloneDeep(objects)
|
2065
1718
|
}
|
2066
|
-
|
2067
|
-
|
2068
|
-
})
|
2069
|
-
|
2070
|
-
throw new Error('Return a promise from process in the definition of knowledgeModule')
|
1719
|
+
try {
|
1720
|
+
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1721
|
+
} catch (error) {
|
1722
|
+
console.log('Error', error)
|
2071
1723
|
}
|
2072
|
-
promise
|
2073
|
-
.then(() => {
|
2074
|
-
f()
|
2075
|
-
})
|
2076
|
-
.catch((e) => {
|
2077
|
-
if (e.errno == 'ECONNREFUSED') {
|
2078
|
-
console.log(e)
|
2079
|
-
readline.close()
|
2080
|
-
} else {
|
2081
|
-
console.log(e)
|
2082
|
-
f()
|
2083
|
-
}
|
2084
|
-
})
|
2085
|
-
})
|
2086
|
-
f()
|
2087
|
-
} else if (args.query) {
|
2088
|
-
let useTestConfig = testConfig
|
2089
|
-
if (args.testModuleName) {
|
2090
|
-
config.testConfig.testModuleName = args.testModuleName
|
2091
|
-
config.testConfig.checks = config.getConfigs()[args.testModuleName].getTestConfig().checks
|
2092
|
-
// useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
|
2093
|
-
// useTestConfig.testModuleName = args.testModuleName
|
2094
1724
|
}
|
2095
|
-
|
2096
|
-
|
2097
|
-
if (
|
2098
|
-
|
2099
|
-
}
|
2100
|
-
try {
|
2101
|
-
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
2102
|
-
} catch (error) {
|
2103
|
-
console.log('Error', error)
|
1725
|
+
printConfig()
|
1726
|
+
} finally {
|
1727
|
+
if (config) {
|
1728
|
+
config.terminate()
|
2104
1729
|
}
|
2105
1730
|
}
|
2106
|
-
printConfig()
|
2107
1731
|
} else {
|
2108
|
-
const initConfig = (config) => {
|
1732
|
+
const initConfig = async (config) => {
|
2109
1733
|
if (template) {
|
2110
1734
|
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
1735
|
+
debugger
|
1736
|
+
config.needsRebuild(template.template, template.instance, { isModule: !isProcess })
|
2111
1737
|
const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
|
2112
1738
|
throw new Error(error)
|
2113
1739
|
}
|
@@ -2140,24 +1766,21 @@ const knowledgeModuleImpl = async ({
|
|
2140
1766
|
|
2141
1767
|
if (template) {
|
2142
1768
|
try {
|
2143
|
-
config.load(template.template, template.instance)
|
1769
|
+
await config.load(rebuildTemplate, template.template, template.instance)
|
2144
1770
|
} catch (e) {
|
2145
1771
|
errorHandler(e)
|
2146
1772
|
}
|
2147
1773
|
}
|
2148
1774
|
}
|
2149
1775
|
|
2150
|
-
|
2151
|
-
|
1776
|
+
// no cache 21 minutes + rebuild fails "node tester_rebuild -m colors"
|
1777
|
+
// cache okay
|
1778
|
+
createConfigExport = async () => {
|
1779
|
+
if (false && createConfig.cached) {
|
2152
1780
|
return createConfig.cached
|
2153
1781
|
}
|
2154
|
-
const config = createConfig(
|
2155
|
-
|
2156
|
-
config.stop_auto_rebuild()
|
2157
|
-
additionalConfig(config)
|
2158
|
-
config.restart_auto_rebuild()
|
2159
|
-
}
|
2160
|
-
initConfig(config)
|
1782
|
+
const config = await createConfig()
|
1783
|
+
await initConfig(config)
|
2161
1784
|
// config.rebuild({ isModule: true })
|
2162
1785
|
createConfig.cached = config
|
2163
1786
|
return createConfig.cached
|
@@ -2186,11 +1809,6 @@ const ensureTestFile = (module, name, type) => {
|
|
2186
1809
|
}
|
2187
1810
|
}
|
2188
1811
|
|
2189
|
-
function w (func) {
|
2190
|
-
func.where = where(3)
|
2191
|
-
return func
|
2192
|
-
}
|
2193
|
-
|
2194
1812
|
const knowledgeModule = async (...args) => {
|
2195
1813
|
await knowledgeModuleImpl(...args).catch((e) => {
|
2196
1814
|
console.error(e)
|
@@ -2201,9 +1819,6 @@ const knowledgeModule = async (...args) => {
|
|
2201
1819
|
module.exports = {
|
2202
1820
|
process: _process,
|
2203
1821
|
stableId,
|
2204
|
-
where,
|
2205
|
-
w,
|
2206
|
-
// submitBug,
|
2207
1822
|
ensureTestFile,
|
2208
1823
|
rebuildTemplate,
|
2209
1824
|
processContext,
|
@@ -2220,5 +1835,6 @@ module.exports = {
|
|
2220
1835
|
loadInstance,
|
2221
1836
|
gs,
|
2222
1837
|
flattens,
|
2223
|
-
writeTest
|
1838
|
+
writeTest,
|
1839
|
+
getConfigForTest,
|
2224
1840
|
}
|