theprogrammablemind 7.5.8-beta.3 → 7.5.8-beta.30
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 +121 -50
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/config.js +363 -179
- package/src/helpers.js +1 -1
- package/src/semantics.js +6 -1
package/src/config.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// lookup = (name) => returns <config>
|
2
2
|
const { Semantics, normalizeGenerator } = require('./semantics')
|
3
3
|
const { Generators } = require('./generators')
|
4
|
-
|
4
|
+
const { v4 : uuidv4 } = require('uuid');
|
5
5
|
const client = require('../client')
|
6
6
|
const DigraphInternal = require('./digraph_internal')
|
7
7
|
const helpers = require('./helpers')
|
@@ -22,6 +22,142 @@ 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 validConfigProps = (config) => {
|
34
|
+
const valid = [
|
35
|
+
'hierarchy',
|
36
|
+
'objects',
|
37
|
+
'bridges',
|
38
|
+
'operators',
|
39
|
+
'words',
|
40
|
+
'priorities',
|
41
|
+
'contextual_priorities',
|
42
|
+
'associations',
|
43
|
+
'name',
|
44
|
+
'version',
|
45
|
+
'generators',
|
46
|
+
'semantics',
|
47
|
+
'where',
|
48
|
+
'floaters',
|
49
|
+
'debug',
|
50
|
+
|
51
|
+
// TODO Fix these from the test app
|
52
|
+
'implicits',
|
53
|
+
'convolution',
|
54
|
+
'expected_generated',
|
55
|
+
'expected_results',
|
56
|
+
'skipSemantics',
|
57
|
+
'description',
|
58
|
+
'contexts',
|
59
|
+
'utterances',
|
60
|
+
'flatten',
|
61
|
+
|
62
|
+
'namespaces',
|
63
|
+
'eqClasses',
|
64
|
+
]
|
65
|
+
helpers.validProps(valid, config, 'config')
|
66
|
+
}
|
67
|
+
|
68
|
+
const setupInitializerFNArgs = (config, args) => {
|
69
|
+
const aw = (word, def) => config.addWord(word, def, args.uuid)
|
70
|
+
const ag = (generator) => config.addGenerator(generator, args.uuid, config.name)
|
71
|
+
const km = (name) => config.getConfig(name)
|
72
|
+
const apis = (name) => config.getConfig(name).api
|
73
|
+
|
74
|
+
return {
|
75
|
+
...args,
|
76
|
+
addWord: aw,
|
77
|
+
addGenerator: ag,
|
78
|
+
config: config.getPseudoConfig(args.uuid, args.currentConfig),
|
79
|
+
km,
|
80
|
+
baseConfig: config,
|
81
|
+
apis,
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
const contextual_priorities_toServer = (cp) => {
|
86
|
+
if (cp.context && cp.choose) {
|
87
|
+
return [cp.context, cp.choose]
|
88
|
+
}
|
89
|
+
return cp
|
90
|
+
}
|
91
|
+
|
92
|
+
const contextual_priorities_toClient = (cp) => {
|
93
|
+
if (cp.context && cp.choose) {
|
94
|
+
return cp
|
95
|
+
}
|
96
|
+
return { context: cp[0], choose: cp[1] }
|
97
|
+
}
|
98
|
+
|
99
|
+
const operatorKey_valid = (key) => {
|
100
|
+
if (
|
101
|
+
!_.isArray(key) ||
|
102
|
+
key.length != 2 ||
|
103
|
+
!_.isString(key[0]) ||
|
104
|
+
!_.isInteger(key[1]) ||
|
105
|
+
key[1] < 0
|
106
|
+
) {
|
107
|
+
|
108
|
+
let details = ''
|
109
|
+
if (!_.isArray(key)) {
|
110
|
+
details = "Expected an array."
|
111
|
+
} else if (key.length != 2) {
|
112
|
+
details = "Expected an array of length two."
|
113
|
+
} else if (!_.isString(key[0])) {
|
114
|
+
details = "Expected element zero to be a string that is an operator id."
|
115
|
+
} else if (!_.isInteger(key[1])) {
|
116
|
+
details = "Expected element one to be a number that is an operator level."
|
117
|
+
} else if (key[1] < 0) {
|
118
|
+
details = "Expected element one to be a number that is an operator level which is greater than zero."
|
119
|
+
}
|
120
|
+
throw new Error(`${JSON.stringify(key)} is not a valid operator key. Values are of the form [<operatorId>, <operatorLevel>]. ${details}`)
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
const elist = (list, check, prefix) => {
|
125
|
+
for ([index, element] of list.entries()) {
|
126
|
+
try {
|
127
|
+
check(element)
|
128
|
+
} catch( e ) {
|
129
|
+
throw new Error(prefix(index, e))
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
const contextual_priorities_valid = (cps) => {
|
134
|
+
elist(cps, (cp) => contextual_priority_valid(cp), (index, e) => `contextual_priorities has an invalid contextual priority at position ${index}. ${e}`)
|
135
|
+
}
|
136
|
+
|
137
|
+
const contextual_priority_valid = (cp) => {
|
138
|
+
if (!cp.context) {
|
139
|
+
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.`)
|
140
|
+
}
|
141
|
+
if (!_.isArray(cp.context)) {
|
142
|
+
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.`)
|
143
|
+
}
|
144
|
+
elist(cp.context, (element) => operatorKey_valid(element), (index, e) => `The contextual priority ${JSON.stringify(cp)} has an invalid operator key at position ${index}. ${e}`)
|
145
|
+
if (!_.isArray(cp.choose)) {
|
146
|
+
throw new Error(`The contextual priority ${JSON.stringify(cp)} has an invalid "choose" value. The value should be a list of the operators in the context to consider for prioritization.`)
|
147
|
+
}
|
148
|
+
elist(cp.choose,
|
149
|
+
(element) => {
|
150
|
+
if (!element && element !== 0) {
|
151
|
+
throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization.`)
|
152
|
+
}
|
153
|
+
if (!_.isInteger(element) || element < 0 || element >= cp.context.length) {
|
154
|
+
throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization. Valid values are between 0 and ${cp.context.length-1}.`)
|
155
|
+
}
|
156
|
+
},
|
157
|
+
(index, e) => `The choose property in the contextual priority ${JSON.stringify(cp)} has an invalid index at position ${index}. ${e}`
|
158
|
+
)
|
159
|
+
}
|
160
|
+
|
25
161
|
const handleBridgeProps = (config, bridge) => {
|
26
162
|
ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
|
27
163
|
() => {
|
@@ -68,7 +204,7 @@ const handleBridgeProps = (config, bridge) => {
|
|
68
204
|
config.addWordInternal(def, {"id": bridge.id, "initial": `{ value: "${def}"}` })
|
69
205
|
} else {
|
70
206
|
const word = def.word
|
71
|
-
def = { initial: JSON.stringify(def), id: bridge.id, word
|
207
|
+
def = { initial: JSON.stringify(def), id: bridge.id, word }
|
72
208
|
config.addWordInternal(word, def)
|
73
209
|
}
|
74
210
|
}
|
@@ -148,7 +284,7 @@ const handleBridgeProps = (config, bridge) => {
|
|
148
284
|
const handleCalculatedProps = (baseConfig, moreConfig) => {
|
149
285
|
for (let bridge of moreConfig.bridges) {
|
150
286
|
const valid = [ 'after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
151
|
-
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where' ]
|
287
|
+
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid' ]
|
152
288
|
helpers.validProps(valid, bridge, 'bridge')
|
153
289
|
handleBridgeProps(baseConfig, bridge)
|
154
290
|
}
|
@@ -171,6 +307,10 @@ if (runtime.process.env.DEBUG_PRIORITY) {
|
|
171
307
|
global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITY)
|
172
308
|
}
|
173
309
|
|
310
|
+
if (runtime.process.env.DEBUG_CONTEXTUAL_PRIORITY) {
|
311
|
+
global.entodictonDebugContextualPriority = JSON.parse(runtime.process.env.DEBUG_CONTEXTUAL_PRIORITY)
|
312
|
+
}
|
313
|
+
|
174
314
|
if (runtime.process.env.DEBUG_ASSOCIATION) {
|
175
315
|
global.entodictonDebugAssociation = JSON.parse(runtime.process.env.DEBUG_ASSOCIATION)
|
176
316
|
}
|
@@ -252,6 +392,14 @@ const normalizeConfig = (config) => {
|
|
252
392
|
}
|
253
393
|
}
|
254
394
|
}
|
395
|
+
|
396
|
+
if (config.semantics) {
|
397
|
+
for (let semantic of config.semantics) {
|
398
|
+
if (semantic.oneShot) {
|
399
|
+
semantic.id = uuid()
|
400
|
+
}
|
401
|
+
}
|
402
|
+
}
|
255
403
|
}
|
256
404
|
}
|
257
405
|
|
@@ -459,8 +607,8 @@ const multiApiImpl = (initializer) => {
|
|
459
607
|
initializer(config, api)
|
460
608
|
const name = api.getName()
|
461
609
|
multiApi.apis[name] = api
|
462
|
-
api.objects = config.get('objects')
|
463
|
-
api.config = () => config
|
610
|
+
// api.objects = config.get('objects')
|
611
|
+
// api.config = () => config
|
464
612
|
multiApi.current = name
|
465
613
|
},
|
466
614
|
|
@@ -471,11 +619,13 @@ const multiApiImpl = (initializer) => {
|
|
471
619
|
}
|
472
620
|
},
|
473
621
|
|
622
|
+
/*
|
474
623
|
set objects (value) {
|
475
624
|
for (const key in Object.keys(this.apis)) {
|
476
625
|
this.apis[key].objects = value
|
477
626
|
}
|
478
627
|
},
|
628
|
+
*/
|
479
629
|
|
480
630
|
// "product1": apiInstance(testData1),
|
481
631
|
apis: {
|
@@ -489,6 +639,46 @@ const multiApiImpl = (initializer) => {
|
|
489
639
|
|
490
640
|
class Config {
|
491
641
|
|
642
|
+
toServer (config) {
|
643
|
+
return config_toServer(config)
|
644
|
+
}
|
645
|
+
|
646
|
+
base () {
|
647
|
+
const base = new Config()
|
648
|
+
for (let km of this.configs.reverse()) {
|
649
|
+
if (km.isSelf) {
|
650
|
+
continue
|
651
|
+
}
|
652
|
+
base.add(km.config)
|
653
|
+
}
|
654
|
+
return base
|
655
|
+
}
|
656
|
+
|
657
|
+
getPseudoConfig (uuid, config) {
|
658
|
+
return {
|
659
|
+
description: "this is a pseudo config that has limited functionality due to being available in the initializer function context",
|
660
|
+
addAssociation: (...args) => this.addAssociation(...args),
|
661
|
+
addAssociations: (...args) => this.addAssociations(...args),
|
662
|
+
addBridge: (...args) => this.addBridge(...args, uuid),
|
663
|
+
addContextualPriority: (...args) => this.addContextualPriority(...args),
|
664
|
+
addGenerator: (...args) => this.addGenerator(...args, uuid, config.name),
|
665
|
+
addHierarchy: (...args) => this.addHierarchy(...args),
|
666
|
+
addOperator: (...args) => this.addOperator(...args, uuid),
|
667
|
+
addPriorities: (...args) => this.addPriorities(...args),
|
668
|
+
addSemantic: (...args) => this.addSemantic(...args, uuid, config.name),
|
669
|
+
removeSemantic: (...args) => this.removeSemantic(...args, uuid, config.name),
|
670
|
+
addWord: (...args) => this.addWord(...args, uuid),
|
671
|
+
|
672
|
+
getHierarchy: (...args) => this.config.hierarchy,
|
673
|
+
getBridges: (...args) => this.config.bridges,
|
674
|
+
|
675
|
+
addArgs: (...args) => this.addArgs(...args),
|
676
|
+
getBridge: (...args) => this.getBridge(...args),
|
677
|
+
fragment: (...args) => this.fragment(...args),
|
678
|
+
addAPI: (...args) => this.addAPI(...args),
|
679
|
+
}
|
680
|
+
}
|
681
|
+
|
492
682
|
inDevelopmentMode (call) {
|
493
683
|
config.developmentModeOn += 1
|
494
684
|
try {
|
@@ -527,9 +717,6 @@ class Config {
|
|
527
717
|
}
|
528
718
|
|
529
719
|
setTestConfig(testConfig) {
|
530
|
-
if (this.name == 'ui') {
|
531
|
-
console.log('ui setting testConfig')
|
532
|
-
}
|
533
720
|
this.testConfig = testConfig
|
534
721
|
}
|
535
722
|
|
@@ -548,6 +735,7 @@ class Config {
|
|
548
735
|
},
|
549
736
|
eqClasses: [],
|
550
737
|
priorities: [], // Done
|
738
|
+
contextual_priorities: [],
|
551
739
|
version: '3',
|
552
740
|
debug: false,
|
553
741
|
associations: { // Done
|
@@ -586,6 +774,7 @@ class Config {
|
|
586
774
|
'namespaces',
|
587
775
|
'eqClasses',
|
588
776
|
'priorities',
|
777
|
+
'contextual_priorities',
|
589
778
|
'associations',
|
590
779
|
'words',
|
591
780
|
'floaters',
|
@@ -739,6 +928,11 @@ class Config {
|
|
739
928
|
}
|
740
929
|
}
|
741
930
|
|
931
|
+
toData (data) {
|
932
|
+
Object.assign(data, this.config)
|
933
|
+
config_toServer(data)
|
934
|
+
}
|
935
|
+
|
742
936
|
load (template, instance, options = { rebuild: false } ) {
|
743
937
|
this.validifyTemplate(template)
|
744
938
|
instance.template = template
|
@@ -750,7 +944,7 @@ class Config {
|
|
750
944
|
// TODO fix beforeQuery
|
751
945
|
template = { fragments: [], queries: [], ...template }
|
752
946
|
template.fragments = template.fragments.concat(this.dynamicFragments)
|
753
|
-
client.
|
947
|
+
client.rebuildTemplate({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
|
754
948
|
} else {
|
755
949
|
// no change
|
756
950
|
// this.initInstances.push({ ...instance, name: config.name })
|
@@ -825,6 +1019,22 @@ class Config {
|
|
825
1019
|
this._delta.json.priorities.push({ action: 'add', priorities })
|
826
1020
|
}
|
827
1021
|
|
1022
|
+
// [ operators: <list of [id, level]>, select: <index of prioritized operator> ]
|
1023
|
+
addContextualPriority(contextual_priority) {
|
1024
|
+
if (!this.config.contextual_priorities) {
|
1025
|
+
this.config.contextual_priorities = []
|
1026
|
+
}
|
1027
|
+
if (global.entodictonDebugContextualPriority) {
|
1028
|
+
if (helpers.safeEquals(entodictonDebugContextualPriority, contextual_priorities)) {
|
1029
|
+
debugger; // debug hierarchy hit
|
1030
|
+
}
|
1031
|
+
}
|
1032
|
+
contextual_priority_valid(contextual_priority)
|
1033
|
+
this.config.contextual_priorities.push(contextual_priority)
|
1034
|
+
const cpServer = contextual_priorities_toServer(contextual_priority)
|
1035
|
+
this._delta.json.contextual_priorities.push({ action: 'add', contextual_priority: cpServer })
|
1036
|
+
}
|
1037
|
+
|
828
1038
|
addHierarchy (child, parent) {
|
829
1039
|
if (child && parent || !child || Array.isArray(child) || (typeof child == 'string' && !parent)) {
|
830
1040
|
this.addHierarchyChildParent(child, parent)
|
@@ -881,15 +1091,19 @@ class Config {
|
|
881
1091
|
}
|
882
1092
|
|
883
1093
|
getBridge (id, level) {
|
884
|
-
|
1094
|
+
if (level) {
|
1095
|
+
return this.config.bridges.find( (bridge) => bridge.id == id && bridge.level == level )
|
1096
|
+
} else {
|
1097
|
+
return this.config.bridges.find( (bridge) => bridge.id == id)
|
1098
|
+
}
|
885
1099
|
}
|
886
1100
|
|
887
|
-
addBridge (bridge) {
|
1101
|
+
addBridge (bridge, uuid) {
|
888
1102
|
if (!this.config.bridges) {
|
889
1103
|
this.config.bridges = []
|
890
1104
|
}
|
891
1105
|
const bridges = this.config.bridges
|
892
|
-
const def = Object.assign({}, bridge, { uuid: this._uuid })
|
1106
|
+
const def = Object.assign({}, bridge, { uuid: uuid || this._uuid })
|
893
1107
|
|
894
1108
|
if (global.entodictonDebugBridge) {
|
895
1109
|
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
@@ -911,12 +1125,7 @@ class Config {
|
|
911
1125
|
this._delta.json.bridges.push({ action: 'add', bridge: def })
|
912
1126
|
}
|
913
1127
|
|
914
|
-
addGenerator (
|
915
|
-
let generator = match
|
916
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
917
|
-
generator = { match, apply }
|
918
|
-
}
|
919
|
-
|
1128
|
+
addGenerator (generator, uuid, name) {
|
920
1129
|
if (!(typeof generator.match === 'function')) {
|
921
1130
|
throw new Error('addGenerator: Expected matcher to be a function')
|
922
1131
|
}
|
@@ -933,20 +1142,16 @@ class Config {
|
|
933
1142
|
}
|
934
1143
|
|
935
1144
|
const generators = this.config.generators
|
936
|
-
Object.assign(generator, { uuid: this._uuid, km: this.name, index: generators.length })
|
1145
|
+
Object.assign(generator, { uuid: uuid || this._uuid, km: name || this.name, index: generators.length })
|
937
1146
|
// used to be unshift
|
938
1147
|
generators.unshift(generator)
|
939
1148
|
}
|
940
1149
|
|
941
|
-
addSemantic (
|
942
|
-
let semantic = match
|
943
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
944
|
-
semantic = { match, apply }
|
945
|
-
}
|
946
|
-
|
1150
|
+
addSemantic (semantic, uuid, name) {
|
947
1151
|
if (!(typeof semantic.match === 'function')) {
|
948
1152
|
throw new Error('addSemantic: Expected match to be a function')
|
949
1153
|
}
|
1154
|
+
|
950
1155
|
if (!(typeof semantic.apply === 'function')) {
|
951
1156
|
throw new Error('addSemantic: Expected apply to be a function')
|
952
1157
|
}
|
@@ -960,11 +1165,18 @@ class Config {
|
|
960
1165
|
}
|
961
1166
|
|
962
1167
|
const semantics = this.config.semantics
|
963
|
-
Object.assign(semantic, { uuid: this._uuid, km: this.name, index: semantics.length })
|
1168
|
+
Object.assign(semantic, { uuid: uuid || semantic.uuid || this._uuid, km: name || this.name, index: semantics.length, id: semantic.id || uuidv4() })
|
964
1169
|
semantics.unshift(semantic)
|
965
1170
|
}
|
966
1171
|
|
967
|
-
|
1172
|
+
removeSemantic(deleteSemantic) {
|
1173
|
+
const index = this.config.semantics.findIndex( (semantic) => semantic.id === deleteSemantic.id )
|
1174
|
+
if (index >= 0) {
|
1175
|
+
this.config.semantics.splice(index, 1)
|
1176
|
+
}
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
addOperator (objectOrPattern, uuid) {
|
968
1180
|
if (!this.config.operators) {
|
969
1181
|
this.config.operators = []
|
970
1182
|
}
|
@@ -973,9 +1185,9 @@ class Config {
|
|
973
1185
|
|
974
1186
|
let operator;
|
975
1187
|
if (typeof objectOrPattern === 'string') {
|
976
|
-
operator = { pattern: objectOrPattern, uuid: this._uuid }
|
1188
|
+
operator = { pattern: objectOrPattern, uuid: uuid || this._uuid }
|
977
1189
|
} else {
|
978
|
-
operator = Object.assign({}, objectOrPattern, { uuid: this._uuid })
|
1190
|
+
operator = Object.assign({}, objectOrPattern, { uuid: uuid || this._uuid })
|
979
1191
|
}
|
980
1192
|
|
981
1193
|
if (global.entodictonDebugOperator) {
|
@@ -996,16 +1208,16 @@ class Config {
|
|
996
1208
|
this._delta.json.operators.push({ action: 'add', operator })
|
997
1209
|
}
|
998
1210
|
|
999
|
-
addWord (word, def) {
|
1000
|
-
this.addWordInternal(word, def)
|
1211
|
+
addWord (word, def, uuid) {
|
1212
|
+
this.addWordInternal(word, def, uuid)
|
1001
1213
|
}
|
1002
1214
|
|
1003
|
-
addWordInternal (word, def) {
|
1215
|
+
addWordInternal (word, def, uuid) {
|
1004
1216
|
if (!this.config.words) {
|
1005
1217
|
this.config.words = {}
|
1006
1218
|
}
|
1007
1219
|
const words = this.config.words
|
1008
|
-
def = Object.assign({}, def, { uuid: this._uuid })
|
1220
|
+
def = Object.assign({}, def, { uuid: uuid || this._uuid })
|
1009
1221
|
if (words[word]) {
|
1010
1222
|
if (!words[word].some((e) => helpers.safeEquals(e, def))) {
|
1011
1223
|
words[word].unshift(def)
|
@@ -1226,33 +1438,7 @@ class Config {
|
|
1226
1438
|
}
|
1227
1439
|
|
1228
1440
|
if (config) {
|
1229
|
-
|
1230
|
-
'hierarchy',
|
1231
|
-
'objects',
|
1232
|
-
'bridges',
|
1233
|
-
'operators',
|
1234
|
-
'words',
|
1235
|
-
'priorities',
|
1236
|
-
'associations',
|
1237
|
-
'name',
|
1238
|
-
'version',
|
1239
|
-
'generators',
|
1240
|
-
'semantics',
|
1241
|
-
'floaters',
|
1242
|
-
'debug',
|
1243
|
-
|
1244
|
-
// TODO Fix these from the test app
|
1245
|
-
'implicits',
|
1246
|
-
'convolution',
|
1247
|
-
'expected_generated',
|
1248
|
-
'expected_results',
|
1249
|
-
'skipSemantics',
|
1250
|
-
'description',
|
1251
|
-
'contexts',
|
1252
|
-
'utterances',
|
1253
|
-
'flatten',
|
1254
|
-
]
|
1255
|
-
helpers.validProps(valid, config, 'config')
|
1441
|
+
validConfigProps(config)
|
1256
1442
|
|
1257
1443
|
config.operators = config.operators || []
|
1258
1444
|
config.bridges = config.bridges || []
|
@@ -1262,6 +1448,7 @@ class Config {
|
|
1262
1448
|
config.hierarchy = config.hierarchy || []
|
1263
1449
|
config.associations = config.associations || { negative: [], positive: [] }
|
1264
1450
|
config.priorities = config.priorities || []
|
1451
|
+
config.contextual_priorities = config.contextual_priorities || []
|
1265
1452
|
}
|
1266
1453
|
|
1267
1454
|
this.maxDepth = 20 // for generators and semantics
|
@@ -1315,6 +1502,10 @@ class Config {
|
|
1315
1502
|
}
|
1316
1503
|
}
|
1317
1504
|
|
1505
|
+
if (config && config.contextual_priorities) {
|
1506
|
+
contextual_priorities_valid(config.contextual_priorities)
|
1507
|
+
}
|
1508
|
+
|
1318
1509
|
normalizeConfig(config)
|
1319
1510
|
|
1320
1511
|
// set the default server so stuff just works
|
@@ -1330,7 +1521,6 @@ class Config {
|
|
1330
1521
|
if (config) {
|
1331
1522
|
this.name = config.name
|
1332
1523
|
}
|
1333
|
-
this.motivations = []
|
1334
1524
|
this.loadOrder = new DigraphInternal()
|
1335
1525
|
this.wasInitialized = false
|
1336
1526
|
this.configs = []
|
@@ -1385,7 +1575,10 @@ class Config {
|
|
1385
1575
|
}
|
1386
1576
|
|
1387
1577
|
delta () {
|
1388
|
-
return {
|
1578
|
+
return {
|
1579
|
+
cacheKey: this._delta.cacheKey,
|
1580
|
+
json: this._delta.json
|
1581
|
+
}
|
1389
1582
|
}
|
1390
1583
|
|
1391
1584
|
resetDelta (cacheKey) {
|
@@ -1397,6 +1590,7 @@ class Config {
|
|
1397
1590
|
bridges: [],
|
1398
1591
|
associations: [],
|
1399
1592
|
priorities: [],
|
1593
|
+
contextual_priorities: [],
|
1400
1594
|
hierarchy: [],
|
1401
1595
|
}
|
1402
1596
|
}
|
@@ -1431,11 +1625,13 @@ class Config {
|
|
1431
1625
|
this._api.add(this, this._api, value)
|
1432
1626
|
} else {
|
1433
1627
|
this._api = _.cloneDeep(value)
|
1628
|
+
/*
|
1434
1629
|
if (this._api) {
|
1435
|
-
this._api.objects = this.config.objects
|
1436
|
-
this._api.config = () => this
|
1437
|
-
this._api.uuid = this._uuid
|
1630
|
+
// this._api.objects = this.config.objects
|
1631
|
+
// this._api.config = () => this
|
1632
|
+
// this._api.uuid = this._uuid
|
1438
1633
|
}
|
1634
|
+
*/
|
1439
1635
|
this.rebuild()
|
1440
1636
|
}
|
1441
1637
|
}
|
@@ -1478,40 +1674,6 @@ class Config {
|
|
1478
1674
|
// this.valid() init was not run because the kms are not all setup yet
|
1479
1675
|
}
|
1480
1676
|
|
1481
|
-
// motivation === { match, apply, uuid }
|
1482
|
-
addMotivation (motivation) {
|
1483
|
-
if (!motivation.uuid) {
|
1484
|
-
motivation.uuid = this.uuid
|
1485
|
-
}
|
1486
|
-
this.motivations.push(motivation)
|
1487
|
-
}
|
1488
|
-
|
1489
|
-
resetMotivations () {
|
1490
|
-
this.motivations = []
|
1491
|
-
}
|
1492
|
-
|
1493
|
-
doMotivations (args, context) {
|
1494
|
-
args = Object.assign({}, args, { context, api: this.api })
|
1495
|
-
// console.log('src/config doMotivations this.uuid', this.uuid)
|
1496
|
-
// args.objects = args.getObjects(this.uuid)
|
1497
|
-
const motivations = this.motivations
|
1498
|
-
this.motivations = []
|
1499
|
-
let done = false
|
1500
|
-
for (const motivation of motivations) {
|
1501
|
-
args.objects = args.getObjects(motivation.uuid)
|
1502
|
-
if (!done && motivation.match(args)) {
|
1503
|
-
motivation.apply(args)
|
1504
|
-
if (args.context.controlKeepMotivation || motivation.repeat) {
|
1505
|
-
this.motivations.push(motivation)
|
1506
|
-
}
|
1507
|
-
done = true
|
1508
|
-
} else {
|
1509
|
-
this.motivations.push(motivation)
|
1510
|
-
}
|
1511
|
-
}
|
1512
|
-
return done
|
1513
|
-
}
|
1514
|
-
|
1515
1677
|
// TODO add more details
|
1516
1678
|
equal(config) {
|
1517
1679
|
if (JSON.stringify(this.config) != JSON.stringify(config.config)) {
|
@@ -1525,6 +1687,9 @@ class Config {
|
|
1525
1687
|
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1526
1688
|
}
|
1527
1689
|
|
1690
|
+
copy (options = { callInitializers: true }) {
|
1691
|
+
}
|
1692
|
+
|
1528
1693
|
copy (options = { callInitializers: true }) {
|
1529
1694
|
this.valid()
|
1530
1695
|
const cp = new Config()
|
@@ -1534,15 +1699,14 @@ class Config {
|
|
1534
1699
|
cp.transitoryMode = this.transitoryMode
|
1535
1700
|
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
1536
1701
|
cp._uuid = cp.configs[0]._uuid
|
1702
|
+
// update uuid here set the uuid in the objects and add error checking
|
1537
1703
|
cp.initializerFn = this.initializerFn
|
1538
|
-
cp.initAfterApi = this.initAfterApi
|
1539
1704
|
cp._api = _.cloneDeep(this._api)
|
1540
1705
|
cp._namespace = this._namespace
|
1541
1706
|
cp._eqClasses = this._eqClasses
|
1542
1707
|
cp.name = this.name
|
1543
1708
|
cp.description = this.description
|
1544
1709
|
cp.tests = this.tests
|
1545
|
-
cp.motivations = [...this.motivations]
|
1546
1710
|
cp.isModule = this.isModule
|
1547
1711
|
cp.loadedForTesting = this.loadedForTesting
|
1548
1712
|
cp.initInstances = this.initInstances.slice()
|
@@ -1567,25 +1731,38 @@ class Config {
|
|
1567
1731
|
}
|
1568
1732
|
cp.mapUUIDs(map)
|
1569
1733
|
|
1734
|
+
if (cp._uuid == 'concept2') {
|
1735
|
+
// debugger
|
1736
|
+
}
|
1570
1737
|
if (options.callInitializers) {
|
1571
1738
|
cp.rebuild(options)
|
1572
|
-
}
|
1573
|
-
|
1574
|
-
|
1575
|
-
cp._api
|
1576
|
-
|
1577
|
-
|
1739
|
+
} else {
|
1740
|
+
// this mess is for duplicate into a KM after resetToOne was called
|
1741
|
+
/*
|
1742
|
+
if (cp._api) {
|
1743
|
+
// cp._api.objects = cp.config.objects
|
1744
|
+
// cp._api.config = () => (cp instanceof Config) ? cp : cp.config
|
1745
|
+
// cp._api.uuid = cp._uuid
|
1746
|
+
}
|
1747
|
+
*/
|
1578
1748
|
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1749
|
+
if (!cp.config.objects) {
|
1750
|
+
cp.config.objects = { namespaced: {} }
|
1751
|
+
} else if (!cp.config.objects.namespaced) {
|
1752
|
+
cp.config.objects.namespaced = {}
|
1753
|
+
}
|
1754
|
+
cp.configs.forEach((km) => {
|
1755
|
+
// const namespace = km.namespace
|
1756
|
+
cp.config.objects.namespaced[km._uuid] = {}
|
1757
|
+
})
|
1758
|
+
/*
|
1759
|
+
if (cp._uuid == 'concept2') {
|
1760
|
+
if (!cp.api.objects.defaultTypesForHierarchy) {
|
1761
|
+
debugger
|
1762
|
+
}
|
1763
|
+
}
|
1764
|
+
*/
|
1583
1765
|
}
|
1584
|
-
cp.configs.forEach((km) => {
|
1585
|
-
// const namespace = km.namespace
|
1586
|
-
cp.config.objects.namespaced[km._uuid] = {}
|
1587
|
-
})
|
1588
|
-
|
1589
1766
|
cp.valid()
|
1590
1767
|
return cp
|
1591
1768
|
}
|
@@ -1685,25 +1862,24 @@ class Config {
|
|
1685
1862
|
}
|
1686
1863
|
*/
|
1687
1864
|
const objects = {}
|
1688
|
-
const km = (name) => this.getConfig(name)
|
1689
1865
|
if (config instanceof Config) {
|
1690
|
-
// const aw = addWord(this.config, config.uuid)
|
1691
|
-
const aw = (word, def) => this.addWord(word, def)
|
1692
1866
|
this.get('objects').namespaced[config._uuid] = objects
|
1867
|
+
/*
|
1693
1868
|
if (config._api) {
|
1694
|
-
config._api.objects = objects
|
1695
|
-
config._api.config = () => this
|
1869
|
+
// config._api.objects = objects
|
1870
|
+
// config._api.config = () => this
|
1696
1871
|
}
|
1697
|
-
|
1872
|
+
*/
|
1873
|
+
config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
|
1698
1874
|
} else {
|
1699
|
-
// const aw = addWord(this.config, this.uuid)
|
1700
|
-
const aw = (word, def) => this.addWord(word, def)
|
1701
1875
|
this.get('objects').namespaced[this._uuid] = objects
|
1876
|
+
/*
|
1702
1877
|
if (config._api) {
|
1703
|
-
config._api.objects = objects
|
1704
|
-
config._api.config = () => this
|
1878
|
+
// config._api.objects = objects
|
1879
|
+
// config._api.config = () => this
|
1705
1880
|
}
|
1706
|
-
|
1881
|
+
*/
|
1882
|
+
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
|
1707
1883
|
}
|
1708
1884
|
})
|
1709
1885
|
this.instances.forEach((instance) => client.processInstance(this, instance))
|
@@ -1711,12 +1887,8 @@ class Config {
|
|
1711
1887
|
|
1712
1888
|
initialize ({ force = true } = {}) {
|
1713
1889
|
if (force || !this.wasInitialized) {
|
1714
|
-
// const aw = addWord(this.config, this.uuid)
|
1715
|
-
const aw = (word, def) => this.addWord(word, def)
|
1716
|
-
const km = (name) => this.getConfig(name)
|
1717
|
-
// this.initializerFn({ addWord: aw, km, config: this, baseConfig: this, currentConfig: this, objects: this.get('objects'), uuid: this._uuid, namespace: '', api: this.api })
|
1718
1890
|
const objects = this.config.objects.namespaced[this._uuid]
|
1719
|
-
this.initializerFn(
|
1891
|
+
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, uuid: this._uuid, namespace: '' }))
|
1720
1892
|
this.wasInitialized = true
|
1721
1893
|
}
|
1722
1894
|
}
|
@@ -1724,29 +1896,22 @@ class Config {
|
|
1724
1896
|
initializer (fn, options = {}) {
|
1725
1897
|
if (options) {
|
1726
1898
|
for (let option of Object.keys(options)) {
|
1727
|
-
const validOptions = [
|
1728
|
-
if (!
|
1899
|
+
const validOptions = []
|
1900
|
+
if (!validOptions.includes(option)) {
|
1729
1901
|
throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
|
1730
1902
|
}
|
1731
1903
|
}
|
1732
1904
|
}
|
1733
|
-
const { initAfterApi = false } = options;
|
1734
1905
|
this.wasInitialized = false
|
1735
|
-
this.
|
1736
|
-
this.initializerFn = (args) => {
|
1906
|
+
this.initializerFn = (args, { dontCallFn } = {}) => {
|
1737
1907
|
const transitoryMode = global.transitoryMode
|
1738
1908
|
global.transitoryMode = false
|
1739
1909
|
// const baseConfig = args.baseConfig
|
1740
1910
|
const currentConfig = args.currentConfig
|
1741
1911
|
|
1742
|
-
if (
|
1743
|
-
|
1744
|
-
// GREG42 currentConfig.api.config = () => this
|
1745
|
-
currentConfig.api.config = () => args.baseConfig
|
1746
|
-
currentConfig.api.uuid = currentConfig._uuid
|
1912
|
+
if (args.isAfterApi) {
|
1913
|
+
fn(args)
|
1747
1914
|
}
|
1748
|
-
// this.instances.forEach( (instance) => client.processInstance(this, instance) )
|
1749
|
-
fn(args)
|
1750
1915
|
currentConfig.wasInitialized = true
|
1751
1916
|
global.transitoryMode = transitoryMode
|
1752
1917
|
}
|
@@ -1913,7 +2078,6 @@ class Config {
|
|
1913
2078
|
}
|
1914
2079
|
this.config.objects.namespaced = {}
|
1915
2080
|
this.resetWasInitialized()
|
1916
|
-
this.resetMotivations()
|
1917
2081
|
|
1918
2082
|
// reorder configs base on load ordering
|
1919
2083
|
{
|
@@ -1939,8 +2103,8 @@ class Config {
|
|
1939
2103
|
this.config.objects.namespaced[km._uuid] = {}
|
1940
2104
|
const namespacedObjects = this.config.objects.namespaced[km._uuid]
|
1941
2105
|
this.setupNamespace(km)
|
1942
|
-
// const aw =
|
1943
|
-
const
|
2106
|
+
// const aw = (word, def) => this.addWord(word, def)
|
2107
|
+
// const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
1944
2108
|
let config = km.config
|
1945
2109
|
|
1946
2110
|
if (config.addedArgss) {
|
@@ -1961,45 +2125,51 @@ class Config {
|
|
1961
2125
|
}
|
1962
2126
|
config.wasInitialized = false
|
1963
2127
|
// TODO change name of config: to baseConfig:
|
1964
|
-
const kmFn = (name) =>
|
2128
|
+
const kmFn = (name) => {
|
2129
|
+
const config = this.getConfig(name)
|
2130
|
+
return config
|
2131
|
+
}
|
1965
2132
|
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
1966
|
-
const args = {
|
2133
|
+
const args = new Object(setupInitializerFNArgs(this, {
|
1967
2134
|
isModule,
|
1968
|
-
addWord: aw,
|
1969
|
-
km: kmFn,
|
1970
2135
|
hierarchy: this.hierarchy,
|
1971
|
-
config,
|
1972
|
-
baseConfig: this,
|
2136
|
+
testConfig: config,
|
1973
2137
|
currentConfig: config,
|
1974
2138
|
uuid: config._uuid,
|
1975
2139
|
objects: namespacedObjects,
|
1976
2140
|
namespace,
|
1977
|
-
|
1978
|
-
|
2141
|
+
api: config.api,
|
2142
|
+
}))
|
2143
|
+
|
2144
|
+
const currentConfig = args.currentConfig
|
2145
|
+
|
2146
|
+
/*
|
2147
|
+
if (args.currentConfig.api) {
|
2148
|
+
// args.currentConfig.api.objects = args.objects
|
2149
|
+
// TODO assign pseudo config?
|
2150
|
+
// args.currentConfig.api.config = () => args.baseConfig
|
2151
|
+
// args.currentConfig.api.uuid = args.currentConfig._uuid
|
2152
|
+
args.currentConfig.wasInitialized = true
|
1979
2153
|
}
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
2154
|
+
*/
|
2155
|
+
// debugger
|
2156
|
+
// greg55
|
2157
|
+
config.initializerFn(args, { dontCallFn: true })
|
1983
2158
|
initAfterApis.unshift({ config, args })
|
1984
|
-
} else {
|
1985
|
-
if (interleaved) {
|
1986
|
-
initAfterApis.unshift(null)
|
1987
|
-
}
|
1988
|
-
}
|
1989
|
-
// greg
|
1990
2159
|
if (config._api) {
|
1991
2160
|
if (config._api.initialize) {
|
1992
2161
|
// reverse the list
|
1993
|
-
|
2162
|
+
// TODO sync up the args with initialize of config
|
2163
|
+
inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
|
1994
2164
|
// config._api.initialize({ config, api: config._api })
|
1995
2165
|
} else {
|
1996
2166
|
if (interleaved) {
|
1997
2167
|
inits.unshift(null)
|
1998
2168
|
}
|
1999
2169
|
}
|
2000
|
-
config._api.objects = namespacedObjects
|
2001
|
-
config._api.config = () => this
|
2002
|
-
config._api.uuid = config._uuid
|
2170
|
+
// config._api.objects = namespacedObjects
|
2171
|
+
// config._api.config = () => this
|
2172
|
+
// config._api.uuid = config._uuid
|
2003
2173
|
} else {
|
2004
2174
|
if (interleaved) {
|
2005
2175
|
inits.unshift(null)
|
@@ -2041,7 +2211,6 @@ class Config {
|
|
2041
2211
|
init()
|
2042
2212
|
}
|
2043
2213
|
for (let init of initAfterApis) {
|
2044
|
-
// init.args.isAfterApi = true
|
2045
2214
|
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2046
2215
|
}
|
2047
2216
|
this.instances.forEach((instance) => client.processInstance(this, instance))
|
@@ -2051,6 +2220,7 @@ class Config {
|
|
2051
2220
|
bridges: this.config.bridges,
|
2052
2221
|
hierarchy: this.config.hierarchy,
|
2053
2222
|
priorities: this.config.priorities,
|
2223
|
+
contextual_priorities: this.config.contextual_priorities,
|
2054
2224
|
associations: this.config.associations,
|
2055
2225
|
words: this.config.words
|
2056
2226
|
}
|
@@ -2059,6 +2229,7 @@ class Config {
|
|
2059
2229
|
this.config.bridges = []
|
2060
2230
|
this.config.hierarchy = []
|
2061
2231
|
this.config.priorities = []
|
2232
|
+
this.config.contextual_priorities = []
|
2062
2233
|
this.config.associations = { positive: [], negative: [] }
|
2063
2234
|
this.config.words = {}
|
2064
2235
|
|
@@ -2073,11 +2244,12 @@ class Config {
|
|
2073
2244
|
}
|
2074
2245
|
// console.log('name -------------', name)
|
2075
2246
|
if (inits[i]) {
|
2247
|
+
// greg55
|
2076
2248
|
inits[i]()
|
2077
2249
|
}
|
2078
2250
|
if (initAfterApis[i]) {
|
2079
2251
|
const init = initAfterApis[i]
|
2080
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true
|
2252
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true})
|
2081
2253
|
}
|
2082
2254
|
const instance = this.instances.find((instance) => instance.name == name)
|
2083
2255
|
if (instance) {
|
@@ -2085,7 +2257,6 @@ class Config {
|
|
2085
2257
|
}
|
2086
2258
|
this.hierarchy.edges = this.config.hierarchy
|
2087
2259
|
}
|
2088
|
-
// this.instances.forEach((instance) => client.processInstance(this, instance))
|
2089
2260
|
}
|
2090
2261
|
|
2091
2262
|
if (reverseIt) {
|
@@ -2208,13 +2379,9 @@ class Config {
|
|
2208
2379
|
}
|
2209
2380
|
const km = (name) => this.getConfig(name)
|
2210
2381
|
if (config instanceof Config) {
|
2211
|
-
|
2212
|
-
const aw = (word, def) => this.addWord(word, def)
|
2213
|
-
config.initializerFn({ isModule: this.isModule, addWord: aw, baseConfig: this, km, currentConfig: config, config, objects: nsobjects, namespace, uuid, api: config.api })
|
2382
|
+
config.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: config, testConfig: config, objects: nsobjects, namespace, uuid }))
|
2214
2383
|
} else {
|
2215
|
-
|
2216
|
-
const aw = (word, def) => this.addWord(word, def)
|
2217
|
-
this.initializerFn({ isModule: this.isModule, addWord: aw, baseConfig: this, km, currentConfig: this, config: this, objects: nsobjects, namespace, uuid, api: this.api })
|
2384
|
+
this.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: this, testConfig: this, objects: nsobjects, namespace, uuid }))
|
2218
2385
|
}
|
2219
2386
|
})
|
2220
2387
|
}
|
@@ -2279,6 +2446,20 @@ class Config {
|
|
2279
2446
|
config.priorities = priorities
|
2280
2447
|
}
|
2281
2448
|
|
2449
|
+
if (config.contextual_priorities) {
|
2450
|
+
let contextual_priorities = config.contextual_priorities
|
2451
|
+
contextual_priorities = contextual_priorities.map((cp) => {
|
2452
|
+
const { context, choose } = cp
|
2453
|
+
return {
|
2454
|
+
context: context.map((id) => {
|
2455
|
+
return [toNS(id[0]), id[1]]
|
2456
|
+
}),
|
2457
|
+
choose
|
2458
|
+
}
|
2459
|
+
})
|
2460
|
+
config.contextual_priorities = contextual_priorities
|
2461
|
+
}
|
2462
|
+
|
2282
2463
|
for (const bag of bags) {
|
2283
2464
|
if (config[bag]) {
|
2284
2465
|
config[bag] = config[bag].map((b) => {
|
@@ -2474,6 +2655,7 @@ class Config {
|
|
2474
2655
|
|
2475
2656
|
// TODO get rid of useOldVersion arg
|
2476
2657
|
addInternal (more, { useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
|
2658
|
+
validConfigProps(more)
|
2477
2659
|
if (more instanceof Config) {
|
2478
2660
|
more.initialize({ force: false })
|
2479
2661
|
if (useOldVersion) {
|
@@ -2571,7 +2753,7 @@ class Config {
|
|
2571
2753
|
this.config[key].splice(iOldOne, 1)
|
2572
2754
|
break;
|
2573
2755
|
}
|
2574
|
-
}
|
2756
|
+
}
|
2575
2757
|
}
|
2576
2758
|
}
|
2577
2759
|
}
|
@@ -2708,5 +2890,7 @@ class Config {
|
|
2708
2890
|
}
|
2709
2891
|
|
2710
2892
|
module.exports = {
|
2711
|
-
Config
|
2893
|
+
Config,
|
2894
|
+
config_toServer,
|
2895
|
+
operatorKey_valid,
|
2712
2896
|
}
|