theprogrammablemind 7.12.7 → 7.12.8-beta.0

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 CHANGED
@@ -81,104 +81,6 @@ const pickObjects = (config, testConfig, getObjects) => {
81
81
  return projection
82
82
  }
83
83
 
84
- // move ask to the KM's since verbatim is called probably in dialogues?
85
- const getAsk = (config) => (uuid) => {
86
- // if (!uuid) {
87
- // debugger
88
- //}
89
- return (asks) => {
90
- const ask = (ask) => {
91
- let oneShot = true // default
92
- if (ask.oneShot === false) {
93
- oneShot = false
94
- }
95
-
96
- const id_q = stableId('semantic')
97
- const id_rs = []
98
- let wasAsked = false
99
- let wasApplied = false
100
- const getWasAsked = () => {
101
- return wasAsked
102
- }
103
- const setWasAsked = (value) => {
104
- wasAsked = value
105
- }
106
- const getWasApplied = () => {
107
- return wasApplied
108
- }
109
- const setWasApplied = (value) => {
110
- wasApplied = value
111
- }
112
-
113
- const semanticsr = ask.semanticsr || []
114
- if (semanticsr.length == 0) {
115
- semanticsr.push({ match: ask.matchr, apply: ask.applyr })
116
- }
117
- for (const semantic of semanticsr) {
118
- const id_r = stableId('semantic')
119
- id_rs.push(id_r)
120
- config.addSemantic({
121
- uuid,
122
- id: id_r,
123
- tied_ids: [id_q],
124
- oneShot,
125
- where: semantic.where || ask.where || where(2),
126
- source: 'response',
127
- match: (args) => semantic.match(args),
128
- apply: (args) => {
129
- setWasApplied(true)
130
- semantic.apply(args)
131
- },
132
- })
133
- }
134
-
135
- config.addSemantic({
136
- uuid,
137
- oneShot,
138
- id: id_q,
139
- tied_ids: id_rs,
140
- where: ask.where,
141
- isQuestion: true, // do one question at a time
142
- getWasAsked,
143
- getWasApplied,
144
- onNevermind: ask.onNevermind,
145
- source: 'question',
146
- match: ({ context }) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
147
- apply: (args) => {
148
- let matchq = ask.matchq
149
- let applyq = ask.applyq
150
- if (!matchq) {
151
- let wasAsked = false
152
- matchq = () => !wasAsked,
153
- applyq = (args) => {
154
- wasAsked = true
155
- return ask.applyq(args)
156
- }
157
- }
158
- if (matchq(args)) {
159
- setWasAsked(true)
160
- setWasApplied(false)
161
- // args.context.motivationKeep = true
162
- args.verbatim(applyq(args))
163
- /*
164
- args.context.verbatim = applyq(args)
165
- args.context.isResponse = true;
166
- delete args.context.controlRemove;
167
- */
168
- args.context.controlKeepMotivation = true
169
- }
170
- args.context.cascade = true
171
- }
172
- })
173
- }
174
- if (!Array.isArray(asks)) {
175
- asks = [asks]
176
- }
177
-
178
- [...asks].reverse().forEach( (a) => ask(a) )
179
- }
180
- }
181
-
182
84
  const sameJSON = (json1, json2) => {
183
85
  const sjson1 = sortJson(json1, { depth: 25 })
184
86
  const sjson2 = sortJson(json2, { depth: 25 })
@@ -300,7 +202,6 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
300
202
  }
301
203
  // for semantics
302
204
  args.addAssumedScoped(args, {})
303
- config.getAddedArgs(args)
304
205
 
305
206
  const getAPI = (uuid) => {
306
207
  if (config && config.getAPI) {
@@ -312,14 +213,14 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
312
213
  return config.getAPIs(uuid)
313
214
  }
314
215
  }
315
- const scopedAsk = getAsk(config)
316
216
  args.getUUIDScoped = (uuid) => {
317
217
  return {
318
- ask: scopedAsk(uuid),
319
218
  api: getAPI(uuid),
320
219
  apis: getAPIs(uuid)
321
220
  }
322
221
  }
222
+ config.getAddedArgs(args)
223
+
323
224
  Object.assign(args, args.getUUIDScoped(uuidForScoping || config.uuid))
324
225
  /*
325
226
  if (uuidForScoping) {
@@ -1281,7 +1182,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1281
1182
  console.log('Errors')
1282
1183
  responses.errors.forEach((error) => console.log(` ${error}`))
1283
1184
  }
1284
- console.log("KM's loaded", config.configs.map((c) => c.name))
1185
+ console.log("KM's loaded (ordered)", config.configs.map((c) => c.name))
1285
1186
  console.log('This is the global objects from running semantics:\n', config.objects)
1286
1187
  if (!_.isEmpty(responses.learned_contextual_priorities)) {
1287
1188
  console.log('\nThe learned contextual priorties are :\n')
@@ -2270,6 +2171,7 @@ const knowledgeModule = async (...args) => {
2270
2171
 
2271
2172
  module.exports = {
2272
2173
  process: _process,
2174
+ stableId,
2273
2175
  where,
2274
2176
  w,
2275
2177
  // submitBug,
package/index.js CHANGED
@@ -15,6 +15,7 @@ module.exports = {
15
15
  knowledgeModule: client.knowledgeModule,
16
16
  ensureTestFile: client.ensureTestFile,
17
17
  where: client.where,
18
+ stableId: client.stableId,
18
19
  w: client.w,
19
20
  Config,
20
21
  Semantics,
package/package.json CHANGED
@@ -65,6 +65,6 @@
65
65
  "json-stable-stringify": "^1.0.1",
66
66
  "node-fetch": "^2.6.1"
67
67
  },
68
- "version": "7.12.7",
68
+ "version": "7.12.8-beta.0",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -1778,7 +1778,16 @@ class Config {
1778
1778
  getAddedArgs (args) {
1779
1779
  for (let addedArgs of this.addedArgss) {
1780
1780
  addedArgs = addedArgs(args)
1781
+ const getUUIDScoped = addedArgs.getUUIDScoped
1782
+ delete addedArgs.getUUIDScoped
1781
1783
  Object.assign(args, addedArgs)
1784
+ if (getUUIDScoped) {
1785
+ const currentGetUUIDScoped = args.getUUIDScoped
1786
+ if (!currentGetUUIDScoped) {
1787
+ debugger
1788
+ }
1789
+ args.getUUIDScoped = (uuid) => Object.assign(currentGetUUIDScoped(uuid), getUUIDScoped(uuid))
1790
+ }
1782
1791
  }
1783
1792
  }
1784
1793
 
@@ -2803,7 +2812,8 @@ class Config {
2803
2812
  more = more.copy()
2804
2813
  more.server(this._server, this._key, this._queryParams)
2805
2814
 
2806
- this.loadOrder.addList(more.configs.map((km) => km.name || km.uuid))
2815
+ const moreConfigs = more.configs.map((km) => km.name || km.uuid)
2816
+ this.loadOrder.addList(moreConfigs)
2807
2817
 
2808
2818
  // get the new ones
2809
2819
  // remove the dups
package/src/digraph.js CHANGED
@@ -113,19 +113,31 @@ class Digraph {
113
113
  }
114
114
 
115
115
  minima (nodes) {
116
- let minima = new Set(nodes)
117
- const ancestors = new Set([])
118
- nodes.forEach((node) => {
119
- this.ancestors(node).forEach((n) => ancestors.add(n))
120
- })
121
- ancestors.forEach((n) => minima.delete(n))
122
- if (minima.size === 0) {
123
- // all unrelated
124
- minima = new Set(nodes)
116
+ nodes = new Set(nodes)
117
+ const nodeToDescendants = {}
118
+ for (const node of nodes) {
119
+ nodeToDescendants[node] = this.descendants(node)
120
+ }
121
+ let minima = new Set()
122
+ for (const node of nodes) {
123
+ let okay = true
124
+ for (const key of nodeToDescendants[node]) {
125
+ if (nodes.has(key)) {
126
+ if (key in nodeToDescendants && nodeToDescendants[key].has(node)) {
127
+ continue
128
+ }
129
+ okay = false
130
+ break
131
+ }
132
+ }
133
+ if (okay) {
134
+ minima.add(node)
135
+ }
125
136
  }
126
137
  return minima
127
138
  }
128
139
 
140
+ /*
129
141
  maxima (nodes) {
130
142
  const maxima = new Set(nodes)
131
143
  const descendants = new Set([])
@@ -135,14 +147,21 @@ class Digraph {
135
147
  descendants.forEach((n) => maxima.delete(n))
136
148
  return maxima
137
149
  }
150
+ */
138
151
 
139
152
  add (child, parent) {
140
153
  this._edges.push([child, parent])
141
154
  }
142
155
 
156
+ exists(child, parent) {
157
+ return this._edges.find((edge) => edge[0] == child && edge[1] == parent)
158
+ }
159
+
143
160
  addList (l) {
144
161
  for (let i = 1; i < l.length; ++i) {
145
- this._edges.push([l[i - 1], l[i]])
162
+ if (!this.exists(l[i-1], l[i])) {
163
+ this._edges.push([l[i - 1], l[i]])
164
+ }
146
165
  }
147
166
  }
148
167
 
@@ -81,19 +81,31 @@ class DigraphInternal {
81
81
  }
82
82
 
83
83
  minima (nodes) {
84
- let minima = new Set(nodes)
85
- const ancestors = new Set([])
86
- nodes.forEach((node) => {
87
- this.ancestors(node).forEach((n) => ancestors.add(n))
88
- })
89
- ancestors.forEach((n) => minima.delete(n))
90
- if (minima.size === 0) {
91
- // all unrelated
92
- minima = new Set(nodes)
84
+ nodes = new Set(nodes)
85
+ const nodeToDescendants = {}
86
+ for (const node of nodes) {
87
+ nodeToDescendants[node] = this.descendants(node)
88
+ }
89
+ let minima = new Set()
90
+ for (const node of nodes) {
91
+ let okay = true
92
+ for (const key of nodeToDescendants[node]) {
93
+ if (nodes.has(key)) {
94
+ if (key in nodeToDescendants && nodeToDescendants[key].has(node)) {
95
+ continue
96
+ }
97
+ okay = false
98
+ break
99
+ }
100
+ }
101
+ if (okay) {
102
+ minima.add(node)
103
+ }
93
104
  }
94
105
  return minima
95
106
  }
96
107
 
108
+ /*
97
109
  maxima (nodes) {
98
110
  const maxima = new Set(nodes)
99
111
  const descendants = new Set([])
@@ -103,14 +115,21 @@ class DigraphInternal {
103
115
  descendants.forEach((n) => maxima.delete(n))
104
116
  return maxima
105
117
  }
118
+ */
106
119
 
107
120
  add (child, parent) {
108
121
  this._edges.push([child, parent])
109
122
  }
110
123
 
124
+ exists(child, parent) {
125
+ return this._edges.findIndex((edge) => edge[0] == child && edge[1] == parent) != -1
126
+ }
127
+
111
128
  addList (l) {
112
129
  for (let i = 1; i < l.length; ++i) {
113
- this._edges.push([l[i - 1], l[i]])
130
+ if (!this.exists(l[i-1], l[i])) {
131
+ this._edges.push([l[i - 1], l[i]])
132
+ }
114
133
  }
115
134
  }
116
135