theprogrammablemind 7.5.8-beta.6 → 7.5.8-beta.61
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 +205 -208
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/config.js +465 -215
- package/src/flatten.js +9 -1
- package/src/helpers.js +3 -1
- package/src/semantics.js +6 -1
package/client.js
CHANGED
@@ -15,14 +15,16 @@ const sortJson = runtime.sortJson
|
|
15
15
|
|
16
16
|
const getAsk = (config) => (uuid) => (asks) => {
|
17
17
|
for (let ask of asks) {
|
18
|
-
config.
|
18
|
+
config.addSemantic({
|
19
19
|
uuid,
|
20
|
+
oneShot: true,
|
20
21
|
match: (args) => ask.matchr(args),
|
21
22
|
apply: (args) => ask.applyr(args)
|
22
23
|
})
|
23
24
|
}
|
24
|
-
config.
|
25
|
+
config.addSemantic({
|
25
26
|
uuid,
|
27
|
+
oneShot: true,
|
26
28
|
match: ({context}) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
|
27
29
|
apply: (args) => {
|
28
30
|
for (let ask of asks) {
|
@@ -37,7 +39,7 @@ const getAsk = (config) => (uuid) => (asks) => {
|
|
37
39
|
}
|
38
40
|
}
|
39
41
|
if (matchq(args)) {
|
40
|
-
args.context.motivationKeep = true
|
42
|
+
// args.context.motivationKeep = true
|
41
43
|
args.context.verbatim = applyq(args)
|
42
44
|
args.context.isResponse = true;
|
43
45
|
delete args.context.controlRemove;
|
@@ -58,7 +60,6 @@ const vimdiff = (actualJSON, expectedJSON) => {
|
|
58
60
|
// console.log(`vimdiff ${path}/actual.json ${path}/expected.json`)
|
59
61
|
{
|
60
62
|
const editor = runtime.process.env.EDITOR || 'vimdiff'
|
61
|
-
debugger
|
62
63
|
// const child = runtime.child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
|
63
64
|
console.log(`${editor} ${path}/expected.json ${path}/actual.json`)
|
64
65
|
runtime.child_process.execSync(`${editor} ${path}/expected.json ${path}/actual.json`, {stdio: 'inherit'})
|
@@ -109,11 +110,12 @@ class ErrorReason extends Error {
|
|
109
110
|
|
110
111
|
const setupArgs = (args, config, logs, hierarchy) => {
|
111
112
|
config.setArgs(args)
|
112
|
-
args.calls = new InitCalls(config.name)
|
113
|
+
args.calls = new InitCalls(args.isInstance ? `${args.isInstance}#${config.name}` : config.name)
|
113
114
|
if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
|
114
115
|
args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
|
115
116
|
}
|
116
117
|
args.km = (name) => config.getConfig(name)
|
118
|
+
args.api = (name) => config.getConfig(name).api
|
117
119
|
args.error = (context) => {
|
118
120
|
throw new ErrorReason(context)
|
119
121
|
}
|
@@ -124,6 +126,7 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
124
126
|
args.listable = listable(hierarchy)
|
125
127
|
args.asList = asList
|
126
128
|
args.retry = () => { throw new RetryError() }
|
129
|
+
args.fragments = (query) => config.fragment(query)
|
127
130
|
const scopedAsk = getAsk(config)
|
128
131
|
|
129
132
|
const getAPI = (uuid) => {
|
@@ -143,7 +146,6 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
143
146
|
apis: getAPIs(uuid)
|
144
147
|
}
|
145
148
|
}
|
146
|
-
args.motivation = (m) => config.addMotivation(m)
|
147
149
|
args.breakOnSemantics = false
|
148
150
|
args.theDebugger = {
|
149
151
|
breakOnSemantics: (value) => args.breakOnSemantics = value
|
@@ -157,10 +159,10 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
157
159
|
}
|
158
160
|
args.e = (c) => config.getEvaluator(args.s, args.calls, logs, c)
|
159
161
|
args.log = (message) => logs.push(message)
|
160
|
-
// config.getAddedArgs(args)
|
161
162
|
args.gs = gs(args.g)
|
162
163
|
args.gsp = gs(args.gp)
|
163
164
|
args.gsr = gs(args.gr)
|
165
|
+
config.getAddedArgs(args)
|
164
166
|
}
|
165
167
|
|
166
168
|
const gs = (g) => (contexts, separator, lastSeparator) => {
|
@@ -298,7 +300,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
298
300
|
}
|
299
301
|
associations.sort()
|
300
302
|
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
301
|
-
debugger
|
302
303
|
results = sortJson({
|
303
304
|
query,
|
304
305
|
paraphrases,
|
@@ -367,7 +368,7 @@ const setupContexts = (rawContexts) => {
|
|
367
368
|
return contexts
|
368
369
|
}
|
369
370
|
|
370
|
-
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, query, data, retries, url, commandLineArgs }) => {
|
371
|
+
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, isInstance, query, data, retries, url, commandLineArgs }) => {
|
371
372
|
// TODO fix this name to contextsPrime
|
372
373
|
const contextsPrime = []
|
373
374
|
const generatedPrime = []
|
@@ -378,7 +379,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
378
379
|
const contexts = setupContexts(json.contexts)
|
379
380
|
|
380
381
|
const objects = config.get('objects')
|
381
|
-
const args = { objects, isResponse: true, response: json, isTest, getObjects: getObjects(objects) }
|
382
|
+
const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), isInstance }
|
382
383
|
if (!json.logs) {
|
383
384
|
json.logs = []
|
384
385
|
}
|
@@ -418,19 +419,18 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
418
419
|
if (json.has_errors) {
|
419
420
|
throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
|
420
421
|
}
|
422
|
+
const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
|
421
423
|
if (!config.get('skipSemantics')) {
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
|
430
|
-
}
|
431
|
-
// contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
|
432
|
-
contextPrime = semantics.apply(args, { marker: 'error', context, reason: e.reason })
|
424
|
+
const semantics = config.getSemantics(json.logs)
|
425
|
+
try {
|
426
|
+
contextPrime = semantics.apply(args, context)
|
427
|
+
} catch( e ) {
|
428
|
+
if (e.message == 'Maximum call stack size exceeded') {
|
429
|
+
const mostCalled = semantics.getMostCalled()
|
430
|
+
e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
|
433
431
|
}
|
432
|
+
// contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
|
433
|
+
contextPrime = semantics.apply(args, { marker: 'error', context, reason: e.reason })
|
434
434
|
}
|
435
435
|
}
|
436
436
|
if (contextPrime.controlRemove) {
|
@@ -439,7 +439,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
439
439
|
let assumed = { isResponse: true };
|
440
440
|
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0] : ''
|
441
441
|
let generatedParenthesized = []
|
442
|
-
if (
|
442
|
+
if (generateParenthesized) {
|
443
443
|
config.parenthesized = true
|
444
444
|
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0] : ''
|
445
445
|
config.parenthesized = false
|
@@ -452,12 +452,12 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
452
452
|
args.gs = gs(args.g)
|
453
453
|
args.gsp = gs(args.gsp)
|
454
454
|
args.gsr = gs(args.gr)
|
455
|
-
if (
|
455
|
+
if (generateParenthesized) {
|
456
456
|
config.parenthesized = false
|
457
457
|
}
|
458
458
|
const paraphrases = config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0]
|
459
459
|
let paraphrasesParenthesized = []
|
460
|
-
if (
|
460
|
+
if (generateParenthesized) {
|
461
461
|
config.parenthesized = true
|
462
462
|
paraphrasesParenthesized = config.getGenerators(json.logs).apply(args, contextPrime, assumed)[0]
|
463
463
|
config.parenthesized = false
|
@@ -471,7 +471,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
471
471
|
contextsPrime.push(contextPrime)
|
472
472
|
generatedPrime.push(generated)
|
473
473
|
paraphrasesPrime.push(paraphrases)
|
474
|
-
if (
|
474
|
+
if (generateParenthesized) {
|
475
475
|
paraphrasesParenthesizedPrime.push(paraphrasesParenthesized)
|
476
476
|
generatedParenthesizedPrime.push(generatedParenthesized)
|
477
477
|
}
|
@@ -549,8 +549,11 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
|
|
549
549
|
// console.log('config', config)
|
550
550
|
data.delta = config.delta()
|
551
551
|
} else {
|
552
|
-
|
552
|
+
config.toData(data)
|
553
|
+
// Object.assign(data, config.config)
|
553
554
|
}
|
555
|
+
|
556
|
+
// config.toServer(data)
|
554
557
|
|
555
558
|
if (data.namespaces) {
|
556
559
|
for (const uuid of Object.keys(data.namespaces)) {
|
@@ -574,7 +577,7 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
|
|
574
577
|
}
|
575
578
|
|
576
579
|
// instance template
|
577
|
-
const
|
580
|
+
const loadInstance = (config, instance) => {
|
578
581
|
const transitoryMode = global.transitoryMode
|
579
582
|
global.transitoryMode = false
|
580
583
|
const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
|
@@ -584,15 +587,15 @@ const processInstance = (config, instance) => {
|
|
584
587
|
if (results.extraConfig) {
|
585
588
|
// config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
|
586
589
|
// config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
|
587
|
-
config.addInternal(instance.template.queries[i], { handleCalculatedProps: true } )
|
590
|
+
config.addInternal(instance.template.queries[i], { addFirst: true, handleCalculatedProps: true } )
|
588
591
|
} else {
|
589
|
-
processContextsB({ config, hierarchy, json: results/*, generators, semantics */, commandLineArgs: {} })
|
592
|
+
processContextsB({ config, hierarchy, json: results/*, generators, semantics */, commandLineArgs: {}, isInstance: `instance${i}` })
|
590
593
|
}
|
591
594
|
}
|
592
595
|
global.transitoryMode = transitoryMode
|
593
596
|
}
|
594
597
|
|
595
|
-
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, testConfig, testsFN, errorHandler = defaultErrorHandler } = {}) => {
|
598
|
+
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = defaultErrorHandler } = {}) => {
|
596
599
|
if (credentials) {
|
597
600
|
config.server(credentials.server, credentials.key)
|
598
601
|
}
|
@@ -606,7 +609,6 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
606
609
|
if (writeTests) {
|
607
610
|
config.rebuild()
|
608
611
|
const objects = getObjects(config.config.objects)(config.uuid)
|
609
|
-
config.beforeQuery({ query, isModule: false, objects })
|
610
612
|
}
|
611
613
|
} catch(error) {
|
612
614
|
throw error
|
@@ -616,6 +618,9 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
616
618
|
if (commandLineArgs && commandLineArgs.checkForLoop) {
|
617
619
|
data.checkForLoop = true
|
618
620
|
}
|
621
|
+
if (rebuildingTemplate) {
|
622
|
+
data.errors_ignore_contextual_priorities_non_existant_ops = true
|
623
|
+
}
|
619
624
|
let queries = query.split('\\n')
|
620
625
|
|
621
626
|
try {
|
@@ -694,7 +699,12 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
694
699
|
|
695
700
|
if (writeTests) {
|
696
701
|
const actual_config = getConfigForTest(config, testConfig)
|
697
|
-
|
702
|
+
const saveObjects = {...config.config.objects}
|
703
|
+
saveObjects.nameToUUID = {}
|
704
|
+
for (let km of config.configs) {
|
705
|
+
saveObjects.nameToUUID[km.name] = km.uuid
|
706
|
+
}
|
707
|
+
writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized)
|
698
708
|
}
|
699
709
|
|
700
710
|
return response
|
@@ -734,7 +744,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
734
744
|
return configForTest
|
735
745
|
}
|
736
746
|
|
737
|
-
const runTest = async (config, expected, { args, verbose,
|
747
|
+
const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
|
738
748
|
const test = expected.query
|
739
749
|
// initialize in between test so state is not preserved since the test was adding without state
|
740
750
|
config.rebuild()
|
@@ -759,8 +769,6 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
759
769
|
objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
|
760
770
|
testConfigName = testConfig.testModuleName
|
761
771
|
}
|
762
|
-
config.beforeQuery({ query: test, isModule: false, objects })
|
763
|
-
// config.resetMotivations()
|
764
772
|
try {
|
765
773
|
const result = await _process(config, test, { errorHandler, isTest: true })
|
766
774
|
result.query = test
|
@@ -778,12 +786,17 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
778
786
|
delete expected_objects.nameToUUID
|
779
787
|
const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
|
780
788
|
const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
|
781
|
-
|
782
|
-
|
789
|
+
let failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
|
790
|
+
let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
|
783
791
|
const failed_responses = !matching(result.responses, expected.responses)
|
784
792
|
const failed_contexts = !matching(result.contexts, expected.contexts)
|
785
793
|
const failed_objects = !matching(actual_objects, expected_objects)
|
786
794
|
|
795
|
+
if (args.testNoParenthesized) {
|
796
|
+
failed_paraphrasesParenthesized = false
|
797
|
+
failed_generatedParenthesized = false
|
798
|
+
}
|
799
|
+
|
787
800
|
const pickEm = (getObjects) => {
|
788
801
|
const picked = {}
|
789
802
|
for (let prop of (testConfig.check || [])) {
|
@@ -809,6 +822,11 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
809
822
|
}
|
810
823
|
return expected.objects.namespaced[expected.objects.nameToUUID[name]]
|
811
824
|
}
|
825
|
+
try {
|
826
|
+
sortJson(pickEm(expectedGetObjects), { depth: 25 })
|
827
|
+
} catch ( e ) {
|
828
|
+
debugger
|
829
|
+
}
|
812
830
|
const expected_checked = sortJson(pickEm(expectedGetObjects), { depth: 25 })
|
813
831
|
const actualGetObjects = (name) => {
|
814
832
|
if (!name) {
|
@@ -825,37 +843,6 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
825
843
|
const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
|
826
844
|
const failed_config = !matching(actual_config, expected_config)
|
827
845
|
let failed = failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked
|
828
|
-
if (!failed) {
|
829
|
-
if (config.afterTest) {
|
830
|
-
failed = config.afterTest({ query: test, expected, actual: result, config })
|
831
|
-
if (failed) {
|
832
|
-
return {
|
833
|
-
utterance: test,
|
834
|
-
errorFromAfterTest: failed,
|
835
|
-
expected: {
|
836
|
-
responses: expected.responses,
|
837
|
-
paraphrases: expected.paraphrases,
|
838
|
-
paraphrasesParenthesized: expected.paraphrasesParenthesized,
|
839
|
-
generatedParenthesized: expected.generatedParenthesized,
|
840
|
-
results: expected.contexts,
|
841
|
-
checked: expected_checked,
|
842
|
-
objects: expected_objects,
|
843
|
-
config: expected.config
|
844
|
-
},
|
845
|
-
actual: {
|
846
|
-
responses: result.responses,
|
847
|
-
paraphrases: result.paraphrases,
|
848
|
-
paraphrasesParenthesized: result.paraphrasesParenthesized,
|
849
|
-
generatedParenthesized: result.generatedParenthesized,
|
850
|
-
results: result.contexts,
|
851
|
-
checked: actual_checked,
|
852
|
-
objects: actual_objects,
|
853
|
-
config: actual_config
|
854
|
-
}
|
855
|
-
}
|
856
|
-
}
|
857
|
-
}
|
858
|
-
}
|
859
846
|
|
860
847
|
if (expected.metadata && result.metadata && failed) {
|
861
848
|
const priorities = analyzeMetaData(expected.metadata, result.metadata)
|
@@ -923,20 +910,16 @@ const runTestsHelper = async (config, tests, failed, juicyBits) => {
|
|
923
910
|
|
924
911
|
const runTests = async (config, testFile, juicyBits) => {
|
925
912
|
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
926
|
-
config.beforeTests()
|
927
913
|
if (juicyBits.verbose) {
|
928
914
|
console.log('\n', testFile, '-----------------------------------------------', '\n')
|
929
915
|
}
|
930
916
|
const v = await runTestsHelper(config, [...tests], [], juicyBits)
|
931
|
-
config.afterTests()
|
932
917
|
return v
|
933
918
|
}
|
934
919
|
|
935
920
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
936
921
|
config.rebuild()
|
937
922
|
const objects = getObjects(config.config.objects)(config.uuid)
|
938
|
-
//config.resetMotivations()
|
939
|
-
config.beforeQuery({ query: test, isModule: false, objects })
|
940
923
|
console.log(test)
|
941
924
|
const result = await _process(config, test, { isTest: true })
|
942
925
|
// const actualObjects = config.config.objects
|
@@ -1118,10 +1101,11 @@ const defaultErrorHandler = async (error) => {
|
|
1118
1101
|
doErrorExit = true
|
1119
1102
|
}
|
1120
1103
|
|
1121
|
-
if (doErrorExit) {
|
1104
|
+
if (typeof runtime.process.exit == 'function' && doErrorExit) {
|
1122
1105
|
runtime.process.exit(-1)
|
1123
1106
|
}
|
1124
|
-
|
1107
|
+
|
1108
|
+
throw error
|
1125
1109
|
}
|
1126
1110
|
|
1127
1111
|
const defaultInnerProcess = (config, errorHandler, responses) => {
|
@@ -1142,6 +1126,37 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1142
1126
|
} else {
|
1143
1127
|
console.log('objects', runtime.util.inspect(config.get('objects'), { depth: Infinity, sorted: true }))
|
1144
1128
|
}
|
1129
|
+
|
1130
|
+
const pickEm = () => {
|
1131
|
+
const picked = {}
|
1132
|
+
const namespaced = config.get('objects')['namespaced']
|
1133
|
+
for (let prop of (config.testConfig.check || [])) {
|
1134
|
+
if (prop.km) {
|
1135
|
+
/*
|
1136
|
+
const objects = namespaced[prop.km]]
|
1137
|
+
picked[prop.km] = {}
|
1138
|
+
for (let p of c.testConfig.check) {
|
1139
|
+
if (p.km) {
|
1140
|
+
continue
|
1141
|
+
}
|
1142
|
+
picked[p] = objects[p]
|
1143
|
+
}
|
1144
|
+
*/
|
1145
|
+
console.log('TODO implement this if needed')
|
1146
|
+
} else {
|
1147
|
+
const objects = namespaced[config.uuid]
|
1148
|
+
picked[prop] = objects[prop]
|
1149
|
+
}
|
1150
|
+
}
|
1151
|
+
return picked
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
const picked = pickEm()
|
1155
|
+
if (!_.isEmpty(picked)) {
|
1156
|
+
console.log('--- checked object properties ---')
|
1157
|
+
console.log(JSON.stringify(picked, null, 2))
|
1158
|
+
}
|
1159
|
+
|
1145
1160
|
console.log('--- The contexts are ----------')
|
1146
1161
|
console.log(JSON.stringify(sortJson(responses.contexts, { depth: 25 }), null, 2))
|
1147
1162
|
console.log('')
|
@@ -1182,32 +1197,8 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
|
|
1182
1197
|
}
|
1183
1198
|
}
|
1184
1199
|
|
1185
|
-
|
1186
|
-
const
|
1187
|
-
`const entodicton = require('entodicton')
|
1188
|
-
const base = require('./${kmBaseName}').copy()
|
1189
|
-
const ${kmName}_tests = require('./${kmName}.test.json')
|
1190
|
-
const ${kmName}_instance = require('./${kmBaseName}.${kmName}.instance.json')
|
1191
|
-
|
1192
|
-
const config = new entodicton.Config({ name: '${kmName}' })
|
1193
|
-
config.add(base)
|
1194
|
-
kirk_instance.base = '${kmBaseName}'
|
1195
|
-
config.load(${kmName}_instance)
|
1196
|
-
|
1197
|
-
entodicton.knowledgeModule( {
|
1198
|
-
module,
|
1199
|
-
description: '${kmName} related concepts',
|
1200
|
-
section,
|
1201
|
-
config,
|
1202
|
-
test: {
|
1203
|
-
name: './${kmName}.test.json',
|
1204
|
-
contents: ${kmName}_tests
|
1205
|
-
},
|
1206
|
-
})
|
1207
|
-
`
|
1208
|
-
*/
|
1209
|
-
|
1210
|
-
const build = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
|
1200
|
+
// loadTemplate BuiltTemplate
|
1201
|
+
const rebuildTemplate = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
|
1211
1202
|
const accumulators = {
|
1212
1203
|
resultss: [],
|
1213
1204
|
fragments: [],
|
@@ -1231,8 +1222,6 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
|
|
1231
1222
|
if (property == 'fragments') {
|
1232
1223
|
global.transitoryMode = true
|
1233
1224
|
}
|
1234
|
-
// greg32
|
1235
|
-
// config.addInternal( query )
|
1236
1225
|
if (hierarchy) {
|
1237
1226
|
for (let edge of hierarchy) {
|
1238
1227
|
if (Array.isArray(edge)) {
|
@@ -1244,7 +1233,7 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
|
|
1244
1233
|
}
|
1245
1234
|
|
1246
1235
|
try {
|
1247
|
-
const results = await _process(config, query.query, {initializer})
|
1236
|
+
const results = await _process(config, query.query, {initializer, rebuildingTemplate: true})
|
1248
1237
|
if (config.config.debug) {
|
1249
1238
|
// TODO pass in the error handler like the other ones
|
1250
1239
|
defaultInnerProcess(config, defaultErrorHandler, results)
|
@@ -1274,6 +1263,12 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
|
|
1274
1263
|
// it will just get added to the config
|
1275
1264
|
const extraConfig = queryOrExtraConfig
|
1276
1265
|
console.log('config', extraConfig)
|
1266
|
+
try {
|
1267
|
+
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true } )
|
1268
|
+
} catch ( e ) {
|
1269
|
+
const where = extraConfig.where ? ` ${extraConfig.where}` : ''
|
1270
|
+
throw new Error(`Error processing extra config${where}: ${e.stack}}`)
|
1271
|
+
}
|
1277
1272
|
accumulators[property].push({ extraConfig: true, ...extraConfig })
|
1278
1273
|
await looper(queries)
|
1279
1274
|
}
|
@@ -1338,36 +1333,31 @@ const knowledgeModule = async ({
|
|
1338
1333
|
module: moduleFromJSFile,
|
1339
1334
|
description,
|
1340
1335
|
section,
|
1341
|
-
config,
|
1336
|
+
// config, createConfig,
|
1337
|
+
createConfig,
|
1338
|
+
newWay,
|
1342
1339
|
demo,
|
1343
1340
|
test,
|
1344
1341
|
template,
|
1345
1342
|
errorHandler = defaultErrorHandler,
|
1346
1343
|
process: processResults = defaultProcess,
|
1347
1344
|
stopAtFirstFailure = true,
|
1348
|
-
|
1349
|
-
beforeTests = () => {},
|
1350
|
-
afterTests = () => {},
|
1351
|
-
beforeTest = () => {},
|
1352
|
-
afterTest = () => {}
|
1345
|
+
...rest
|
1353
1346
|
} = {}) => {
|
1354
1347
|
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
config.afterTest = afterTest
|
1348
|
+
const unknownArgs = Object.keys(rest)
|
1349
|
+
if (unknownArgs.length > 0) {
|
1350
|
+
throw new Error(`Unknown arguments to knowledgeModule: ${unknownArgs.join()}`)
|
1351
|
+
}
|
1360
1352
|
|
1361
1353
|
const testConfig = test
|
1362
1354
|
|
1363
1355
|
if (!moduleFromJSFile) {
|
1364
1356
|
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.")
|
1365
1357
|
}
|
1366
|
-
if (!config) {
|
1367
|
-
|
1368
|
-
|
1369
|
-
if (!config.name) {
|
1370
|
-
throw new Error("config must have 'name' set to the knowledge module name.")
|
1358
|
+
// if (!config && !createConfig) {
|
1359
|
+
if (!createConfig) {
|
1360
|
+
throw new Error("'config' or 'createConfig' is a required parameter. The value should the config that defines the knowledge module.")
|
1371
1361
|
}
|
1372
1362
|
if (!description) {
|
1373
1363
|
throw new Error("'description' is a required parameter. The value should the description of the knowledge module.")
|
@@ -1377,86 +1367,51 @@ const knowledgeModule = async ({
|
|
1377
1367
|
}
|
1378
1368
|
|
1379
1369
|
const isProcess = require.main === moduleFromJSFile
|
1380
|
-
|
1381
|
-
|
1382
|
-
if (
|
1383
|
-
|
1370
|
+
|
1371
|
+
const setupConfig = (config) => {
|
1372
|
+
if (!config.name) {
|
1373
|
+
throw new Error("config must have 'name' set to the knowledge module name.")
|
1384
1374
|
}
|
1385
|
-
}
|
1386
1375
|
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
} else {
|
1393
|
-
return true
|
1394
|
-
}
|
1395
|
-
})
|
1396
|
-
config.config.bridges = config.config.bridges.filter( (bridge) => {
|
1397
|
-
if (bridge.development) {
|
1398
|
-
return false
|
1399
|
-
} else {
|
1400
|
-
return true
|
1376
|
+
config.description = description
|
1377
|
+
if (typeof test === 'object') {
|
1378
|
+
if (test.contents) {
|
1379
|
+
config.tests = test.contents
|
1380
|
+
test = test.name
|
1401
1381
|
}
|
1402
|
-
})
|
1403
|
-
}
|
1404
|
-
|
1405
|
-
let module
|
1406
|
-
if (_.isFunction(moduleFromJSFile)) {
|
1407
|
-
module = moduleFromJSFile
|
1408
|
-
} else {
|
1409
|
-
module = () => {
|
1410
|
-
config.rebuild({ isModule: true })
|
1411
|
-
moduleFromJSFile.exports = config
|
1412
|
-
}
|
1413
|
-
}
|
1414
|
-
processResults = processResults({ config, errorHandler })
|
1415
|
-
config.description = description
|
1416
|
-
config.demo = demo
|
1417
|
-
if (typeof test === 'object') {
|
1418
|
-
if (test.contents) {
|
1419
|
-
config.tests = test.contents
|
1420
|
-
test = test.name
|
1421
|
-
}
|
1422
|
-
} else {
|
1423
|
-
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1424
|
-
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1425
1382
|
} else {
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
if (!isProcess) {
|
1432
|
-
if (template) {
|
1433
|
-
if (config.needsRebuild(template.template, template.instance)) {
|
1434
|
-
throw new Error(`This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguements or the -rt argument to rebuild.`)
|
1435
|
-
}
|
1436
|
-
try {
|
1437
|
-
config.load(template.template, template.instance)
|
1438
|
-
} catch( e ) {
|
1439
|
-
errorHandler(e)
|
1383
|
+
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1384
|
+
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1385
|
+
} else {
|
1386
|
+
config.tests = []
|
1440
1387
|
}
|
1441
1388
|
}
|
1389
|
+
config.setTestConfig(testConfig)
|
1442
1390
|
}
|
1391
|
+
|
1392
|
+
|
1443
1393
|
if (isProcess) {
|
1394
|
+
const config = createConfig()
|
1395
|
+
setupConfig(config)
|
1396
|
+
processResults = processResults({ config, errorHandler })
|
1444
1397
|
// setup();
|
1445
1398
|
const parser = new runtime.ArgumentParser({
|
1446
1399
|
description: 'Entodicton knowledge module'
|
1447
1400
|
})
|
1448
1401
|
|
1449
|
-
const helpDebugAssociation = 'In order to get a debug break when a specific association is created set the DEBUG_ASSOCIATION environment variable to the JSON of the association to break on. For example DEBUG_ASSOCIATION=\'["the
|
1450
|
-
const helpDebugHierarchy = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_HIERARCHY environment variable to the JSON of the child-parent pair to break on. For example DEBUG_HIERARCHY=\'["cat
|
1451
|
-
const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'["verb
|
1452
|
-
const
|
1453
|
-
const
|
1402
|
+
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]]\''
|
1403
|
+
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]]\''
|
1404
|
+
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]]\''
|
1405
|
+
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}\''
|
1406
|
+
const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id/level to break on. For example DEBUG_BRIDGE=\'id#level\''
|
1407
|
+
const helpDebugOperator = 'In order to get a debug break when a specific hierarcy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\''
|
1454
1408
|
|
1455
1409
|
|
1456
1410
|
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
1457
1411
|
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1458
1412
|
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' })
|
1459
1413
|
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' })
|
1414
|
+
parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
|
1460
1415
|
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' })
|
1461
1416
|
// 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.' })
|
1462
1417
|
parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild' })
|
@@ -1483,6 +1438,7 @@ const knowledgeModule = async ({
|
|
1483
1438
|
parser.add_argument('-da', '--debugAssociation', { help: helpDebugAssociation })
|
1484
1439
|
parser.add_argument('-dh', '--debugHierarchy', { help: helpDebugHierarchy })
|
1485
1440
|
parser.add_argument('-dp', '--debugPriority', { help: helpDebugPriority })
|
1441
|
+
parser.add_argument('-dcp', '--debugContextualPriority', { help: helpDebugContextualPriority })
|
1486
1442
|
parser.add_argument('-db', '--debugBridge', { help: helpDebugBridge })
|
1487
1443
|
parser.add_argument('-do', '--debugOperator', { help: helpDebugOperator })
|
1488
1444
|
|
@@ -1559,6 +1515,10 @@ const knowledgeModule = async ({
|
|
1559
1515
|
|
1560
1516
|
}
|
1561
1517
|
config.load(template.template, template.instance, { rebuild: needsRebuild })
|
1518
|
+
if (config.name == 'ui') {
|
1519
|
+
console.log('config.COUNTER', config.COUNTER)
|
1520
|
+
debugger
|
1521
|
+
}
|
1562
1522
|
if (needsRebuild) {
|
1563
1523
|
return
|
1564
1524
|
}
|
@@ -1566,20 +1526,8 @@ const knowledgeModule = async ({
|
|
1566
1526
|
|
1567
1527
|
if (!args.save && !args.rebuildTemplate && !args.dontAddAssociations) {
|
1568
1528
|
config.addAssociationsFromTests(config.tests);
|
1569
|
-
//for (let query in config.tests) {
|
1570
|
-
// config.addAssociations(config.tests[query].associations || []);
|
1571
|
-
//}
|
1572
1529
|
}
|
1573
1530
|
|
1574
|
-
/*
|
1575
|
-
if (args.buildTemplate) {
|
1576
|
-
if (template) {
|
1577
|
-
config.rebuild()
|
1578
|
-
config.load(template.template, template.instance, { rebuild: true })
|
1579
|
-
}
|
1580
|
-
}
|
1581
|
-
*/
|
1582
|
-
|
1583
1531
|
let configPrinted = false
|
1584
1532
|
const printConfig = () => {
|
1585
1533
|
if (configPrinted) {
|
@@ -1712,11 +1660,13 @@ const knowledgeModule = async ({
|
|
1712
1660
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1713
1661
|
hasError = true
|
1714
1662
|
}
|
1715
|
-
if (
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1663
|
+
if (!args.testNoParenthesized) {
|
1664
|
+
if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
|
1665
|
+
hasError = true
|
1666
|
+
}
|
1667
|
+
if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
|
1668
|
+
hasError = true
|
1669
|
+
}
|
1720
1670
|
}
|
1721
1671
|
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
1722
1672
|
hasError = true
|
@@ -1742,9 +1692,13 @@ const knowledgeModule = async ({
|
|
1742
1692
|
}
|
1743
1693
|
}
|
1744
1694
|
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1745
|
-
|
1695
|
+
if (!args.testNoParenthesized) {
|
1696
|
+
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
1697
|
+
}
|
1746
1698
|
show('responses', result.expected.responses, result.actual.responses)
|
1747
|
-
|
1699
|
+
if (!args.testNoParenthesized) {
|
1700
|
+
show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
|
1701
|
+
}
|
1748
1702
|
/*
|
1749
1703
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1750
1704
|
if (!headerShown) {
|
@@ -1821,7 +1775,6 @@ const knowledgeModule = async ({
|
|
1821
1775
|
if (query.length === 0) {
|
1822
1776
|
return readline.close()
|
1823
1777
|
}
|
1824
|
-
// const promise = processResults(_process(config, query, { testsFN: test }))
|
1825
1778
|
const promise = _process(config, query, { testsFN: test }).then((results) => {
|
1826
1779
|
console.log(results.responses.join(' '))
|
1827
1780
|
})
|
@@ -1849,7 +1802,6 @@ const knowledgeModule = async ({
|
|
1849
1802
|
if (args.objectDiff) {
|
1850
1803
|
global.beforeObjects = _.cloneDeep(objects)
|
1851
1804
|
}
|
1852
|
-
config.beforeQuery({ query: args.query, isModule: false, objects })
|
1853
1805
|
try {
|
1854
1806
|
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1855
1807
|
} catch( error ) {
|
@@ -1858,11 +1810,55 @@ const knowledgeModule = async ({
|
|
1858
1810
|
}
|
1859
1811
|
printConfig()
|
1860
1812
|
} else {
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1813
|
+
const initConfig = (config) => {
|
1814
|
+
setupConfig(config)
|
1815
|
+
|
1816
|
+
let loadForTesting = false
|
1817
|
+
if (global.theprogrammablemind) {
|
1818
|
+
if (global.theprogrammablemind.loadForTesting[config.name]) {
|
1819
|
+
loadForTesting = true
|
1820
|
+
}
|
1821
|
+
}
|
1822
|
+
// remove test only stuff
|
1823
|
+
if (!isProcess && !loadForTesting) {
|
1824
|
+
config.config.operators = config.config.operators.filter( (operator) => {
|
1825
|
+
if (operator.development) {
|
1826
|
+
return false
|
1827
|
+
} else {
|
1828
|
+
return true
|
1829
|
+
}
|
1830
|
+
})
|
1831
|
+
config.config.bridges = config.config.bridges.filter( (bridge) => {
|
1832
|
+
if (bridge.development) {
|
1833
|
+
return false
|
1834
|
+
} else {
|
1835
|
+
return true
|
1836
|
+
}
|
1837
|
+
})
|
1838
|
+
}
|
1839
|
+
|
1840
|
+
if (template) {
|
1841
|
+
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess })) {
|
1842
|
+
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.`
|
1843
|
+
throw new Error(error)
|
1844
|
+
}
|
1845
|
+
try {
|
1846
|
+
config.load(template.template, template.instance)
|
1847
|
+
} catch( e ) {
|
1848
|
+
errorHandler(e)
|
1849
|
+
}
|
1850
|
+
}
|
1851
|
+
|
1852
|
+
config.addAssociationsFromTests(config.tests);
|
1853
|
+
}
|
1854
|
+
|
1855
|
+
createConfigExport = () => {
|
1856
|
+
const config = createConfig()
|
1857
|
+
initConfig(config)
|
1858
|
+
config.rebuild({ isModule: true })
|
1859
|
+
return config
|
1860
|
+
}
|
1861
|
+
moduleFromJSFile.exports = createConfigExport
|
1866
1862
|
}
|
1867
1863
|
|
1868
1864
|
}
|
@@ -1918,7 +1914,7 @@ module.exports = {
|
|
1918
1914
|
w,
|
1919
1915
|
// submitBug,
|
1920
1916
|
ensureTestFile,
|
1921
|
-
|
1917
|
+
rebuildTemplate,
|
1922
1918
|
processContext,
|
1923
1919
|
processContexts,
|
1924
1920
|
runTests,
|
@@ -1930,8 +1926,9 @@ module.exports = {
|
|
1930
1926
|
Digraph,
|
1931
1927
|
analyzeMetaData,
|
1932
1928
|
processContextsB,
|
1933
|
-
|
1929
|
+
loadInstance,
|
1934
1930
|
gs,
|
1935
1931
|
flattens,
|
1936
1932
|
writeTest
|
1937
1933
|
}
|
1934
|
+
|