theprogrammablemind_4wp 7.5.8-beta.13 → 7.5.8-beta.15
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +12 -7
- package/package.json +1 -1
- package/src/config.js +127 -2
package/client.js
CHANGED
@@ -9,6 +9,7 @@ const _ = require('lodash')
|
|
9
9
|
const stringify = require('json-stable-stringify')
|
10
10
|
const Lines = require('./lines')
|
11
11
|
const flattens = require('./src/flatten')
|
12
|
+
const { config_toServer } = require('./src/config.js')
|
12
13
|
const { appendNoDups, InitCalls, updateQueries } = require('./src/helpers')
|
13
14
|
const runtime = require('./runtime')
|
14
15
|
const sortJson = runtime.sortJson
|
@@ -109,7 +110,7 @@ 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
|
}
|
@@ -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
|
}
|
@@ -551,6 +552,8 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
|
|
551
552
|
} else {
|
552
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)) {
|
@@ -586,7 +589,7 @@ const processInstance = (config, instance) => {
|
|
586
589
|
// config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
|
587
590
|
config.addInternal(instance.template.queries[i], { 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
|
@@ -1447,9 +1450,10 @@ const knowledgeModule = async ({
|
|
1447
1450
|
description: 'Entodicton knowledge module'
|
1448
1451
|
})
|
1449
1452
|
|
1450
|
-
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
|
1451
|
-
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
|
1452
|
-
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
|
1453
|
+
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]]\' })'
|
1454
|
+
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]]\' })'
|
1455
|
+
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]]\' })'
|
1456
|
+
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}\' })'
|
1453
1457
|
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\' })'
|
1454
1458
|
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]))\' })'
|
1455
1459
|
|
@@ -1484,6 +1488,7 @@ const knowledgeModule = async ({
|
|
1484
1488
|
parser.add_argument('-da', '--debugAssociation', { help: helpDebugAssociation })
|
1485
1489
|
parser.add_argument('-dh', '--debugHierarchy', { help: helpDebugHierarchy })
|
1486
1490
|
parser.add_argument('-dp', '--debugPriority', { help: helpDebugPriority })
|
1491
|
+
parser.add_argument('-dcp', '--debugContextualPriority', { help: helpDebugContextualPriority })
|
1487
1492
|
parser.add_argument('-db', '--debugBridge', { help: helpDebugBridge })
|
1488
1493
|
parser.add_argument('-do', '--debugOperator', { help: helpDebugOperator })
|
1489
1494
|
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -22,6 +22,83 @@ const indent = (string, indent) => {
|
|
22
22
|
return string.replace(/^/gm, ' '.repeat(indent));
|
23
23
|
}
|
24
24
|
|
25
|
+
const config_toServer = (config) => {
|
26
|
+
if (config.contextual_priorities) {
|
27
|
+
config.contextual_priorities = config.contextual_priorities.map((cp) => {
|
28
|
+
return [cp.context, cp.choose]
|
29
|
+
})
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
const contextual_priorities_toServer = (cp) => {
|
34
|
+
if (cp.context && cp.choose) {
|
35
|
+
return [cp.context, cp.choose]
|
36
|
+
}
|
37
|
+
return cp
|
38
|
+
}
|
39
|
+
|
40
|
+
const contextual_priorities_toClient = (cp) => {
|
41
|
+
if (cp.context && cp.choose) {
|
42
|
+
return cp
|
43
|
+
}
|
44
|
+
return { context: cp[0], choose: cp[1] }
|
45
|
+
}
|
46
|
+
|
47
|
+
const operatorKey_valid = (key) => {
|
48
|
+
if (
|
49
|
+
!_.isArray(key) ||
|
50
|
+
key.length != 2 ||
|
51
|
+
!_.isString(key[0]) ||
|
52
|
+
!_.isInteger(key[1]) ||
|
53
|
+
key[1] < 0
|
54
|
+
) {
|
55
|
+
|
56
|
+
let details = ''
|
57
|
+
if (!_.isArray(key)) {
|
58
|
+
details = "Expected an array."
|
59
|
+
} else if (key.length != 2) {
|
60
|
+
details = "Expected an array of length two."
|
61
|
+
} else if (!_.isString(key[0])) {
|
62
|
+
details = "Expected element zero to be a string that is an operator id."
|
63
|
+
} else if (!_.isInteger(key[1])) {
|
64
|
+
details = "Expected element one to be a number that is an operator level."
|
65
|
+
} else if (key[1] < 0) {
|
66
|
+
details = "Expected element one to be a number that is an operator level which is greater than zero."
|
67
|
+
}
|
68
|
+
throw new Error(`${JSON.stringify(key)} is not a valid operator key. Values are of the form [<operatorId>, <operatorLevel>]. ${details}`)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
const elist = (list, check, prefix) => {
|
73
|
+
for ([index, element] of list.entries()) {
|
74
|
+
try {
|
75
|
+
check(element)
|
76
|
+
} catch( e ) {
|
77
|
+
throw new Error(prefix(index, e))
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
const contextual_priorities_valid = (cps) => {
|
82
|
+
debugger
|
83
|
+
elist(cps, (cp) => contextual_priority_valid(cp), (index, e) => `contextual_priorities has an invalid contextual priority at position ${index}. ${e}`)
|
84
|
+
}
|
85
|
+
|
86
|
+
const contextual_priority_valid = (cp) => {
|
87
|
+
if (!cp.context) {
|
88
|
+
throw new Error(`The contextual priority ${JSON.stringify(cp)} is missing the "context" property. That is a list of the operator keys that are to be prioritized differently.`)
|
89
|
+
}
|
90
|
+
if (!_.isArray(cp.context)) {
|
91
|
+
throw new Error(`The contextual priority ${JSON.stringify(cp)} has an invalid "context" value. That is a list of the operator keys that are to be prioritized differently.`)
|
92
|
+
}
|
93
|
+
elist(cp.context, (element) => operatorKey_valid(element), (index, e) => `The contextual priority ${JSON.stringify(cp)} has an invalid operator key at position ${index}. ${e}`)
|
94
|
+
if (!cp.choose && cp.choose !== 0) {
|
95
|
+
throw new Error(`The contextual priority ${JSON.stringify(cp)} is missing the "choose" property. That is an index into the "context" property of the operator that is to be prioritized.`)
|
96
|
+
}
|
97
|
+
if (!_.isInteger(cp.choose) || cp.choose < 0 || cp.choose >= cp.context.length) {
|
98
|
+
throw new Error(`The contextual priority ${JSON.stringify(cp)} is missing the "choose" property. That is an index into the "context" property of the operator that is to be prioritized. Valid values are between 0 and ${cp.context.length-1}.`)
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
25
102
|
const handleBridgeProps = (config, bridge) => {
|
26
103
|
ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
|
27
104
|
() => {
|
@@ -171,6 +248,10 @@ if (runtime.process.env.DEBUG_PRIORITY) {
|
|
171
248
|
global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITY)
|
172
249
|
}
|
173
250
|
|
251
|
+
if (runtime.process.env.DEBUG_CONTEXTUAL_PRIORITY) {
|
252
|
+
global.entodictonDebugContextualPriority = JSON.parse(runtime.process.env.DEBUG_CONTEXTUAL_PRIORITY)
|
253
|
+
}
|
254
|
+
|
174
255
|
if (runtime.process.env.DEBUG_ASSOCIATION) {
|
175
256
|
global.entodictonDebugAssociation = JSON.parse(runtime.process.env.DEBUG_ASSOCIATION)
|
176
257
|
}
|
@@ -548,6 +629,7 @@ class Config {
|
|
548
629
|
},
|
549
630
|
eqClasses: [],
|
550
631
|
priorities: [], // Done
|
632
|
+
contextual_priorities: [],
|
551
633
|
version: '3',
|
552
634
|
debug: false,
|
553
635
|
associations: { // Done
|
@@ -586,6 +668,7 @@ class Config {
|
|
586
668
|
'namespaces',
|
587
669
|
'eqClasses',
|
588
670
|
'priorities',
|
671
|
+
'contextual_priorities',
|
589
672
|
'associations',
|
590
673
|
'words',
|
591
674
|
'floaters',
|
@@ -825,6 +908,22 @@ class Config {
|
|
825
908
|
this._delta.json.priorities.push({ action: 'add', priorities })
|
826
909
|
}
|
827
910
|
|
911
|
+
// [ operators: <list of [id, level]>, select: <index of prioritized operator> ]
|
912
|
+
addContextualPriority(contextual_priority) {
|
913
|
+
if (!this.config.contextual_priorities) {
|
914
|
+
this.config.contextual_priorities = []
|
915
|
+
}
|
916
|
+
if (global.entodictonDebugContextualPriority) {
|
917
|
+
if (helpers.safeEquals(entodictonDebugContextualPriority, contextual_priorities)) {
|
918
|
+
debugger; // debug hierarchy hit
|
919
|
+
}
|
920
|
+
}
|
921
|
+
contextual_priority_valid(contextual_priority)
|
922
|
+
const cpServer = contextual_priorities_toServer(contextual_priority)
|
923
|
+
this.config.contextual_priorities.push(cpServer)
|
924
|
+
this._delta.json.contextual_priorities.push({ action: 'add', contextual_priority: cpServer })
|
925
|
+
}
|
926
|
+
|
828
927
|
addHierarchy (child, parent) {
|
829
928
|
if (child && parent || !child || Array.isArray(child) || (typeof child == 'string' && !parent)) {
|
830
929
|
this.addHierarchyChildParent(child, parent)
|
@@ -1233,6 +1332,7 @@ class Config {
|
|
1233
1332
|
'operators',
|
1234
1333
|
'words',
|
1235
1334
|
'priorities',
|
1335
|
+
'contextual_priorities',
|
1236
1336
|
'associations',
|
1237
1337
|
'name',
|
1238
1338
|
'version',
|
@@ -1262,6 +1362,7 @@ class Config {
|
|
1262
1362
|
config.hierarchy = config.hierarchy || []
|
1263
1363
|
config.associations = config.associations || { negative: [], positive: [] }
|
1264
1364
|
config.priorities = config.priorities || []
|
1365
|
+
config.contextual_priorities = config.contextual_priorities || []
|
1265
1366
|
}
|
1266
1367
|
|
1267
1368
|
this.maxDepth = 20 // for generators and semantics
|
@@ -1315,6 +1416,10 @@ class Config {
|
|
1315
1416
|
}
|
1316
1417
|
}
|
1317
1418
|
|
1419
|
+
if (config && config.contextual_priorities) {
|
1420
|
+
contextual_priorities_valid(config.contextual_priorities)
|
1421
|
+
}
|
1422
|
+
|
1318
1423
|
normalizeConfig(config)
|
1319
1424
|
|
1320
1425
|
// set the default server so stuff just works
|
@@ -1385,7 +1490,10 @@ class Config {
|
|
1385
1490
|
}
|
1386
1491
|
|
1387
1492
|
delta () {
|
1388
|
-
return {
|
1493
|
+
return {
|
1494
|
+
cacheKey: this._delta.cacheKey,
|
1495
|
+
json: this._delta.json
|
1496
|
+
}
|
1389
1497
|
}
|
1390
1498
|
|
1391
1499
|
resetDelta (cacheKey) {
|
@@ -1397,6 +1505,7 @@ class Config {
|
|
1397
1505
|
bridges: [],
|
1398
1506
|
associations: [],
|
1399
1507
|
priorities: [],
|
1508
|
+
contextual_priorities: [],
|
1400
1509
|
hierarchy: [],
|
1401
1510
|
}
|
1402
1511
|
}
|
@@ -2051,6 +2160,7 @@ class Config {
|
|
2051
2160
|
bridges: this.config.bridges,
|
2052
2161
|
hierarchy: this.config.hierarchy,
|
2053
2162
|
priorities: this.config.priorities,
|
2163
|
+
contextual_priorities: this.config.contextual_priorities,
|
2054
2164
|
associations: this.config.associations,
|
2055
2165
|
words: this.config.words
|
2056
2166
|
}
|
@@ -2059,6 +2169,7 @@ class Config {
|
|
2059
2169
|
this.config.bridges = []
|
2060
2170
|
this.config.hierarchy = []
|
2061
2171
|
this.config.priorities = []
|
2172
|
+
this.config.contextual_priorities = []
|
2062
2173
|
this.config.associations = { positive: [], negative: [] }
|
2063
2174
|
this.config.words = {}
|
2064
2175
|
|
@@ -2279,6 +2390,18 @@ class Config {
|
|
2279
2390
|
config.priorities = priorities
|
2280
2391
|
}
|
2281
2392
|
|
2393
|
+
if (config.contextual_priorities) {
|
2394
|
+
let contextual_priorities = config.contextual_priorities
|
2395
|
+
contextual_priorities = contextual_priorities.map((cp) => {
|
2396
|
+
const [ context, choose ] = cp
|
2397
|
+
const contextPrime = context.map((id) => {
|
2398
|
+
return [toNS(id[0]), id[1]]
|
2399
|
+
})
|
2400
|
+
return [ contextPrime, choose ]
|
2401
|
+
})
|
2402
|
+
config.contextual_priorities = contextual_priorities
|
2403
|
+
}
|
2404
|
+
|
2282
2405
|
for (const bag of bags) {
|
2283
2406
|
if (config[bag]) {
|
2284
2407
|
config[bag] = config[bag].map((b) => {
|
@@ -2708,5 +2831,7 @@ class Config {
|
|
2708
2831
|
}
|
2709
2832
|
|
2710
2833
|
module.exports = {
|
2711
|
-
Config
|
2834
|
+
Config,
|
2835
|
+
config_toServer,
|
2836
|
+
operatorKey_valid,
|
2712
2837
|
}
|