ekms 9.6.3-beta.9 → 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 (74) hide show
  1. package/common/actions.instance.json +2767 -13
  2. package/common/actions.js +112 -5
  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 +280 -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 +100 -0
  19. package/common/dimension.instance.json +264 -69
  20. package/common/dimension.js +2 -2
  21. package/common/dimension.test.json +545 -441
  22. package/common/drone.instance.json +9101 -794
  23. package/common/drone.js +257 -68
  24. package/common/drone.test.json +415672 -38730
  25. package/common/drone_v1.instance.json +462 -57
  26. package/common/edible.instance.json +640 -0
  27. package/common/emotions.instance.json +20 -0
  28. package/common/evaluate.js +1 -1
  29. package/common/fastfood.instance.json +1310 -176
  30. package/common/formulas.instance.json +20 -5
  31. package/common/formulas.js +1 -1
  32. package/common/gdefaults.js +19 -3
  33. package/common/help.test.json +23 -3
  34. package/common/helpers/conjunction.js +2 -0
  35. package/common/helpers/formulas.js +6 -0
  36. package/common/helpers/properties.js +9 -7
  37. package/common/helpers.js +11 -6
  38. package/common/hierarchy.js +2 -0
  39. package/common/kirk.instance.json +20 -0
  40. package/common/length.instance.json +1117 -5708
  41. package/common/length.test.json +29761 -12488
  42. package/common/logging.js +41 -0
  43. package/common/logging.test.json +2 -0
  44. package/common/math.instance.json +30 -12
  45. package/common/math.js +6 -5
  46. package/common/menus.instance.json +140 -35
  47. package/common/meta.js +1 -1
  48. package/common/nameable.js +0 -2
  49. package/common/nameable.test.json +252 -150
  50. package/common/ordering.instance.json +40 -0
  51. package/common/people.instance.json +160 -0
  52. package/common/pipboy.instance.json +340 -85
  53. package/common/pokemon.instance.json +260 -0
  54. package/common/pressure.instance.json +108 -370
  55. package/common/properties.instance.json +20 -0
  56. package/common/properties.js +2 -1
  57. package/common/properties.test.json +2754 -2142
  58. package/common/rates.test.json +6914 -2428
  59. package/common/reports.instance.json +49 -176
  60. package/common/sdefaults.js +18 -5
  61. package/common/spock.instance.json +20 -0
  62. package/common/stm.js +95 -12
  63. package/common/stm.test.json +2670 -54
  64. package/common/temperature.instance.json +709 -2284
  65. package/common/time.instance.json +14241 -2228
  66. package/common/time.js +30 -3
  67. package/common/time.test.json +9914 -0
  68. package/common/tokenize.js +2 -0
  69. package/common/ui.instance.json +20 -5
  70. package/common/ui.js +1 -1
  71. package/common/weight.instance.json +621 -1886
  72. package/common/wp.instance.json +280 -70
  73. package/main.js +4 -0
  74. package/package.json +11 -5
@@ -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')
@@ -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
- recall({ context, frameOfReference, useHierarchy=true, all, condition = (() => true), filter = ((result) => result) } = {}) {
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,6 +116,9 @@ class API {
112
116
  // care about value first
113
117
  let findCounter = 0
114
118
  for (const m of mentioned) {
119
+ if (stopCondition(m)) {
120
+ break
121
+ }
115
122
  if (context.value && (context.value == m.marker || context.value == m.value)) {
116
123
  findCounter += 1
117
124
  if (findPrevious && findCounter < 2) {
@@ -141,6 +148,9 @@ class API {
141
148
  // care about marker second
142
149
  findCounter = 0
143
150
  for (const m of mentioned) {
151
+ if (stopCondition(m)) {
152
+ break
153
+ }
144
154
  if (context.marker != 'unknown' && this.isA(m.marker, context.marker)) {
145
155
  findCounter += 1
146
156
  if (findPrevious && findCounter < 2) {
@@ -160,6 +170,9 @@ class API {
160
170
  // if (context.types && context.types.includes(m.marker)) {
161
171
  if (context.types) {
162
172
  for (const parent of context.types) {
173
+ if (stopCondition(m)) {
174
+ break
175
+ }
163
176
  if (parent != 'unknown' && this.isA(m.marker, parent)) {
164
177
  findCounter += 1
165
178
  if (findPrevious && findCounter < 2) {
@@ -192,6 +205,9 @@ class API {
192
205
  if (findPrevious && findCounter < 2) {
193
206
  continue
194
207
  }
208
+ if (stopCondition(m)) {
209
+ break
210
+ }
195
211
  if (condition(m)) {
196
212
  if (all) {
197
213
  addForAll(m)
@@ -233,6 +249,8 @@ const config = {
233
249
  "(<stm_previous|previous> ([memorable]))",
234
250
  "(([memorable]) <stm_before|before>)",
235
251
  "([remember] (memorable/*))",
252
+ "([recall] (memorable/*))",
253
+ "([delete|delete,forget] ([deletable]))",
236
254
  ],
237
255
  words: {
238
256
  literals: {
@@ -241,10 +259,37 @@ const config = {
241
259
  },
242
260
  },
243
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
+ },
244
279
  {
245
280
  id: 'memorable',
246
- isA: ['theAble'],
247
- 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
+ },
248
293
  },
249
294
  {
250
295
  id: 'remember',
@@ -275,6 +320,19 @@ const config = {
275
320
  },
276
321
  ],
277
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
+ },
278
336
  {
279
337
  where: where(),
280
338
  match: ({context}) => context.marker == 'mentions' && context.evaluate,
@@ -294,7 +352,6 @@ const config = {
294
352
  }
295
353
 
296
354
  if (!context.value) {
297
- // retry()
298
355
  context.evalue = { marker: 'answerNotKnown' }
299
356
  return
300
357
  }
@@ -328,6 +385,23 @@ function initializer({config}) {
328
385
  }
329
386
  },
330
387
 
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
+
331
405
  recall: async (args) => {
332
406
  if (args.frameOfReference?.nameable_named) {
333
407
  const result = await e(args.frameOfReference)
@@ -358,10 +432,19 @@ knowledgeModule( {
358
432
  name: './stm.test.json',
359
433
  contents: stm_tests,
360
434
  checks: {
361
- context: [defaultContextCheck({ extra: ['pullFromContext', 'stm_id'] })],
362
- objects: [{ path: ['mentioned'] }],
363
- // objects: [defaultContextCheck({ extra: ['mentioned'] })],
364
- // objects: [{ property: 'mentioned', check: helpers.defaultContextCheckProperties }],
365
- },
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
+ },
366
449
  },
367
450
  })