theprogrammablemind 8.9.1-beta.27 → 8.9.1-beta.28
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 +114 -24
- package/package.json +1 -1
- package/src/config.js +31 -8
- package/src/helpers.js +25 -1
package/client.js
CHANGED
@@ -12,7 +12,7 @@ const _ = require('lodash')
|
|
12
12
|
const stringify = require('json-stable-stringify')
|
13
13
|
const Lines = require('./lines')
|
14
14
|
const flattens = require('./src/flatten')
|
15
|
-
const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where } = require('./src/helpers')
|
15
|
+
const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries } = require('./src/helpers')
|
16
16
|
const runtime = require('./runtime')
|
17
17
|
const sortJson = runtime.sortJson
|
18
18
|
|
@@ -35,6 +35,16 @@ const getConfig_getObjectsCheck = (config, testConfig) => {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
+
const getSuggestion = (diff) => {
|
39
|
+
return diff.map( (element) => {
|
40
|
+
return element.marker
|
41
|
+
})
|
42
|
+
}
|
43
|
+
|
44
|
+
const getSuggestionMessage = (suggestion) => {
|
45
|
+
return `Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestion))}, choose: <indexOfMainElement> },\n If that does not work look at the logs and check when the operators become wrong during an interation. Deduce the change based on the previous iteration and what operator was applied.`
|
46
|
+
}
|
47
|
+
|
38
48
|
const getConfig_getContextCheck = (testConfig) => {
|
39
49
|
return (testConfig.checks && testConfig.checks.context) || []
|
40
50
|
}
|
@@ -277,7 +287,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
277
287
|
data.errors_ignore_contextual_priorities_non_existant_ops = true
|
278
288
|
}
|
279
289
|
let queries = query.split('\\n')
|
280
|
-
|
290
|
+
let summaries = [] // for error
|
281
291
|
try {
|
282
292
|
const response = {
|
283
293
|
hierarchy: [],
|
@@ -295,11 +305,11 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
295
305
|
paraphrasesParenthesized: [],
|
296
306
|
generatedParenthesized: [],
|
297
307
|
responses: [],
|
298
|
-
associations: []
|
308
|
+
associations: [],
|
309
|
+
summaries: []
|
299
310
|
}
|
300
311
|
|
301
312
|
let startCounter = 0
|
302
|
-
const summaries = []
|
303
313
|
while (true) {
|
304
314
|
if (queries.length === 0) {
|
305
315
|
break
|
@@ -328,9 +338,6 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
328
338
|
}
|
329
339
|
}
|
330
340
|
json.contexts = json.results
|
331
|
-
if (json.summaries) {
|
332
|
-
summaries.push(json.summaries)
|
333
|
-
}
|
334
341
|
startCounter = json.end_counter + 1
|
335
342
|
delete json.results
|
336
343
|
if (json.status !== 200) {
|
@@ -340,6 +347,8 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
340
347
|
if (isTest) {
|
341
348
|
start = runtime.performance.performance.now()
|
342
349
|
}
|
350
|
+
const summary = { summaries: json.summaries, length: json.contexts.length }
|
351
|
+
summaries.push(summary)
|
343
352
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
344
353
|
await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
345
354
|
if (isTest) {
|
@@ -368,7 +377,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
368
377
|
response.paraphrasesParenthesized = response.paraphrasesParenthesized.concat(paraphrasesParenthesizedPrime)
|
369
378
|
response.generatedParenthesized = response.generatedParenthesized.concat(generatedParenthesizedPrime)
|
370
379
|
response.responses = response.responses.concat(responsesPrime)
|
371
|
-
response.summaries
|
380
|
+
response.summaries.push(summary)
|
372
381
|
queries = queries.slice(1)
|
373
382
|
}
|
374
383
|
}
|
@@ -380,11 +389,12 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
380
389
|
for (const km of config.configs) {
|
381
390
|
saveObjects.nameToUUID[km.name] = km.uuid
|
382
391
|
}
|
383
|
-
writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized, summaries)
|
392
|
+
writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized, response.summaries)
|
384
393
|
}
|
385
394
|
|
386
395
|
return response
|
387
396
|
} catch (error) {
|
397
|
+
error.summaries = summaries
|
388
398
|
error.query = query
|
389
399
|
errorHandler(error)
|
390
400
|
}
|
@@ -544,7 +554,8 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
544
554
|
checked: expected_checked,
|
545
555
|
checkedContexts: pickedExpectedContexts,
|
546
556
|
objects: expected_objects,
|
547
|
-
config: expected.config
|
557
|
+
config: expected.config,
|
558
|
+
summaries: expected.summaries,
|
548
559
|
},
|
549
560
|
actual: {
|
550
561
|
responses: result.responses,
|
@@ -555,7 +566,8 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
555
566
|
checked: actual_checked,
|
556
567
|
checkedContexts: pickedResultContexts,
|
557
568
|
objects: actual_objects,
|
558
|
-
config: actual_config
|
569
|
+
config: actual_config,
|
570
|
+
summaries: result.summaries,
|
559
571
|
}
|
560
572
|
}
|
561
573
|
}
|
@@ -909,12 +921,13 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
|
|
909
921
|
}
|
910
922
|
|
911
923
|
// builtTemplate saveInstance
|
912
|
-
const rebuildTemplate = async ({ config, target, previousResultss, startOfChanges, template, errorHandler = defaultErrorHandler }) => {
|
924
|
+
const rebuildTemplate = async ({ config, instance, target, previousResultss, rebuild, startOfChanges, template, errorHandler = defaultErrorHandler }) => {
|
913
925
|
const accumulators = {
|
914
926
|
resultss: [],
|
915
927
|
fragments: [],
|
916
928
|
semantics: [],
|
917
929
|
associations: [],
|
930
|
+
summaries: [],
|
918
931
|
learned_contextual_priorities: []
|
919
932
|
}
|
920
933
|
config.fragmentsBeingBuilt = []
|
@@ -948,12 +961,29 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
948
961
|
try {
|
949
962
|
let results
|
950
963
|
let prMessage = ''
|
951
|
-
|
964
|
+
const suggestFix = (newSummaries) => {
|
965
|
+
if (!previousResults) {
|
966
|
+
return
|
967
|
+
}
|
968
|
+
const suggestion = suggestAssociationsFixFromSummaries(previousResults.summaries, newSummaries)
|
969
|
+
if (suggestion.length > 0) {
|
970
|
+
console.log(getSuggestionMessage(suggestion))
|
971
|
+
}
|
972
|
+
}
|
973
|
+
if (!rebuild && previousResults && previousResults.query == query.query) {
|
952
974
|
results = previousResults
|
953
975
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
954
976
|
await loadInstance(config, { resultss: [results] })
|
955
977
|
} else {
|
956
|
-
|
978
|
+
try {
|
979
|
+
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
980
|
+
} catch (e) {
|
981
|
+
debugger
|
982
|
+
if (e.summaries && e.summaries.length > 0) {
|
983
|
+
suggestFix(e.summaries)
|
984
|
+
}
|
985
|
+
throw e
|
986
|
+
}
|
957
987
|
}
|
958
988
|
if (config.config.debug) {
|
959
989
|
// TODO pass in the error handler like the other ones
|
@@ -961,9 +991,11 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
961
991
|
}
|
962
992
|
if (results.contexts.length > 1) {
|
963
993
|
console.log(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
994
|
+
suggestFix(results.summaries)
|
964
995
|
throw new Error(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
965
996
|
} else if (results.paraphrases[0].toLowerCase() !== query.query.toLowerCase()) {
|
966
997
|
console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}".${prMessage}`)
|
998
|
+
// suggestFix(results.summaries)
|
967
999
|
} else {
|
968
1000
|
console.log(`query ${isFragment ? 'fragment' : ''}"${query.query}".${prMessage}`)
|
969
1001
|
}
|
@@ -978,6 +1010,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
978
1010
|
if (isFragment) {
|
979
1011
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
980
1012
|
}
|
1013
|
+
accumulators.summaries = accumulators.summaries.concat(results.summaries)
|
981
1014
|
accumulators.associations = accumulators.associations.concat(results.associations)
|
982
1015
|
accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
|
983
1016
|
await looper(configs)
|
@@ -1070,16 +1103,31 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1070
1103
|
}
|
1071
1104
|
let todo = []
|
1072
1105
|
todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false || query.skipSemantics } }))
|
1106
|
+
/*
|
1073
1107
|
todo = todo.concat((template.configs || []).map((query, index) => {
|
1074
1108
|
let pr
|
1075
|
-
if (index < startOfChanges) {
|
1109
|
+
if (index < startOfChanges || (!startOfChanges && index < previousResultss.length)) {
|
1076
1110
|
pr = previousResultss[index]
|
1077
1111
|
}
|
1078
1112
|
return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics }
|
1079
1113
|
}))
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1114
|
+
*/
|
1115
|
+
if (template.configs) {
|
1116
|
+
for (let configsIndex = 0; configsIndex < template.configs.length; ++configsIndex) {
|
1117
|
+
const query = template.configs[configsIndex]
|
1118
|
+
// account for things for example associations being added to the config while debugginer
|
1119
|
+
const pr = previousResultss.find((pr) => pr.query == query)
|
1120
|
+
todo.push({ property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics })
|
1121
|
+
}
|
1122
|
+
}
|
1123
|
+
todo = todo.concat((template.fragments || []).map((query, index) => {
|
1124
|
+
const pr = instance.fragments[index]
|
1125
|
+
return Object.assign({}, toProperties(query), { property: 'fragments', previousResults: pr, skipSemantics: false })
|
1126
|
+
}))
|
1127
|
+
todo = todo.concat((template.semantics || []).map((definition) => {
|
1128
|
+
return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true }
|
1129
|
+
}))
|
1130
|
+
await looper([...todo])
|
1083
1131
|
}
|
1084
1132
|
|
1085
1133
|
const checkTemplate = (template) => {
|
@@ -1577,13 +1625,18 @@ const knowledgeModuleImpl = async ({
|
|
1577
1625
|
console.log('**************************** ERRORS ************************')
|
1578
1626
|
for (const result of results) {
|
1579
1627
|
console.log('Utterance: ', result.utterance)
|
1580
|
-
|
1628
|
+
if (!result.hasError) {
|
1629
|
+
continue
|
1630
|
+
}
|
1631
|
+
const show = (label, expected, actual, { console_log=true } = {}) => {
|
1581
1632
|
if (JSON.stringify(expected) !== JSON.stringify(actual)) {
|
1582
|
-
if (
|
1583
|
-
|
1633
|
+
if (console_log) {
|
1634
|
+
if (!headerShown) {
|
1635
|
+
console.log(' Failure')
|
1636
|
+
}
|
1637
|
+
console.log(` expected ${label}`, expected)
|
1638
|
+
console.log(` actual ${label} `, actual)
|
1584
1639
|
}
|
1585
|
-
console.log(` expected ${label}`, expected)
|
1586
|
-
console.log(` actual ${label} `, actual)
|
1587
1640
|
newError = true
|
1588
1641
|
headerShown = true
|
1589
1642
|
if (args.vimdiff) {
|
@@ -1592,6 +1645,44 @@ const knowledgeModuleImpl = async ({
|
|
1592
1645
|
result.hasError = true
|
1593
1646
|
}
|
1594
1647
|
}
|
1648
|
+
if (!deepEqual(result.expected.summaries, result.actual.summaries)) {
|
1649
|
+
/*
|
1650
|
+
const suggestion = suggestAssociationsFix(result.expected.summaries, result.actual.summaries)
|
1651
|
+
let suggestedFix
|
1652
|
+
if (suggestion) {
|
1653
|
+
suggestedFix = suggestion
|
1654
|
+
console.log(`Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestedFix))}, choose: <indexOfMainElement> }`)
|
1655
|
+
}
|
1656
|
+
*/
|
1657
|
+
|
1658
|
+
const checkForFix = () => {
|
1659
|
+
for (let iDiff = 0; iDiff < result.expected.paraphrases.length; ++iDiff) {
|
1660
|
+
if (result.expected.paraphrases[iDiff] !== result.actual.paraphrases[iDiff]) {
|
1661
|
+
// const context = result.expected.contexts[iDiff]
|
1662
|
+
let lengths = 0
|
1663
|
+
// just check where the results differ since earlier summaries can be different but dont matter if the result is the same
|
1664
|
+
for (let iSummaries = 0; iSummaries < result.expected.summaries.length; ++iSummaries) {
|
1665
|
+
const summary = result.expected.summaries[iSummaries]
|
1666
|
+
lengths += summary.length
|
1667
|
+
if (lengths > iDiff) {
|
1668
|
+
const suggestion = suggestAssociationsFix(result.expected.summaries[iSummaries].summaries, result.actual.summaries[iSummaries].summaries)
|
1669
|
+
if (suggestion) {
|
1670
|
+
suggestedFix = suggestion
|
1671
|
+
// console.log(`Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestedFix))}, choose: <indexOfMainElement> },`)
|
1672
|
+
console.log(getSuggestionMessage(suggestedFix))
|
1673
|
+
return
|
1674
|
+
}
|
1675
|
+
}
|
1676
|
+
}
|
1677
|
+
}
|
1678
|
+
}
|
1679
|
+
}
|
1680
|
+
checkForFix()
|
1681
|
+
|
1682
|
+
// find the context where the different is
|
1683
|
+
// select the first diff that has a different operator in the range
|
1684
|
+
// show that
|
1685
|
+
}
|
1595
1686
|
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1596
1687
|
if (!args.testNoParenthesized) {
|
1597
1688
|
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
@@ -1755,7 +1846,6 @@ const knowledgeModuleImpl = async ({
|
|
1755
1846
|
const initConfig = async (config) => {
|
1756
1847
|
if (template) {
|
1757
1848
|
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
1758
|
-
debugger
|
1759
1849
|
config.needsRebuild(template.template, template.instance, { isModule: !isProcess })
|
1760
1850
|
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.`
|
1761
1851
|
throw new Error(error)
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -119,19 +119,35 @@ const debugConfigProps = (config) => {
|
|
119
119
|
}
|
120
120
|
const checkProps = [
|
121
121
|
{ property: 'priorities', check: (v) => debugPriority(v) },
|
122
|
-
{ property: '
|
123
|
-
|
122
|
+
{ property: 'associations', check: (v) => debugAssociation(v) },
|
123
|
+
// TODO implement debugWords
|
124
|
+
{ property: 'words', check: (v) => debugWords(v) },
|
124
125
|
{ property: 'hierarchy', check: (v) => debugHierarchy(v) },
|
125
126
|
{ property: 'operators', check: (v) => debugOperator(v) },
|
126
127
|
{ property: 'bridges', check: (v) => debugBridge(v) }
|
127
128
|
]
|
128
129
|
for (const { property, check } of checkProps) {
|
129
|
-
if (property == '
|
130
|
+
if (property == 'associations') {
|
131
|
+
if (config[property]) {
|
132
|
+
if (config[property].negative) {
|
133
|
+
for (const value of config[property].negative) {
|
134
|
+
check(value)
|
135
|
+
}
|
136
|
+
}
|
137
|
+
if (config[property].positive) {
|
138
|
+
for (const value of config[property].positive) {
|
139
|
+
check(value)
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
} else if (property == 'words') {
|
144
|
+
/*
|
130
145
|
if (config[property]) {
|
131
|
-
for (const value
|
146
|
+
for (const value of config[property].literals) {
|
132
147
|
check(value)
|
133
148
|
}
|
134
149
|
}
|
150
|
+
*/
|
135
151
|
} else if (config[property]) {
|
136
152
|
for (const value of config[property]) {
|
137
153
|
check(value)
|
@@ -173,6 +189,13 @@ const validConfigProps = (config) => {
|
|
173
189
|
'eqClasses'
|
174
190
|
]
|
175
191
|
helpers.validProps(valid, config, 'config')
|
192
|
+
|
193
|
+
// TODO add more type checks
|
194
|
+
if (config.associations) {
|
195
|
+
if (!config.associations.positive && !config.associations.negative) {
|
196
|
+
throw new Error(`Expected the 'associations' property to be a hash with 'positive' and or 'negative' properties`)
|
197
|
+
}
|
198
|
+
}
|
176
199
|
}
|
177
200
|
|
178
201
|
const setupInitializerFNArgs = (config, args) => {
|
@@ -261,7 +284,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
261
284
|
if (bridge.development && config.isModule) {
|
262
285
|
return
|
263
286
|
}
|
264
|
-
if (!bridge.bridge) {
|
287
|
+
if (false && !bridge.bridge) {
|
265
288
|
bridge.bridge = '{ ...next(operator) }'
|
266
289
|
}
|
267
290
|
if (!bridge.level) {
|
@@ -561,7 +584,7 @@ const normalizeConfig = (config) => {
|
|
561
584
|
if (!bridge.level) {
|
562
585
|
bridge.level = 0
|
563
586
|
}
|
564
|
-
if (!bridge.bridge) {
|
587
|
+
if (false && !bridge.bridge) {
|
565
588
|
bridge.bridge = '{ ...next(operator) }'
|
566
589
|
}
|
567
590
|
}
|
@@ -1172,7 +1195,7 @@ class Config {
|
|
1172
1195
|
delete bridge.evaluators
|
1173
1196
|
delete bridge.semantic
|
1174
1197
|
delete bridge.semantics
|
1175
|
-
if (!bridge.bridge) {
|
1198
|
+
if (false && !bridge.bridge) {
|
1176
1199
|
bridge.bridge = '{ ...next(operator) }'
|
1177
1200
|
}
|
1178
1201
|
return bridge
|
@@ -1305,7 +1328,7 @@ class Config {
|
|
1305
1328
|
// TODO fix beforeQuery
|
1306
1329
|
template = { fragments: [], configs: [], ...template }
|
1307
1330
|
template.fragments = template.fragments.concat(this.dynamicFragments)
|
1308
|
-
await rebuildTemplate({ config: this, target: this.name,
|
1331
|
+
await rebuildTemplate({ config: this, instance, target: this.name, startOfChanges: options.startOfChanges, beforeQuery: () => {}, template, ...options, previousResultss: options.previousResultss || instance.resultss })
|
1309
1332
|
} else {
|
1310
1333
|
// no change
|
1311
1334
|
// this.initInstances.push({ ...instance, name: config.name })
|
package/src/helpers.js
CHANGED
@@ -27,6 +27,28 @@ function where (goUp = 2) {
|
|
27
27
|
}
|
28
28
|
}
|
29
29
|
|
30
|
+
function suggestAssociationsFix(esummary, asummary) {
|
31
|
+
for (let isummary = 0; isummary < esummary.length; ++isummary) {
|
32
|
+
if (!deepEqual(esummary[isummary], asummary[isummary])) {
|
33
|
+
return esummary[isummary].operators
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return []
|
37
|
+
}
|
38
|
+
|
39
|
+
function suggestAssociationsFixFromSummaries(esummaries, asummaries) {
|
40
|
+
for (let isummaries = 0; isummaries < esummaries.length; ++isummaries) {
|
41
|
+
const esummary = esummaries[isummaries].summaries
|
42
|
+
const asummary = asummaries[isummaries].summaries
|
43
|
+
for (let isummary = 0; isummary < esummary.length; ++isummary) {
|
44
|
+
if (!deepEqual(esummary[isummary], asummary[isummary])) {
|
45
|
+
return esummary[isummary].operators
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return []
|
50
|
+
}
|
51
|
+
|
30
52
|
function w (func) {
|
31
53
|
func.where = where(3)
|
32
54
|
return func
|
@@ -437,5 +459,7 @@ module.exports = {
|
|
437
459
|
sortJson,
|
438
460
|
subPriority,
|
439
461
|
where,
|
440
|
-
w
|
462
|
+
w,
|
463
|
+
suggestAssociationsFix,
|
464
|
+
suggestAssociationsFixFromSummaries,
|
441
465
|
}
|