ekms 8.0.0-beta.9 → 8.0.0-beta.90

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 (112) hide show
  1. package/common/animals.instance.json +2915 -1553
  2. package/common/animals.js +17 -20
  3. package/common/articles.js +103 -0
  4. package/common/articles.test.json +310 -0
  5. package/common/asking.instance.json +2 -0
  6. package/common/asking.js +253 -0
  7. package/common/asking.test.json +2290 -0
  8. package/common/avatar.js +6 -10
  9. package/common/characters.js +23 -29
  10. package/common/colors.instance.json +7487 -4114
  11. package/common/colors.js +5 -9
  12. package/common/colors.test.json +345 -780
  13. package/common/comparable.instance.json +1750 -0
  14. package/common/comparable.js +36 -28
  15. package/common/comparable.test.json +1196 -2
  16. package/common/concept.js +121 -119
  17. package/common/conjunction.instance.json +2 -0
  18. package/common/conjunction.js +104 -0
  19. package/common/conjunction.test.json +322 -0
  20. package/common/countable.js +20 -14
  21. package/common/countable.test.json +1050 -0
  22. package/common/crew.instance.json +13553 -7026
  23. package/common/crew.js +37 -42
  24. package/common/crew.test.json +714 -452
  25. package/common/currency.js +28 -46
  26. package/common/dialogues.js +150 -426
  27. package/common/dialogues.test.json +0 -786
  28. package/common/dimension.instance.json +491 -262
  29. package/common/dimension.js +22 -24
  30. package/common/dimension.test.json +508 -1702
  31. package/common/edible.instance.json +20446 -10806
  32. package/common/edible.js +4 -9
  33. package/common/emotions.instance.json +192 -124
  34. package/common/emotions.js +36 -39
  35. package/common/evaluate.instance.json +2 -0
  36. package/common/evaluate.js +53 -0
  37. package/common/evaluate.test.json +574 -0
  38. package/common/events.js +11 -15
  39. package/common/fastfood.instance.json +222642 -113618
  40. package/common/fastfood.js +76 -86
  41. package/common/fastfood.test.json +268 -90
  42. package/common/formulas.instance.json +443 -247
  43. package/common/formulas.js +20 -27
  44. package/common/gdefaults.js +40 -27
  45. package/common/help.js +9 -14
  46. package/common/help.test.json +65 -16
  47. package/common/helpers/concept.js +10 -7
  48. package/common/helpers/dialogues.js +5 -3
  49. package/common/helpers/properties.js +67 -64
  50. package/common/helpers.js +35 -24
  51. package/common/hierarchy.js +17 -25
  52. package/common/javascript.js +12 -19
  53. package/common/kirk.instance.json +583 -299
  54. package/common/kirk.js +6 -9
  55. package/common/length.instance.json +9005 -5001
  56. package/common/length.js +5 -9
  57. package/common/listener.js +48 -0
  58. package/common/listener.test.json +104 -0
  59. package/common/math.instance.json +406 -1178
  60. package/common/math.js +17 -21
  61. package/common/meta.js +24 -48
  62. package/common/nameable.instance.json +2 -0
  63. package/common/nameable.js +144 -0
  64. package/common/nameable.test.json +3191 -0
  65. package/common/negation.js +11 -7
  66. package/common/numbers.js +28 -32
  67. package/common/ordering.instance.json +443 -343
  68. package/common/ordering.js +81 -87
  69. package/common/ordinals.instance.json +2 -0
  70. package/common/ordinals.js +60 -0
  71. package/common/ordinals.test.json +306 -0
  72. package/common/people.instance.json +2210 -1150
  73. package/common/people.js +9 -14
  74. package/common/percentages.instance.json +2 -0
  75. package/common/percentages.js +53 -0
  76. package/common/percentages.test.json +751 -0
  77. package/common/pipboy.instance.json +11845 -6590
  78. package/common/pipboy.js +51 -62
  79. package/common/pokemon.instance.json +4300 -2285
  80. package/common/pokemon.js +8 -21
  81. package/common/pos.js +16 -14
  82. package/common/pressure.instance.json +2325 -1340
  83. package/common/pressure.js +5 -9
  84. package/common/properties.instance.json +148 -88
  85. package/common/properties.js +149 -160
  86. package/common/punctuation.js +16 -8
  87. package/common/reports.instance.json +1019 -551
  88. package/common/reports.js +77 -101
  89. package/common/reports.test.json +15623 -10458
  90. package/common/scorekeeper.js +19 -31
  91. package/common/sdefaults.js +17 -8
  92. package/common/sizeable.js +7 -11
  93. package/common/spock.instance.json +582 -298
  94. package/common/spock.js +6 -9
  95. package/common/stgame.js +20 -20
  96. package/common/stm.js +173 -31
  97. package/common/stm.test.json +1734 -1
  98. package/common/tell.js +15 -19
  99. package/common/temperature.instance.json +2430 -1429
  100. package/common/temperature.js +5 -9
  101. package/common/tester.js +15 -4
  102. package/common/testing.js +8 -12
  103. package/common/time.js +21 -26
  104. package/common/tokenize.js +6 -7
  105. package/common/ui.instance.json +150 -463
  106. package/common/ui.js +22 -33
  107. package/common/ui.test.json +641 -5357
  108. package/common/weight.instance.json +8034 -4503
  109. package/common/weight.js +5 -9
  110. package/common/yesno.js +6 -6
  111. package/main.js +20 -4
  112. package/package.json +37 -6
package/common/spock.js CHANGED
@@ -1,4 +1,4 @@
1
- const { Config, knowledgeModule, where } = require('./runtime').theprogrammablemind
1
+ const { knowledgeModule, where } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const crew = require('./crew')
4
4
  const spock_tests = require('./spock.test.json')
@@ -10,23 +10,20 @@ const template = {
10
10
  ]
11
11
  };
12
12
 
13
- const createConfig = () => {
14
- const config = new Config({ name: 'spock', }, module)
15
- config.add(crew())
16
- return config
17
- }
18
-
19
13
  spock_instance.base = 'crew'
20
14
  // config.load(template, spock_instance)
15
+
21
16
  knowledgeModule( {
17
+ config: { name: 'spock', },
18
+ includes: [crew],
19
+
22
20
  module,
23
21
  description: 'Spock Simulator using a KM template',
24
- createConfig,
25
22
  test: {
26
23
  name: './spock.test.json',
27
24
  contents: spock_tests,
28
25
  checks: {
29
- context: defaultContextCheck,
26
+ context: defaultContextCheck(),
30
27
  },
31
28
  },
32
29
  template: {
package/common/stgame.js CHANGED
@@ -1,4 +1,4 @@
1
- const { Config, knowledgeModule, where } = require('./runtime').theprogrammablemind
1
+ const { knowledgeModule, where, process : clientProcess } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const createCharacters = require('./characters')
4
4
  const stgame_tests = require('./stgame.test.json')
@@ -31,7 +31,8 @@ class KirkAPI {
31
31
 
32
32
  process(config, utterance) {
33
33
  this.kirk.server(config.getServer(), config.getAPIKey())
34
- return this.kirk.process(utterance, { credentials: this.credentials })
34
+ // return this.kirk.process(utterance, { credentials: this.credentials })
35
+ return clientProcess(this.kirk, utterance, { credentials: this.credentials })
35
36
  }
36
37
 
37
38
  response({km, context, result}) {
@@ -52,8 +53,10 @@ class SpockAPI {
52
53
  }
53
54
 
54
55
  process(config, utterance) {
56
+ debugger
55
57
  this.spock.server(config.getServer(), config.getAPIKey())
56
- return this.spock.process(utterance, { credentials: this.credentials })
58
+ // return this.spock.process(utterance, { credentials: this.credentials })
59
+ return clientProcess(this.spock, utterance, { credentials: this.credentials })
57
60
  }
58
61
 
59
62
  response({km, context, result}) {
@@ -61,35 +64,32 @@ class SpockAPI {
61
64
  }
62
65
  }
63
66
 
67
+ const createCharactersHelper = async () => {
68
+ const characters = await createCharacters()
69
+ const kirk = await createKirk()
70
+ const spock = await createSpock()
71
+ await characters.setApi(() => new KirkAPI(kirk))
72
+ await characters.setApi(() => new SpockAPI(spock))
73
+ return characters
74
+ }
64
75
 
65
- const createConfig = () => {
66
- const characters = createCharacters()
67
- const kirk = createKirk()
68
- const spock = createSpock()
69
- characters.api = new KirkAPI(kirk);
70
- characters.api = new SpockAPI(spock);
71
- const config = new Config({
76
+ knowledgeModule( {
77
+ config: {
72
78
  name: 'stgame',
73
79
  operators: [ "([a])" ],
74
80
  bridges: [ { id: 'a', level: 0, bridge: "{ ...next(operator) }" } ],
75
81
  words: {"?": [{"id": "a", "initial": "{}" }]},
76
- }, module)
77
- config.stop_auto_rebuild()
78
- config.api = api
79
- config.add(characters)
80
- config.restart_auto_rebuild()
81
- return config
82
- }
82
+ },
83
+ api: () => api,
84
+ includes: [createCharactersHelper],
83
85
 
84
- knowledgeModule( {
85
86
  module,
86
87
  description: 'Game simulator for trek-like characters',
87
- createConfig,
88
88
  test: {
89
89
  name: './stgame.test.json',
90
90
  contents: stgame_tests,
91
91
  checks: {
92
- context: defaultContextCheck,
92
+ context: defaultContextCheck(),
93
93
  },
94
94
  },
95
95
  })
package/common/stm.js CHANGED
@@ -1,5 +1,8 @@
1
- const { Config, knowledgeModule, where } = require('./runtime').theprogrammablemind
1
+ const { knowledgeModule, where } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
+ const helpers = require('./helpers')
4
+ const articles = require('./articles')
5
+ const evaluate = require('./evaluate')
3
6
  const stm_tests = require('./stm.test.json')
4
7
 
5
8
  class API {
@@ -10,6 +13,11 @@ class API {
10
13
  ]
11
14
  this._objects.mentioned = []
12
15
  this._objects.variables = {}
16
+ this.idCounter = 0
17
+ }
18
+
19
+ getId() {
20
+ return ++this.idCounter
13
21
  }
14
22
 
15
23
  addIsA(isA) {
@@ -27,7 +35,14 @@ class API {
27
35
  return false
28
36
  }
29
37
 
30
- mentioned(concept, value = undefined) {
38
+ getByType(type) {
39
+ return this._objects.mentioned.filter( (context) => this.isA(context.marker, type) )
40
+ }
41
+
42
+ mentioned({ context:concept, value=null, frameOfReference } = {}) {
43
+ if (!frameOfReference) {
44
+ frameOfReference = this._objects
45
+ }
31
46
  // TODO value should perhaps have been called id as in concept id and then value could be value
32
47
  if (value) {
33
48
  concept = { ...concept, pullFromContext: false }
@@ -43,49 +58,114 @@ class API {
43
58
  concept.value = value
44
59
  }
45
60
  concept.fromSTM = true
46
- this._objects.mentioned.unshift(concept)
61
+ if (!concept.stm) {
62
+ concept.stm = {}
63
+ }
64
+ if (!concept.stm.id) {
65
+ concept.stm.id = this.getId()
66
+ }
67
+ frameOfReference.mentioned = (frameOfReference.mentioned || []).filter( (context) => context.stm && context.stm.id != concept.stm.id )
68
+ frameOfReference.mentioned.unshift(concept)
47
69
  }
48
70
 
49
- mentions(context, useHierarchy=true) {
71
+ mentions({ context, frameOfReference, useHierarchy=true, all, condition = (() => true) } = {}) {
72
+ let mentioned = frameOfReference?.mentioned || this._objects.mentioned
73
+
74
+ const findPrevious = !!context.stm_previous
75
+ const forAll = []
76
+ const addForAll = (context) => {
77
+ if (!forAll.find( (c) => c.stm.id == context.stm.id)) {
78
+ forAll.push(context)
79
+ }
80
+ }
81
+
50
82
  // care about value first
51
- for (let m of this._objects.mentioned) {
52
- if (context.value && context.value == m.marker) {
53
- return m
83
+ let findCounter = 0
84
+ for (let m of mentioned) {
85
+ if (context.value && (context.value == m.marker || context.value == m.value)) {
86
+ findCounter += 1
87
+ if (findPrevious && findCounter < 2) {
88
+ continue
89
+ }
90
+ if (condition()) {
91
+ if (all) {
92
+ allForAll(m)
93
+ } else {
94
+ return m
95
+ }
96
+ }
54
97
  }
55
98
  }
56
99
 
57
100
  if (!useHierarchy) {
58
101
  return
59
102
  }
103
+
60
104
  // care about marker second
61
- for (let m of this._objects.mentioned) {
105
+ findCounter = 0
106
+ for (let m of mentioned) {
62
107
  if (context.marker != 'unknown' && this.isA(m.marker, context.marker)) {
63
- return m
108
+ findCounter += 1
109
+ if (findPrevious && findCounter < 2) {
110
+ continue
111
+ }
112
+ if (condition(m)) {
113
+ if (all) {
114
+ addForAll(m)
115
+ } else {
116
+ return m
117
+ }
118
+ }
64
119
  }
65
120
  // if (context.types && context.types.includes(m.marker)) {
66
121
  if (context.types) {
67
122
  for (let parent of context.types) {
68
123
  if (parent != 'unknown' && this.isA(m.marker, parent)) {
69
- return m
124
+ findCounter += 1
125
+ if (findPrevious && findCounter < 2) {
126
+ continue
127
+ }
128
+ if (condition(m)) {
129
+ if (all) {
130
+ addForAll(m)
131
+ } else {
132
+ return m
133
+ }
134
+ }
70
135
  }
71
136
  }
72
137
  }
73
138
  }
74
139
 
140
+ findCounter = 0
75
141
  if (context.types && context.types.length == 1) {
76
- for (let m of this._objects.mentioned) {
142
+ for (let m of mentioned) {
77
143
  if (context.unknown) {
78
- return m
144
+ findCounter += 1
145
+ if (findPrevious && findCounter < 2) {
146
+ continue
147
+ }
148
+ if (condition(m)) {
149
+ if (all) {
150
+ addForAll(m)
151
+ } else {
152
+ return m
153
+ }
154
+ }
79
155
  }
80
156
  }
81
157
  }
158
+
159
+ if (all) {
160
+ return forAll
161
+ }
82
162
  }
83
163
 
84
164
  getVariable(name) {
85
165
  if (!name) {
86
166
  return
87
167
  }
88
- let valueNew = this.mentions({ marker: name, value: name }, false) || name
168
+ let valueNew = this.mentions({ context: { marker: name, value: name }, useHierarchy: false }) || name
89
169
  if (valueNew && valueNew.value) {
90
170
  valueNew = valueNew.value
91
171
  }
@@ -93,42 +173,104 @@ class API {
93
173
  }
94
174
 
95
175
  setVariable(name, value) {
96
- this.mentioned({ marker: name }, value)
176
+ this.mentioned({ context: { marker: name }, value })
97
177
  }
98
178
  }
99
179
 
100
180
  const api = new API()
101
181
 
102
- let createConfig = () => {
103
- const config = new Config({ name: 'stm' }, module)
104
- config.stop_auto_rebuild()
182
+ const config = {
183
+ name: 'stm',
184
+ operators: [
185
+ "([stm_previous|previous] ([memorable]))",
186
+ "(([memorable]) [stm_before|before])",
187
+ "([remember] (memorable/*))",
188
+ ],
189
+ words: {
190
+ literals: {
191
+ "m1": [{"id": "memorable", development: true, "initial": "{ value: 'm1' }" }],
192
+ "m2": [{"id": "memorable", development: true, "initial": "{ value: 'm2' }" }],
193
+ },
194
+ },
195
+ bridges: [
196
+ {
197
+ id: 'memorable',
198
+ isA: ['theAble'],
199
+ words: helpers.words('memorable')
200
+ },
201
+ {
202
+ id: 'remember',
203
+ bridge: "{ ...next(operator), postModifiers: ['rememberee'], rememberee: after[0] }",
204
+ isA: ['verb'],
205
+ semantic: async ({context, api, e}) => {
206
+ let value = (await e(context.rememberee)).evalue
207
+ if (value == context.rememberee.value) {
208
+ value = context.rememberee
209
+ }
210
+ api.mentioned({ context: value })
211
+ },
212
+ },
213
+ {
214
+ id: 'stm_previous',
215
+ bridge: '{ ...after[0], modifiers: ["stm_previous"], stm_previous: operator, pullFromContext: true }',
216
+ },
217
+ {
218
+ id: 'stm_before',
219
+ isA: ['adjective'],
220
+ bridge: '{ ...before[0], postModifiers: ["stm_previous"], stm_previous: operator, pullFromContext: true }',
221
+ },
222
+ ],
223
+ semantics: [
224
+ {
225
+ where: where(),
226
+ notes: 'pull from context',
227
+ // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
228
+ match: ({context, callId}) => context.pullFromContext && !context.same, // && context.value,
229
+ apply: async ({callId, context, kms, e, log, retry}) => {
230
+ context.value = kms.stm.api.mentions({ context })
231
+ if (!context.value) {
232
+ // retry()
233
+ context.value = { marker: 'answerNotKnown' }
234
+ return
235
+ }
236
+
237
+ const instance = await e(context.value)
238
+ if (instance.evalue && !instance.edefault) {
239
+ context.value = instance.evalue
240
+ }
241
+ if (context.evaluate) {
242
+ context.evalue = context.value
243
+ }
244
+ },
245
+ },
246
+ ],
247
+ }
105
248
 
106
- config.initializer( ({config}) => {
249
+ const initializer = ({config}) => {
107
250
  config.addArgs(({kms}) => ({
108
- mentioned: (context) => {
109
- kms.stm.api.mentioned(context)
251
+ mentioned: (args) => {
252
+ kms.stm.api.mentioned(args)
110
253
  },
111
- mentions: (context) => {
112
- return kms.stm.api.mentions(context)
254
+ mentions: (args) => {
255
+ return kms.stm.api.mentions(args)
113
256
  },
114
257
  }))
115
- })
116
- config.api = api
117
-
118
- config.restart_auto_rebuild()
119
- return config
120
- }
258
+ }
121
259
 
122
260
  knowledgeModule( {
261
+ config,
262
+ api: () => new API(),
263
+ includes: [evaluate, articles],
264
+ initializer,
265
+
123
266
  module,
124
267
  description: 'short term memory',
125
- createConfig,
126
268
  test: {
127
269
  name: './stm.test.json',
128
270
  contents: stm_tests,
129
271
  checks: {
130
- context: defaultContextCheck,
131
- objects: ['mentioned'],
272
+ context: [...defaultContextCheck(), 'pullFromContext', 'stm_id'],
273
+ objects: [{ property: 'mentioned', filter: helpers.defaultContextCheckProperties }],
132
274
  },
133
275
  },
134
276
  })