ekms 9.6.3 → 9.7.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.
Files changed (84) hide show
  1. package/common/actions.instance.json +2771 -15
  2. package/common/actions.js +116 -8
  3. package/common/actions.test.json +79138 -384
  4. package/common/angle.instance.json +138 -834
  5. package/common/angle.test.json +172 -127
  6. package/common/animals.instance.json +260 -0
  7. package/common/articles.js +1 -2
  8. package/common/avatar.test.json +173 -33
  9. package/common/can.instance.json +40 -0
  10. package/common/colors.instance.json +308 -0
  11. package/common/comparable.instance.json +120 -0
  12. package/common/compass.instance.json +63 -18
  13. package/common/concept.js +2 -1
  14. package/common/conjunction.js +11 -17
  15. package/common/control.js +42 -0
  16. package/common/control.test.json +2 -0
  17. package/common/crew.instance.json +520 -0
  18. package/common/dates.instance.json +184 -0
  19. package/common/dialogues.js +3 -3
  20. package/common/dimension.instance.json +264 -69
  21. package/common/dimension.js +5 -5
  22. package/common/dimension.test.json +545 -441
  23. package/common/drone.instance.json +15927 -2638
  24. package/common/drone.js +359 -71
  25. package/common/drone.test.json +587651 -44132
  26. package/common/drone_v1.instance.json +492 -59
  27. package/common/drone_v1.js +9 -9
  28. package/common/edible.instance.json +696 -0
  29. package/common/emotions.instance.json +20 -0
  30. package/common/evaluate.js +1 -1
  31. package/common/fastfood.instance.json +1310 -216
  32. package/common/fastfood.js +1 -1
  33. package/common/formulas.instance.json +20 -5
  34. package/common/formulas.js +1 -1
  35. package/common/gdefaults.js +32 -5
  36. package/common/help.test.json +23 -3
  37. package/common/helpers/conjunction.js +2 -0
  38. package/common/helpers/formulas.js +6 -0
  39. package/common/helpers/properties.js +9 -7
  40. package/common/helpers.js +11 -6
  41. package/common/hierarchy.js +2 -0
  42. package/common/kirk.instance.json +20 -0
  43. package/common/length.instance.json +1117 -5708
  44. package/common/length.test.json +29761 -12488
  45. package/common/logging.js +41 -0
  46. package/common/logging.test.json +2 -0
  47. package/common/math.instance.json +30 -12
  48. package/common/math.js +6 -5
  49. package/common/menus.instance.json +140 -35
  50. package/common/meta.js +1 -1
  51. package/common/nameable.js +7 -9
  52. package/common/nameable.test.json +252 -150
  53. package/common/ordering.instance.json +40 -0
  54. package/common/ordinals.js +51 -5
  55. package/common/people.instance.json +160 -0
  56. package/common/pipboy.instance.json +396 -85
  57. package/common/pipboy.js +1 -1
  58. package/common/pokemon.instance.json +260 -0
  59. package/common/pressure.instance.json +108 -370
  60. package/common/properties.instance.json +20 -0
  61. package/common/properties.js +5 -4
  62. package/common/properties.test.json +2754 -2142
  63. package/common/rates.instance.json +1 -1
  64. package/common/rates.js +3 -3
  65. package/common/rates.test.json +6914 -2428
  66. package/common/reminders.js +1 -1
  67. package/common/reports.instance.json +49 -176
  68. package/common/reports.js +2 -2
  69. package/common/scorekeeper.js +1 -1
  70. package/common/sdefaults.js +18 -5
  71. package/common/spock.instance.json +20 -0
  72. package/common/stm.js +115 -53
  73. package/common/stm.test.json +2670 -54
  74. package/common/temperature.instance.json +709 -2284
  75. package/common/time.instance.json +14333 -2220
  76. package/common/time.js +48 -2
  77. package/common/time.test.json +13239 -0
  78. package/common/tokenize.js +2 -0
  79. package/common/ui.instance.json +20 -5
  80. package/common/ui.js +1 -1
  81. package/common/weight.instance.json +621 -1886
  82. package/common/wp.instance.json +336 -70
  83. package/main.js +4 -0
  84. package/package.json +11 -5
package/common/reports.js CHANGED
@@ -38,7 +38,7 @@ function compareValue(property, v1, v2) {
38
38
  function newReport({km, objects}) {
39
39
  objects.tempReportId += 1
40
40
  const reportId = `tempReport${objects.tempReportId}`
41
- km('stm').api.mentioned({ context: { marker: "report", text: reportId, types: [ "report" ], value: reportId, word: reportId } })
41
+ km('stm').api.remember({ context: { marker: "report", text: reportId, types: [ "report" ], value: reportId, word: reportId } })
42
42
  // name to listing
43
43
  objects.listings[reportId] = {
44
44
  columns: ['name', 'supplier'],
@@ -344,7 +344,7 @@ const config = {
344
344
  const name = context.name.map((n) => n.text).join('')
345
345
  objects.listings[name] = {...listing}
346
346
  config.addWord(`${name}`, { id: 'report', initial: `{ value: "${name}" }` })
347
- km('stm').api.mentioned({
347
+ km('stm').api.remember({
348
348
  context: {
349
349
  marker: "report",
350
350
  text: name,
@@ -43,7 +43,7 @@ function setNextPlayer(km, objects) {
43
43
  word: "turn"
44
44
  }
45
45
  const api = km('stm').api
46
- api.mentioned({ context: turn })
46
+ api.remember({ context: turn })
47
47
  }
48
48
 
49
49
  function addPlayer(objects, config, player) {
@@ -1,5 +1,6 @@
1
1
  const { flatten, knowledgeModule, where, debug } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck, concats, toEValue, toFinalValue } = require('./helpers')
3
+ const control = require('./control')
3
4
  const sdefaults_tests = require('./sdefaults.test.json')
4
5
 
5
6
  class API {
@@ -14,6 +15,8 @@ class API {
14
15
  }
15
16
  }
16
17
 
18
+ // TODO generalize this for avoiding recusive call without changing the context properties
19
+
17
20
  const config = {
18
21
  name: 'sdefaults',
19
22
  semantics: [
@@ -22,13 +25,17 @@ const config = {
22
25
  where: where(),
23
26
  priority: -1,
24
27
  // match: ({context}) => context.flatten || context.listable && context.value[0].flatten,
25
- match: ({context}) => context.flatten || context.listable && context.value.some((value) => value.flatten),
28
+ // match: (args) => okay(args, ({context}) => (context.flatten || context.listable && context.value.some((value) => value.flatten))),
29
+ match: (args) => args.callOnce(args, ({context}) => (context.flatten || context.listable && context.value.some((value) => value.flatten))),
26
30
  // match: ({context}) => context.flatten || context.listable || (Array.isArray(context.value) && context.value.some((value) => value.flatten)),
27
- apply: async ({config, km, context, s}) => {
31
+ apply: async ({config, km, context, s, _continue}) => {
28
32
  const [flats, wf] = flatten(['list'], context)
29
33
  const evalues = []
30
34
  for (const flat of flats) {
31
- const result = await s({ ...flat, flatten: false })
35
+ if (!flat.control) {
36
+ flat.control = context.control
37
+ }
38
+ const result = await s(flat)
32
39
  if (result.evalue) {
33
40
  evalues.push(result.evalue)
34
41
  }
@@ -37,17 +44,22 @@ const config = {
37
44
  context.evalue = concats(evalues)
38
45
  context.isResponse = true
39
46
  }
47
+ context.control.seen.length = 0
40
48
  }
41
49
  },
42
50
  {
43
51
  notes: 'flatten relation',
44
52
  where: where(),
45
53
  priority: -1,
46
- match: ({context}) => context.flatten && context.relation,
54
+ // match: ({context}) => context.flatten && context.relation,
55
+ match: (args) => args.callOnce(args, ({context}) => (context.flatten && context.relation)),
47
56
  apply: async ({config, km, context, s}) => {
48
57
  const [flats, wf] = flatten(['list'], context)
49
58
  for (const flat of flats) {
50
- await s({ ...flat, flatten: false })
59
+ if (!flat.control) {
60
+ flat.control = context.control
61
+ }
62
+ await s(flat)
51
63
  }
52
64
  }
53
65
  },
@@ -85,6 +97,7 @@ function initializer({objects, config, isModule}) {
85
97
 
86
98
  knowledgeModule({
87
99
  config,
100
+ includes: [control],
88
101
  initializer,
89
102
  api: () => new API(),
90
103
 
@@ -395,6 +395,16 @@
395
395
  "theAble",
396
396
  false
397
397
  ],
398
+ [
399
+ "deletable",
400
+ "deletable",
401
+ false
402
+ ],
403
+ [
404
+ "delete",
405
+ "verb",
406
+ false
407
+ ],
398
408
  [
399
409
  "distributable",
400
410
  "queryable",
@@ -965,6 +975,11 @@
965
975
  "adjective",
966
976
  false
967
977
  ],
978
+ [
979
+ "memorable",
980
+ "deletable",
981
+ false
982
+ ],
968
983
  [
969
984
  "memorable",
970
985
  "theAble",
@@ -1415,6 +1430,11 @@
1415
1430
  "theAble",
1416
1431
  false
1417
1432
  ],
1433
+ [
1434
+ "recall",
1435
+ "verb",
1436
+ false
1437
+ ],
1418
1438
  [
1419
1439
  "remember",
1420
1440
  "verb",
package/common/stm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { knowledgeModule, where, debug } = require('./runtime').theprogrammablemind
2
- const { defaultContextCheck } = require('./helpers')
2
+ const { defaultContextCheckProperties, defaultContextCheck } = require('./helpers')
3
3
  const helpers = require('./helpers')
4
4
  const helpers_conjunction = require('./helpers/conjunction')
5
5
  const articles = require('./articles')
@@ -41,7 +41,7 @@ class API {
41
41
  return this._objects.mentioned.filter( (context) => this.isA(context.marker, type) )
42
42
  }
43
43
 
44
- mentioned(args) {
44
+ remember(args) {
45
45
  let concept, value, frameOfReference
46
46
  if (!args.context) {
47
47
  concept = args
@@ -51,6 +51,10 @@ class API {
51
51
  frameOfReference = args.frameOfReference
52
52
  }
53
53
 
54
+ if (concept.pullFromContext) {
55
+ return
56
+ }
57
+
54
58
  if (!frameOfReference) {
55
59
  frameOfReference = this._objects
56
60
  }
@@ -76,8 +80,8 @@ class API {
76
80
  helpers.unshiftL(frameOfReference.mentioned, concept, this.maximumMentioned)
77
81
  }
78
82
 
79
- mentions({ context, frameOfReference, useHierarchy=true, all, lastN, condition = (() => true) } = {}) {
80
- let mentioned = this._objects.mentioned
83
+ recall({ context, frameOfReference, useHierarchy=true, all, stopCondition = (() => false), condition = (() => true), filter = ((result) => result) } = {}) {
84
+ let mentioned = this._objects.mentioned.filter((m) => !m.namespaced?.stm?.deleted)
81
85
  let reversed = false
82
86
  if (frameOfReference) {
83
87
  if (frameOfReference.namespaced?.stm?.mentioned) {
@@ -97,7 +101,7 @@ class API {
97
101
  if (!mentioned) {
98
102
  return
99
103
  }
100
- const findPrevious = !!context.stm_previous
104
+ const findPrevious = !!context?.stm_previous
101
105
  const forAll = []
102
106
  function addForAll(context) {
103
107
  if (!forAll.find( (c) => c.namespaced.stm.id == context.namespaced.stm.id)) {
@@ -112,7 +116,7 @@ class API {
112
116
  // care about value first
113
117
  let findCounter = 0
114
118
  for (const m of mentioned) {
115
- if (lastN === 0) {
119
+ if (stopCondition(m)) {
116
120
  break
117
121
  }
118
122
  if (context.value && (context.value == m.marker || context.value == m.value)) {
@@ -124,20 +128,17 @@ class API {
124
128
  continue
125
129
  }
126
130
  if (condition(m)) {
127
- if (all || lastN) {
131
+ if (all) {
128
132
  addForAll(m)
129
- if (lastN) {
130
- lastN -= 1
131
- }
132
133
  } else {
133
- return m
134
+ return filter(m)
134
135
  }
135
136
  }
136
137
  }
137
138
  }
138
139
 
139
- if (lastN === 0) {
140
- return forAll
140
+ if (forAll.length > 0) {
141
+ return filter(forAll)
141
142
  }
142
143
 
143
144
  if (!useHierarchy) {
@@ -147,7 +148,7 @@ class API {
147
148
  // care about marker second
148
149
  findCounter = 0
149
150
  for (const m of mentioned) {
150
- if (lastN === 0) {
151
+ if (stopCondition(m)) {
151
152
  break
152
153
  }
153
154
  if (context.marker != 'unknown' && this.isA(m.marker, context.marker)) {
@@ -159,19 +160,19 @@ class API {
159
160
  continue
160
161
  }
161
162
  if (condition(m)) {
162
- if (all || lastN) {
163
+ if (all) {
163
164
  addForAll(m)
164
- if (lastN) {
165
- lastN -= 1
166
- }
167
165
  } else {
168
- return m
166
+ return filter(m)
169
167
  }
170
168
  }
171
169
  }
172
170
  // if (context.types && context.types.includes(m.marker)) {
173
171
  if (context.types) {
174
172
  for (const parent of context.types) {
173
+ if (stopCondition(m)) {
174
+ break
175
+ }
175
176
  if (parent != 'unknown' && this.isA(m.marker, parent)) {
176
177
  findCounter += 1
177
178
  if (findPrevious && findCounter < 2) {
@@ -181,13 +182,10 @@ class API {
181
182
  continue
182
183
  }
183
184
  if (condition(m)) {
184
- if (all || lastN) {
185
- if (lastN) {
186
- lastN -= 1
187
- }
185
+ if (all) {
188
186
  addForAll(m)
189
187
  } else {
190
- return m
188
+ return filter(m)
191
189
  }
192
190
  }
193
191
  }
@@ -195,37 +193,34 @@ class API {
195
193
  }
196
194
  }
197
195
 
198
- if (lastN === 0) {
199
- return forAll
196
+ if (forAll.length > 0) {
197
+ return filter(forAll)
200
198
  }
201
199
 
202
200
  findCounter = 0
203
201
  if (context.types && context.types.length == 1) {
204
202
  for (const m of mentioned) {
205
- if (lastN === 0) {
206
- break
207
- }
208
203
  if (context.unknown) {
209
204
  findCounter += 1
210
205
  if (findPrevious && findCounter < 2) {
211
206
  continue
212
207
  }
208
+ if (stopCondition(m)) {
209
+ break
210
+ }
213
211
  if (condition(m)) {
214
- if (all || lastN) {
212
+ if (all) {
215
213
  addForAll(m)
216
- if (lastN) {
217
- lastN -= 1
218
- }
219
214
  } else {
220
- return m
215
+ return filter(m)
221
216
  }
222
217
  }
223
218
  }
224
219
  }
225
220
  }
226
221
 
227
- if (all || lastN) {
228
- return forAll
222
+ if (forAll.length > 0) {
223
+ return filter(forAll)
229
224
  }
230
225
  }
231
226
 
@@ -233,7 +228,7 @@ class API {
233
228
  if (!context || context.marker == 'mentions') {
234
229
  return
235
230
  }
236
- let valueNew = this.mentions({ context, useHierarchy: false, condition: (context) => context.isVariable })
231
+ let valueNew = this.recall({ context, useHierarchy: false, condition: (context) => context.isVariable })
237
232
  if (valueNew && valueNew.value) {
238
233
  valueNew = valueNew.value
239
234
  }
@@ -241,7 +236,7 @@ class API {
241
236
  }
242
237
 
243
238
  setVariable(variableName, value) {
244
- this.mentioned({ context: { marker: variableName, isVariable: true }, value })
239
+ this.remember({ context: { marker: variableName, isVariable: true }, value })
245
240
  }
246
241
  }
247
242
 
@@ -254,6 +249,8 @@ const config = {
254
249
  "(<stm_previous|previous> ([memorable]))",
255
250
  "(([memorable]) <stm_before|before>)",
256
251
  "([remember] (memorable/*))",
252
+ "([recall] (memorable/*))",
253
+ "([delete|delete,forget] ([deletable]))",
257
254
  ],
258
255
  words: {
259
256
  literals: {
@@ -262,10 +259,37 @@ const config = {
262
259
  },
263
260
  },
264
261
  bridges: [
262
+ {
263
+ id: 'deletable',
264
+ },
265
+ {
266
+ id: 'delete',
267
+ isA: ['verb'],
268
+ bridge: "{ ...next(operator), deletable: after[0], operator: operator, interpolate: [{ property: 'operator' }, { property: 'deletable' }] }",
269
+ semantic: async ({context, recall}) => {
270
+ const object = await recall({ context: context.deletable })
271
+ if (object) {
272
+ object.namespaced.stm.deleted = true
273
+ for (const callback of object.namespaced.stm.callbacks || []) {
274
+ callback.callback(object)
275
+ }
276
+ }
277
+ }
278
+ },
265
279
  {
266
280
  id: 'memorable',
267
- isA: ['theAble'],
268
- words: helpers.words('memorable')
281
+ isA: ['theAble', 'deletable'],
282
+ words: helpers.words('memorable'),
283
+ check: defaultContextCheckProperties(),
284
+ },
285
+ {
286
+ id: 'recall',
287
+ bridge: "{ ...next(operator), postModifiers: ['recallee'], recallee: after[0] }",
288
+ isA: ['verb'],
289
+ semantic: async ({context, recall, resolveResponse, e}) => {
290
+ const object = await recall({ context: context.recallee })
291
+ resolveResponse(context, object)
292
+ },
269
293
  },
270
294
  {
271
295
  id: 'remember',
@@ -276,7 +300,7 @@ const config = {
276
300
  if (value == context.rememberee.value) {
277
301
  value = context.rememberee
278
302
  }
279
- api.mentioned({ context: value })
303
+ api.remember({ context: value })
280
304
  },
281
305
  },
282
306
  {
@@ -296,11 +320,24 @@ const config = {
296
320
  },
297
321
  ],
298
322
  semantics: [
323
+ {
324
+ where: where(),
325
+ match: ({context}) => context.marker == 'mentions' && context.evaluate && context.args?.context?.distributer,
326
+ apply: async ({callId, _continue, toList, context, kms, e, log, toArray, retry}) => {
327
+ context.args.filter ??= (r) => r
328
+ context.args.all = true
329
+ const oldFilter = context.args.filter
330
+ context.args.filter = (result) => {
331
+ return oldFilter(result)
332
+ }
333
+ _continue()
334
+ }
335
+ },
299
336
  {
300
337
  where: where(),
301
338
  match: ({context}) => context.marker == 'mentions' && context.evaluate,
302
339
  apply: ({context, kms, toList, resolveEvaluate}) => {
303
- resolveEvaluate(context, kms.stm.api.mentions(context.args))
340
+ resolveEvaluate(context, kms.stm.api.recall(context.args))
304
341
  }
305
342
  },
306
343
  {
@@ -308,14 +345,13 @@ const config = {
308
345
  notes: 'pull from context',
309
346
  // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
310
347
  match: ({context, callId}) => context.pullFromContext && !context.same, // && context.value,
311
- apply: async ({callId, mentions, toList, context, kms, e, log, retry}) => {
312
- context.value = (await mentions({ context }))
348
+ apply: async ({callId, recall, toList, context, kms, e, log, retry}) => {
349
+ context.value = (await recall({ context }))
313
350
  if (Array.isArray(context.value)) {
314
351
  context.value = toList(context.value)
315
352
  }
316
353
 
317
354
  if (!context.value) {
318
- // retry()
319
355
  context.evalue = { marker: 'answerNotKnown' }
320
356
  return
321
357
  }
@@ -334,8 +370,8 @@ const config = {
334
370
 
335
371
  function initializer({config}) {
336
372
  config.addArgs(({kms, e, toList}) => ({
337
- mentioned: (args) => {
338
- kms.stm.api.mentioned(args)
373
+ remember: (args) => {
374
+ kms.stm.api.remember(args)
339
375
  },
340
376
 
341
377
  frameOfReference: (context, { mentioned, reversed } = {}) => {
@@ -349,7 +385,24 @@ function initializer({config}) {
349
385
  }
350
386
  },
351
387
 
352
- mentions: async (args) => {
388
+ addCallback: (context, callback) => {
389
+ // init
390
+ context.namespaced ??= {}
391
+ context.namespaced.stm ??= {}
392
+ context.namespaced.stm.callbackCounter ??= 1
393
+ context.namespaced.stm.callbacks ??= []
394
+
395
+ // meat
396
+ context.namespaced.stm.callbackCounter += 1
397
+ const counter = context.namespaced.stm.callbackCounter
398
+ context.namespaced.stm.callbacks.push({ callback, counter })
399
+ callback.removeCallback = () => {
400
+ context.namespaced.stm.callbacks = context.namespaced.stm.callbacks.filter((cb) => cb.counter != counter)
401
+ }
402
+ return counter
403
+ },
404
+
405
+ recall: async (args) => {
353
406
  if (args.frameOfReference?.nameable_named) {
354
407
  const result = await e(args.frameOfReference)
355
408
  if (result.evalue) {
@@ -379,10 +432,19 @@ knowledgeModule( {
379
432
  name: './stm.test.json',
380
433
  contents: stm_tests,
381
434
  checks: {
382
- context: [defaultContextCheck({ extra: ['pullFromContext', 'stm_id'] })],
383
- objects: [{ path: ['mentioned'] }],
384
- // objects: [defaultContextCheck({ extra: ['mentioned'] })],
385
- // objects: [{ property: 'mentioned', check: helpers.defaultContextCheckProperties }],
386
- },
435
+ context: [defaultContextCheck({ extra: ['pullFromContext', 'stm_id'] })],
436
+ objects: [
437
+ {
438
+ property: 'mentioned',
439
+ check: [{
440
+ property: (key) => typeof key == 'number',
441
+ check: [{
442
+ property: 'namespaced',
443
+ check: [{ property: 'stm', check: ['id', 'deleted', 'named'] }]
444
+ }]
445
+ }] ,
446
+ },
447
+ ],
448
+ },
387
449
  },
388
450
  })