ekms 8.0.0 → 8.1.0-beta.1

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 (124) hide show
  1. package/common/animals.instance.json +3055 -1651
  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 -30
  10. package/common/colors.instance.json +25666 -0
  11. package/common/colors.js +67 -0
  12. package/common/colors.test.json +4425 -0
  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/concept.test.json +688 -0
  18. package/common/conjunction.instance.json +2 -0
  19. package/common/conjunction.js +104 -0
  20. package/common/conjunction.test.json +322 -0
  21. package/common/countable.js +20 -14
  22. package/common/countable.test.json +1050 -0
  23. package/common/crew.instance.json +16432 -9850
  24. package/common/crew.js +39 -42
  25. package/common/crew.test.json +714 -452
  26. package/common/currency.js +28 -46
  27. package/common/dialogues.js +187 -429
  28. package/common/dialogues.test.json +684 -450
  29. package/common/dimension.instance.json +517 -289
  30. package/common/dimension.js +22 -24
  31. package/common/dimension.test.json +727 -1944
  32. package/common/edible.instance.json +20506 -10664
  33. package/common/edible.js +4 -9
  34. package/common/emotions.instance.json +195 -123
  35. package/common/emotions.js +36 -39
  36. package/common/evaluate.instance.json +2 -0
  37. package/common/evaluate.js +53 -0
  38. package/common/evaluate.test.json +574 -0
  39. package/common/events.js +11 -15
  40. package/common/fastfood.instance.json +223185 -113172
  41. package/common/fastfood.js +77 -87
  42. package/common/fastfood.test.json +8205 -3733
  43. package/common/formulas.instance.json +444 -244
  44. package/common/formulas.js +20 -27
  45. package/common/formulas.test.json +1027 -955
  46. package/common/gdefaults.js +45 -32
  47. package/common/help.js +9 -14
  48. package/common/help.test.json +71 -18
  49. package/common/helpers/concept.js +37 -10
  50. package/common/helpers/dialogues.js +22 -4
  51. package/common/helpers/formulas.js +0 -14
  52. package/common/helpers/meta.js +0 -1
  53. package/common/helpers/properties.js +92 -84
  54. package/common/helpers.js +35 -24
  55. package/common/hierarchy.js +18 -25
  56. package/common/javascript.js +12 -19
  57. package/common/kirk.instance.json +583 -300
  58. package/common/kirk.js +6 -9
  59. package/common/length.instance.json +8995 -4964
  60. package/common/length.js +5 -9
  61. package/common/listener.js +48 -0
  62. package/common/listener.test.json +104 -0
  63. package/common/math.instance.json +409 -1202
  64. package/common/math.js +17 -21
  65. package/common/meta.js +24 -50
  66. package/common/nameable.instance.json +2 -0
  67. package/common/nameable.js +144 -0
  68. package/common/nameable.test.json +3191 -0
  69. package/common/negation.instance.json +2 -0
  70. package/common/negation.js +38 -0
  71. package/common/negation.test.json +308 -0
  72. package/common/numbers.js +28 -32
  73. package/common/ordering.instance.json +459 -274
  74. package/common/ordering.js +81 -87
  75. package/common/ordinals.instance.json +2 -0
  76. package/common/ordinals.js +61 -0
  77. package/common/ordinals.test.json +412 -0
  78. package/common/people.instance.json +2138 -1321
  79. package/common/people.js +9 -14
  80. package/common/people.test.json +1815 -1073
  81. package/common/percentages.instance.json +2 -0
  82. package/common/percentages.js +53 -0
  83. package/common/percentages.test.json +751 -0
  84. package/common/pipboy.instance.json +12261 -6898
  85. package/common/pipboy.js +53 -62
  86. package/common/pipboy.test.json +2835 -0
  87. package/common/pokemon.instance.json +4432 -2351
  88. package/common/pokemon.js +8 -21
  89. package/common/pos.js +16 -14
  90. package/common/pressure.instance.json +2311 -1303
  91. package/common/pressure.js +5 -9
  92. package/common/properties.instance.json +151 -87
  93. package/common/properties.js +164 -167
  94. package/common/properties.test.json +17605 -4030
  95. package/common/punctuation.js +24 -8
  96. package/common/punctuation.test.json +233 -5
  97. package/common/reports.instance.json +1037 -551
  98. package/common/reports.js +77 -103
  99. package/common/reports.test.json +15623 -10458
  100. package/common/scorekeeper.js +19 -31
  101. package/common/sdefaults.js +17 -8
  102. package/common/sizeable.js +13 -12
  103. package/common/spock.instance.json +582 -299
  104. package/common/spock.js +6 -9
  105. package/common/stgame.js +20 -20
  106. package/common/stm.js +182 -29
  107. package/common/stm.test.json +1734 -1
  108. package/common/tell.js +15 -19
  109. package/common/temperature.instance.json +2379 -1355
  110. package/common/temperature.js +5 -9
  111. package/common/tester.js +15 -4
  112. package/common/testing.js +8 -13
  113. package/common/time.js +21 -26
  114. package/common/tokenize.js +8 -8
  115. package/common/tokenize.test.json +86 -1
  116. package/common/ui.instance.json +151 -460
  117. package/common/ui.js +22 -34
  118. package/common/ui.test.json +641 -5357
  119. package/common/weight.instance.json +7957 -4350
  120. package/common/weight.js +5 -9
  121. package/common/weight.test.json +242 -238
  122. package/common/yesno.js +6 -6
  123. package/main.js +68 -45
  124. package/package.json +44 -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,8 +35,20 @@ class API {
27
35
  return false
28
36
  }
29
37
 
30
- mentioned(concept, value = undefined) {
31
- concept = { ...concept, pullFromContext: false }
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
+ }
46
+ // TODO value should perhaps have been called id as in concept id and then value could be value
47
+ if (value) {
48
+ concept = { ...concept, pullFromContext: false }
49
+ } else {
50
+ concept.pullFromContext = false
51
+ }
32
52
  if (value) {
33
53
  if (concept.marker == 'unknown') {
34
54
  if (concept.value) {
@@ -37,48 +57,115 @@ class API {
37
57
  }
38
58
  concept.value = value
39
59
  }
40
- this._objects.mentioned.unshift(concept)
60
+ concept.fromSTM = true
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)
41
69
  }
42
70
 
43
- 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
+
44
82
  // care about value first
45
- for (let m of this._objects.mentioned) {
46
- if (context.value && context.value == m.marker) {
47
- return { ...m, fromSTM: true }
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
+ }
48
97
  }
49
98
  }
50
99
 
51
100
  if (!useHierarchy) {
52
101
  return
53
102
  }
103
+
54
104
  // care about marker second
55
- for (let m of this._objects.mentioned) {
105
+ findCounter = 0
106
+ for (let m of mentioned) {
56
107
  if (context.marker != 'unknown' && this.isA(m.marker, context.marker)) {
57
- return { ...m, fromSTM: true }
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
+ }
58
119
  }
59
120
  // if (context.types && context.types.includes(m.marker)) {
60
121
  if (context.types) {
61
122
  for (let parent of context.types) {
62
123
  if (parent != 'unknown' && this.isA(m.marker, parent)) {
63
- return { ...m, fromSTM: true }
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
+ }
64
135
  }
65
136
  }
66
137
  }
67
138
  }
139
+
140
+ findCounter = 0
68
141
  if (context.types && context.types.length == 1) {
69
- for (let m of this._objects.mentioned) {
142
+ for (let m of mentioned) {
70
143
  if (context.unknown) {
71
- return { ...m, fromSTM: true }
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
+ }
72
155
  }
73
156
  }
74
157
  }
158
+
159
+ if (all) {
160
+ return forAll
161
+ }
75
162
  }
76
163
 
77
164
  getVariable(name) {
78
165
  if (!name) {
79
166
  return
80
167
  }
81
- let valueNew = this.mentions({ marker: name, value: name }, false) || name
168
+ let valueNew = this.mentions({ context: { marker: name, value: name }, useHierarchy: false }) || name
82
169
  if (valueNew && valueNew.value) {
83
170
  valueNew = valueNew.value
84
171
  }
@@ -86,38 +173,104 @@ class API {
86
173
  }
87
174
 
88
175
  setVariable(name, value) {
89
- this.mentioned({ marker: name }, value)
176
+ this.mentioned({ context: { marker: name }, value })
90
177
  }
91
178
  }
92
179
 
93
180
  const api = new API()
94
181
 
95
- let createConfig = () => {
96
- const config = new Config({ name: 'stm' }, module)
97
- 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
+ }
98
248
 
99
- config.initializer( ({config}) => {
249
+ const initializer = ({config}) => {
100
250
  config.addArgs(({kms}) => ({
101
- mentioned: (context) => {
102
- kms.stm.api.mentioned(context)
251
+ mentioned: (args) => {
252
+ kms.stm.api.mentioned(args)
253
+ },
254
+ mentions: (args) => {
255
+ return kms.stm.api.mentions(args)
103
256
  },
104
257
  }))
105
- })
106
- config.api = api
107
-
108
- config.restart_auto_rebuild()
109
- return config
110
- }
258
+ }
111
259
 
112
260
  knowledgeModule( {
261
+ config,
262
+ api: () => new API(),
263
+ includes: [evaluate, articles],
264
+ initializer,
265
+
113
266
  module,
114
267
  description: 'short term memory',
115
- createConfig,
116
268
  test: {
117
269
  name: './stm.test.json',
118
270
  contents: stm_tests,
119
271
  checks: {
120
- context: defaultContextCheck,
272
+ context: [...defaultContextCheck(), 'pullFromContext', 'stm_id'],
273
+ objects: [{ property: 'mentioned', filter: helpers.defaultContextCheckProperties }],
121
274
  },
122
275
  },
123
276
  })