ekms 8.0.0-beta.5 → 8.0.0-beta.50

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. package/common/animals.instance.json +2855 -1363
  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/avatar.js +5 -9
  6. package/common/characters.js +22 -28
  7. package/common/colors.instance.json +6978 -3493
  8. package/common/colors.js +4 -8
  9. package/common/colors.test.json +345 -780
  10. package/common/comparable.js +5 -22
  11. package/common/concept.js +120 -118
  12. package/common/countable.js +18 -12
  13. package/common/countable.test.json +1050 -0
  14. package/common/crew.instance.json +13032 -6570
  15. package/common/crew.js +36 -41
  16. package/common/crew.test.json +714 -452
  17. package/common/currency.js +27 -45
  18. package/common/dialogues.js +158 -282
  19. package/common/dimension.instance.json +273 -272
  20. package/common/dimension.js +16 -22
  21. package/common/dimension.test.json +446 -1640
  22. package/common/edible.instance.json +19911 -9877
  23. package/common/edible.js +3 -8
  24. package/common/emotions.instance.json +146 -128
  25. package/common/emotions.js +35 -38
  26. package/common/evaluate.instance.json +2 -0
  27. package/common/evaluate.js +49 -0
  28. package/common/evaluate.test.json +574 -0
  29. package/common/events.js +9 -13
  30. package/common/fastfood.instance.json +221141 -111240
  31. package/common/fastfood.js +70 -80
  32. package/common/formulas.instance.json +251 -265
  33. package/common/formulas.js +17 -24
  34. package/common/gdefaults.js +24 -26
  35. package/common/help.js +7 -12
  36. package/common/help.test.json +22 -22
  37. package/common/helpers/concept.js +9 -6
  38. package/common/helpers/dialogues.js +2 -3
  39. package/common/helpers/properties.js +52 -58
  40. package/common/helpers.js +1 -1
  41. package/common/hierarchy.js +16 -24
  42. package/common/javascript.js +11 -18
  43. package/common/kirk.instance.json +583 -289
  44. package/common/kirk.js +5 -8
  45. package/common/length.instance.json +5530 -4754
  46. package/common/length.js +4 -8
  47. package/common/listener.js +48 -0
  48. package/common/listener.test.json +104 -0
  49. package/common/math.instance.json +192 -1184
  50. package/common/math.js +15 -19
  51. package/common/meta.js +23 -47
  52. package/common/nameable.instance.json +2 -0
  53. package/common/nameable.js +135 -0
  54. package/common/nameable.test.json +2121 -0
  55. package/common/negation.instance.json +2 -0
  56. package/common/negation.js +38 -0
  57. package/common/negation.test.json +308 -0
  58. package/common/numbers.js +6 -10
  59. package/common/ordering.instance.json +340 -160
  60. package/common/ordering.js +80 -86
  61. package/common/people.instance.json +2066 -1014
  62. package/common/people.js +8 -13
  63. package/common/percentages.instance.json +2 -0
  64. package/common/percentages.js +53 -0
  65. package/common/percentages.test.json +751 -0
  66. package/common/pipboy.instance.json +7999 -6269
  67. package/common/pipboy.js +32 -43
  68. package/common/pokemon.instance.json +4207 -2069
  69. package/common/pokemon.js +7 -20
  70. package/common/pos.js +4 -5
  71. package/common/pressure.instance.json +1341 -1189
  72. package/common/pressure.js +4 -8
  73. package/common/properties.instance.json +130 -60
  74. package/common/properties.js +56 -133
  75. package/common/punctuation.js +6 -6
  76. package/common/reports.instance.json +595 -557
  77. package/common/reports.js +64 -89
  78. package/common/scorekeeper.js +18 -30
  79. package/common/sdefaults.js +16 -7
  80. package/common/sizeable.js +5 -9
  81. package/common/spock.instance.json +583 -289
  82. package/common/spock.js +5 -8
  83. package/common/stgame.js +19 -19
  84. package/common/stm.js +163 -26
  85. package/common/stm.test.json +1734 -1
  86. package/common/tell.js +14 -18
  87. package/common/temperature.instance.json +1461 -1293
  88. package/common/temperature.js +4 -8
  89. package/common/tester.js +3 -3
  90. package/common/testing.js +8 -12
  91. package/common/time.js +20 -25
  92. package/common/tokenize.js +4 -5
  93. package/common/ui.instance.json +257 -258
  94. package/common/ui.js +11 -17
  95. package/common/weight.instance.json +5212 -4233
  96. package/common/weight.js +4 -8
  97. package/common/yesno.js +5 -5
  98. package/main.js +59 -46
  99. package/package.json +27 -5
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,18 +10,15 @@ 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,
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,30 +64,27 @@ 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,
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,11 @@ 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 } = {}) {
31
43
  // TODO value should perhaps have been called id as in concept id and then value could be value
32
44
  if (value) {
33
45
  concept = { ...concept, pullFromContext: false }
@@ -43,49 +55,112 @@ class API {
43
55
  concept.value = value
44
56
  }
45
57
  concept.fromSTM = true
58
+ if (!concept.stm) {
59
+ concept.stm = {}
60
+ }
61
+ if (!concept.stm.id) {
62
+ concept.stm.id = this.getId()
63
+ }
64
+ this._objects.mentioned = this._objects.mentioned.filter( (context) => context.stm && context.stm.id != concept.stm.id )
46
65
  this._objects.mentioned.unshift(concept)
47
66
  }
48
67
 
49
- mentions(context, useHierarchy=true) {
68
+ mentions({ context, useHierarchy=true, all, condition = (() => true) } = {}) {
69
+ const findPrevious = !!context.stm_previous
70
+ const forAll = []
71
+ const addForAll = (context) => {
72
+ if (!forAll.find( (c) => c.stm.id == context.stm.id)) {
73
+ forAll.push(context)
74
+ }
75
+ }
76
+
50
77
  // care about value first
78
+ let findCounter = 0
51
79
  for (let m of this._objects.mentioned) {
52
- if (context.value && context.value == m.marker) {
53
- return m
80
+ if (context.value && (context.value == m.marker || context.value == m.value)) {
81
+ findCounter += 1
82
+ if (findPrevious && findCounter < 2) {
83
+ continue
84
+ }
85
+ if (condition()) {
86
+ if (all) {
87
+ allForAll(m)
88
+ } else {
89
+ return m
90
+ }
91
+ }
54
92
  }
55
93
  }
56
94
 
57
95
  if (!useHierarchy) {
58
96
  return
59
97
  }
98
+
60
99
  // care about marker second
100
+ findCounter = 0
61
101
  for (let m of this._objects.mentioned) {
62
102
  if (context.marker != 'unknown' && this.isA(m.marker, context.marker)) {
63
- return m
103
+ findCounter += 1
104
+ if (findPrevious && findCounter < 2) {
105
+ continue
106
+ }
107
+ if (condition(m)) {
108
+ if (all) {
109
+ addForAll(m)
110
+ } else {
111
+ return m
112
+ }
113
+ }
64
114
  }
65
115
  // if (context.types && context.types.includes(m.marker)) {
66
116
  if (context.types) {
67
117
  for (let parent of context.types) {
68
118
  if (parent != 'unknown' && this.isA(m.marker, parent)) {
69
- return m
119
+ findCounter += 1
120
+ if (findPrevious && findCounter < 2) {
121
+ continue
122
+ }
123
+ if (condition(m)) {
124
+ if (all) {
125
+ addForAll(m)
126
+ } else {
127
+ return m
128
+ }
129
+ }
70
130
  }
71
131
  }
72
132
  }
73
133
  }
74
134
 
135
+ findCounter = 0
75
136
  if (context.types && context.types.length == 1) {
76
137
  for (let m of this._objects.mentioned) {
77
138
  if (context.unknown) {
78
- return m
139
+ findCounter += 1
140
+ if (findPrevious && findCounter < 2) {
141
+ continue
142
+ }
143
+ if (condition(m)) {
144
+ if (all) {
145
+ addForAll(m)
146
+ } else {
147
+ return m
148
+ }
149
+ }
79
150
  }
80
151
  }
81
152
  }
153
+
154
+ if (all) {
155
+ return forAll
156
+ }
82
157
  }
83
158
 
84
159
  getVariable(name) {
85
160
  if (!name) {
86
161
  return
87
162
  }
88
- let valueNew = this.mentions({ marker: name, value: name }, false) || name
163
+ let valueNew = this.mentions({ context: { marker: name, value: name }, useHierarchy: false }) || name
89
164
  if (valueNew && valueNew.value) {
90
165
  valueNew = valueNew.value
91
166
  }
@@ -93,41 +168,103 @@ class API {
93
168
  }
94
169
 
95
170
  setVariable(name, value) {
96
- this.mentioned({ marker: name }, value)
171
+ this.mentioned({ context: { marker: name }, value })
97
172
  }
98
173
  }
99
174
 
100
175
  const api = new API()
101
176
 
102
- let createConfig = () => {
103
- const config = new Config({ name: 'stm' }, module)
104
- config.stop_auto_rebuild()
177
+ const config = {
178
+ name: 'stm',
179
+ operators: [
180
+ "([stm_previous|previous] ([memorable]))",
181
+ "(([memorable]) [stm_before|before])",
182
+ "([remember] (memorable/*))",
183
+ ],
184
+ words: {
185
+ literals: {
186
+ "m1": [{"id": "memorable", development: true, "initial": "{ value: 'm1' }" }],
187
+ "m2": [{"id": "memorable", development: true, "initial": "{ value: 'm2' }" }],
188
+ },
189
+ },
190
+ bridges: [
191
+ {
192
+ id: 'memorable',
193
+ isA: ['theAble'],
194
+ words: helpers.words('memorable')
195
+ },
196
+ {
197
+ id: 'remember',
198
+ bridge: "{ ...next(operator), postModifiers: ['rememberee'], rememberee: after[0] }",
199
+ isA: ['verby'],
200
+ semantic: async ({context, api, e}) => {
201
+ let value = (await e(context.rememberee)).evalue
202
+ if (value == context.rememberee.value) {
203
+ value = context.rememberee
204
+ }
205
+ api.mentioned({ context: value })
206
+ },
207
+ },
208
+ {
209
+ id: 'stm_previous',
210
+ bridge: '{ ...after[0], modifiers: ["stm_previous"], stm_previous: operator, pullFromContext: true }',
211
+ },
212
+ {
213
+ id: 'stm_before',
214
+ isA: ['adjective'],
215
+ bridge: '{ ...before[0], postModifiers: ["stm_previous"], stm_previous: operator, pullFromContext: true }',
216
+ },
217
+ ],
218
+ semantics: [
219
+ {
220
+ where: where(),
221
+ notes: 'pull from context',
222
+ // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
223
+ match: ({context, callId}) => context.pullFromContext && !context.same, // && context.value,
224
+ apply: async ({callId, context, kms, e, log, retry}) => {
225
+ context.value = kms.stm.api.mentions({ context })
226
+ if (!context.value) {
227
+ // retry()
228
+ context.value = { marker: 'answerNotKnown' }
229
+ return
230
+ }
231
+
232
+ const instance = await e(context.value)
233
+ if (instance.evalue && !instance.edefault) {
234
+ context.value = instance.evalue
235
+ }
236
+ if (context.evaluate) {
237
+ context.evalue = context.value
238
+ }
239
+ },
240
+ },
241
+ ],
242
+ }
105
243
 
106
- config.initializer( ({config}) => {
244
+ const initializer = ({config}) => {
107
245
  config.addArgs(({kms}) => ({
108
- mentioned: (context) => {
109
- kms.stm.api.mentioned(context)
246
+ mentioned: ({ context }) => {
247
+ kms.stm.api.mentioned({ context })
110
248
  },
111
- mentions: (context) => {
112
- return kms.stm.api.mentions(context)
249
+ mentions: ({ context }) => {
250
+ return kms.stm.api.mentions({ context })
113
251
  },
114
252
  }))
115
- })
116
- config.api = api
117
-
118
- config.restart_auto_rebuild()
119
- return config
120
- }
253
+ }
121
254
 
122
255
  knowledgeModule( {
256
+ config,
257
+ api: () => new API(),
258
+ includes: [evaluate, articles],
259
+ initializer,
260
+
123
261
  module,
124
262
  description: 'short term memory',
125
- createConfig,
126
263
  test: {
127
264
  name: './stm.test.json',
128
265
  contents: stm_tests,
129
266
  checks: {
130
- context: defaultContextCheck,
267
+ context: [...defaultContextCheck, 'pullFromContext', 'stm_id'],
131
268
  objects: ['mentioned'],
132
269
  },
133
270
  },