ekms 8.0.0-beta.6 → 8.0.0-beta.60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. package/common/animals.instance.json +2871 -1379
  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 +7170 -3657
  8. package/common/colors.js +4 -8
  9. package/common/colors.test.json +345 -780
  10. package/common/comparable.instance.json +1738 -0
  11. package/common/comparable.js +46 -27
  12. package/common/comparable.test.json +438 -2
  13. package/common/concept.js +120 -118
  14. package/common/countable.js +19 -13
  15. package/common/countable.test.json +1050 -0
  16. package/common/crew.instance.json +13066 -6598
  17. package/common/crew.js +36 -41
  18. package/common/crew.test.json +714 -452
  19. package/common/currency.js +27 -45
  20. package/common/dialogues.js +161 -285
  21. package/common/dimension.instance.json +474 -253
  22. package/common/dimension.js +16 -22
  23. package/common/dimension.test.json +446 -1640
  24. package/common/edible.instance.json +20059 -10007
  25. package/common/edible.js +3 -8
  26. package/common/emotions.instance.json +147 -129
  27. package/common/emotions.js +35 -38
  28. package/common/evaluate.instance.json +2 -0
  29. package/common/evaluate.js +49 -0
  30. package/common/evaluate.test.json +574 -0
  31. package/common/events.js +10 -14
  32. package/common/fastfood.instance.json +221967 -111264
  33. package/common/fastfood.js +74 -84
  34. package/common/fastfood.test.json +268 -90
  35. package/common/formulas.instance.json +455 -249
  36. package/common/formulas.js +19 -26
  37. package/common/gdefaults.js +24 -26
  38. package/common/help.js +7 -12
  39. package/common/help.test.json +22 -22
  40. package/common/helpers/concept.js +10 -7
  41. package/common/helpers/dialogues.js +2 -3
  42. package/common/helpers/properties.js +54 -62
  43. package/common/helpers.js +6 -5
  44. package/common/hierarchy.js +16 -24
  45. package/common/javascript.js +11 -18
  46. package/common/kirk.instance.json +584 -290
  47. package/common/kirk.js +5 -8
  48. package/common/length.instance.json +8834 -4757
  49. package/common/length.js +4 -8
  50. package/common/listener.js +48 -0
  51. package/common/listener.test.json +104 -0
  52. package/common/math.instance.json +425 -1187
  53. package/common/math.js +16 -20
  54. package/common/meta.js +23 -47
  55. package/common/nameable.instance.json +2 -0
  56. package/common/nameable.js +135 -0
  57. package/common/nameable.test.json +2121 -0
  58. package/common/negation.instance.json +2 -0
  59. package/common/negation.js +38 -0
  60. package/common/negation.test.json +308 -0
  61. package/common/numbers.js +27 -31
  62. package/common/ordering.instance.json +366 -246
  63. package/common/ordering.js +80 -86
  64. package/common/people.instance.json +2134 -1022
  65. package/common/people.js +8 -13
  66. package/common/percentages.instance.json +2 -0
  67. package/common/percentages.js +53 -0
  68. package/common/percentages.test.json +751 -0
  69. package/common/pipboy.instance.json +11777 -6289
  70. package/common/pipboy.js +48 -59
  71. package/common/pokemon.instance.json +4226 -2081
  72. package/common/pokemon.js +7 -20
  73. package/common/pos.js +12 -13
  74. package/common/pressure.instance.json +2208 -1175
  75. package/common/pressure.js +4 -8
  76. package/common/properties.instance.json +131 -61
  77. package/common/properties.js +57 -134
  78. package/common/punctuation.js +6 -6
  79. package/common/reports.instance.json +1018 -530
  80. package/common/reports.js +73 -97
  81. package/common/scorekeeper.js +18 -30
  82. package/common/sdefaults.js +16 -7
  83. package/common/sizeable.js +6 -10
  84. package/common/spock.instance.json +584 -290
  85. package/common/spock.js +5 -8
  86. package/common/stgame.js +19 -19
  87. package/common/stm.js +164 -27
  88. package/common/stm.test.json +1734 -1
  89. package/common/tell.js +14 -18
  90. package/common/temperature.instance.json +2271 -1222
  91. package/common/temperature.js +4 -8
  92. package/common/tester.js +3 -3
  93. package/common/testing.js +8 -12
  94. package/common/time.js +20 -25
  95. package/common/tokenize.js +4 -5
  96. package/common/ui.instance.json +459 -240
  97. package/common/ui.js +16 -22
  98. package/common/weight.instance.json +7646 -4026
  99. package/common/weight.js +4 -8
  100. package/common/yesno.js +5 -5
  101. package/main.js +59 -46
  102. package/package.json +28 -5
package/common/math.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 dialogues = require('./dialogues')
4
4
  const numbers = require('./numbers')
@@ -33,22 +33,22 @@ const mathematicalOperator = (name, words, apply, before = []) => [
33
33
  id: `${name}Operator`, level: 0,
34
34
  bridge: `{ ...next(operator), marker: next(operator('${name}Expression')), types: lub(append(['mathematicalExpression'], operator.types, before[0].types, after[0].types)), value: null, x: before[0], y: after[0], number: 'one', isResponse: true, evaluate: true }` ,
35
35
  // bridge: `{ ...next(operator), marker: next(operator('${name}Expression')), value: null, x: before[0], y: after[0], number: 'one', isResponse: true, evaluate: true }` ,
36
- isA: ['mathematicalOperator'],
36
+ isA: ['mathematical_operator'],
37
37
  before,
38
38
  localHierarchy: [ ['unknown', 'number'] ],
39
39
  // levelSpecificHierarchy: [[1, 'mathematicalExpression']],
40
40
  words,
41
- generatorp: ({gp, context}) => context.word,
41
+ generatorp: ({context}) => context.word,
42
42
  },
43
43
  {
44
44
  where: where(),
45
45
  id: `${name}Expression`, level: 0,
46
46
  bridge: "{ ...next(operator) }" ,
47
47
  isA: ['mathematicalExpression'],
48
- generatorp: ({gp, context}) => `${gp(context.x)} ${context.word} ${gp(context.y)}`,
49
- evaluator: ({e, context}) => {
50
- const x = toValue(e(context.x))
51
- const y = toValue(e(context.y))
48
+ generatorp: async ({gp, context}) => `${await gp(context.x)} ${context.word} ${await gp(context.y)}`,
49
+ evaluator: async ({e, context}) => {
50
+ const x = toValue(await e(context.x))
51
+ const y = toValue(await e(context.y))
52
52
  if (!x || !y) {
53
53
  // context.evalue = { ...context, paraphrase: true, x: { ...context.x, value: x }, y: { ...context.y, value: y } }
54
54
  context.isResponse = false
@@ -69,11 +69,11 @@ const mathematicalOperator = (name, words, apply, before = []) => [
69
69
  }
70
70
  ]
71
71
 
72
- let configStruct = {
72
+ let config = {
73
73
  name: 'math',
74
74
  operators: [
75
75
  "([mathematicalExpression])",
76
- "([mathematicalOperator])",
76
+ "([mathematical_operator])",
77
77
  "(([number|]) [plusOperator] ([number|]))",
78
78
  "(([number|]) [minusOperator] ([number|]))",
79
79
  "(([number|]) [timesOperator] ([number|]))",
@@ -92,8 +92,8 @@ let configStruct = {
92
92
  isA: ['concept', 'number'],
93
93
  },
94
94
  {
95
- id: "mathematicalOperator",
96
- before: ['verby'],
95
+ id: "mathematical_operator",
96
+ before: ['verb'],
97
97
  after: ['adjective'],
98
98
  },
99
99
  { id: "x", isA: ['number'], level: 0, bridge: '{ ...next(operator) }', development: true},
@@ -108,20 +108,16 @@ let configStruct = {
108
108
  const template = {
109
109
  configs: [
110
110
  "mathematical modifies operator",
111
- "* + / and - are mathematical operators",
112
- configStruct,
111
+ config,
112
+ // "* + / and - are mathematical operators",
113
113
  ]
114
114
  }
115
115
 
116
- const createConfig = () => {
117
- const config = new Config({ name: 'math' }, module)
118
- config.add(numbers(), dialogues(), punctuation(), countable(), comparable())
119
- return config
120
- }
121
-
122
116
  knowledgeModule( {
117
+ config: { name: 'math' },
118
+ includes: [numbers, dialogues, punctuation, countable, comparable],
119
+
123
120
  module,
124
- createConfig,
125
121
  description: 'talking about math',
126
122
  template: { template, instance },
127
123
  test: {
package/common/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- const { Config, knowledgeModule, ensureTestFile, where, unflatten, flattens } = require('./runtime').theprogrammablemind
1
+ const { knowledgeModule, ensureTestFile, where, unflatten, flattens } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const _ = require('lodash')
4
4
  const gdefaults = require('./gdefaults.js')
@@ -17,7 +17,7 @@ const template = {
17
17
  };
18
18
 
19
19
  // TODO -> if a car's top speed is over 200 mph then the car is fast
20
- let configStruct = {
20
+ let config = {
21
21
  name: 'meta',
22
22
  operators: [
23
23
  "((phrase) [means] (phrase))",
@@ -130,8 +130,8 @@ let configStruct = {
130
130
  {
131
131
  where: where(),
132
132
  match: ({context}) => context.marker == 'orList' && context.paraphrase,
133
- apply: ({context, gs}) => {
134
- return gs(context.value, ', ', ' or ')
133
+ apply: async ({context, gs}) => {
134
+ return await gs(context.value, ', ', ' or ')
135
135
  },
136
136
  priority: -1,
137
137
  },
@@ -139,10 +139,8 @@ let configStruct = {
139
139
  priority: -1,
140
140
  where: where(),
141
141
  match: ({context}) => context.marker == 'means' && context.paraphrase,
142
- apply: ({context, g}) => {
143
- // const before = g({ ...context.from, paraphrase: true, debug: true})
144
- const before = g({ ...context.from, paraphrase: true})
145
- return `${g({ ...context.from, paraphrase: true})} means ${g(context.to)}`
142
+ apply: async ({context, g}) => {
143
+ return `${await g({ ...context.from, paraphrase: true})} means ${await g(context.to)}`
146
144
  }
147
145
  },
148
146
  {
@@ -160,8 +158,8 @@ let configStruct = {
160
158
  {
161
159
  where: where(),
162
160
  match: ({context}) => context.marker === 'if',
163
- apply: ({context, g}) => {
164
- return `if ${g(context.antecedant)} then ${g(context.consequence)}`
161
+ apply: async ({context, g}) => {
162
+ return `if ${await g(context.antecedant)} then ${await g(context.consequence)}`
165
163
  },
166
164
  priority: -1,
167
165
  },
@@ -182,10 +180,10 @@ let configStruct = {
182
180
  {
183
181
  where: where(),
184
182
  match: ({context}) => context.marker == 'orList',
185
- apply: ({context, s}) => {
183
+ apply: async ({context, s}) => {
186
184
  const response = []
187
185
  for (const value of context.value) {
188
- response.push(s(value))
186
+ response.push(await s(value))
189
187
  }
190
188
  context.evalue = {
191
189
  marker: 'orList',
@@ -205,7 +203,7 @@ let configStruct = {
205
203
  const apply = (DEFINITIONs, DERIVED) => {
206
204
  const mappingss = translationMappings(DEFINITIONs, DERIVED)
207
205
  const invertMappings = (mappings) => mappings.map( ({ from, to }) => { return { to: from, from: to } } )
208
- return ({context, s, g, config}) => {
206
+ return async ({context, s, config}) => {
209
207
  DEFINITIONs = _.cloneDeep(DEFINITIONs)
210
208
  //const mappings = mappingss[0]
211
209
  let toPrimes = []
@@ -215,8 +213,7 @@ let configStruct = {
215
213
  }
216
214
  // next move add debug arg to s and g
217
215
  TO.query = true
218
- toPrimes.push([s(TO), mappings])
219
- // toPrime = s(TO, { debug: { apply: true } })
216
+ toPrimes.push([await s(TO), mappings])
220
217
  }
221
218
 
222
219
  let hasResponse = false
@@ -271,7 +268,7 @@ let configStruct = {
271
268
  // match: match(context),
272
269
  where: where(),
273
270
  match: match(context),
274
- apply: apply(antecedants, _.cloneDeep(context.consequence)) ,
271
+ apply: apply(antecedants, _.cloneDeep(context.consequence)),
275
272
  }
276
273
  config.addSemantic(semantic)
277
274
  }
@@ -280,17 +277,14 @@ let configStruct = {
280
277
  notes: 'from means to where from is unknown',
281
278
  where: where(),
282
279
  match: ({context}) => context.marker == 'means' && context.from.marker == 'unknown',
283
- apply: ({config, context, kms, e, isTest}) => {
280
+ apply: async ({config, context, kms, e, isTest}) => {
284
281
  if (false && isTest) {
285
282
  return
286
283
  } else if (kms.dialogues) {
287
284
  if (context.to.value) {
288
285
  kms.stm.api.setVariable(context.from.value, context.to.value)
289
286
  } else {
290
- // config.addWord(context.from.word,
291
287
  kms.dialogues.api.makeObject({ context: context.from, types: context.to.types || [], config });
292
- // kms.dialogues.api.makeObject({ context: context.from, types: [], config });
293
- // const r = e(context.to)
294
288
  kms.stm.api.setVariable(context.from.value, context.to)
295
289
  }
296
290
  }
@@ -300,17 +294,17 @@ let configStruct = {
300
294
  notes: 'x means y where x and y have known markers',
301
295
  where: where(),
302
296
  match: ({context}) => context.marker == 'means',
303
- apply: ({config, context, g}) => {
297
+ apply: async ({config, context, g}) => {
304
298
  // setup the write semantic
305
299
  {
306
300
  const matchByMarker = (defContext) => ({context}) => context.marker == defContext.from.marker && !context.query && !context.objects
307
301
  const matchByValue = (defContext) => ({context}) => context.evalue == defContext.from.value && !context.query && !context.objects
308
- const apply = (mappings, TO) => ({context, s}) => {
302
+ const apply = (mappings, TO) => async ({context, s}) => {
309
303
  TO = _.cloneDeep(TO)
310
304
  for (let { from, to } of mappings) {
311
305
  hashIndexesSet(TO, to, hashIndexesGet(context, from))
312
306
  }
313
- toPrime = s(TO)
307
+ toPrime = await s(TO)
314
308
  context.result = toPrime.result
315
309
  }
316
310
  const mappings = translationMapping(context.from, context.to)
@@ -332,7 +326,7 @@ let configStruct = {
332
326
  {
333
327
  const matchByMarker = (defContext) => ({context, uuid}) => context.marker == defContext.from.marker && (context.query || context.evaluate) && !context[`disable${uuid}`]
334
328
  const matchByValue = (defContext) => ({context, uuid}) => context.value == defContext.from.value && (context.query || context.evaluate) && !context[`disable${uuid}`]
335
- const apply = (mappings, TO) => ({uuid, context, s, g, config}) => {
329
+ const apply = (mappings, TO) => async ({uuid, context, s, g, config}) => {
336
330
  TO = _.cloneDeep(TO)
337
331
  for (let { from, to } of mappings) {
338
332
  hashIndexesSet(TO, to, hashIndexesGet(context, from))
@@ -345,8 +339,7 @@ let configStruct = {
345
339
  TO.evaluate = context.evaluate
346
340
  }
347
341
  TO[`disable${uuid}`] = true
348
- // toPrime = s(TO, { debug: { apply: true } })
349
- toPrime = s(TO)
342
+ toPrime = await s(TO)
350
343
  if (context.query) {
351
344
  if (toPrime.evalue) {
352
345
  context.evalue = toPrime.evalue
@@ -359,7 +352,7 @@ let configStruct = {
359
352
  }
360
353
  const mappings = translationMapping(context.from, context.to)
361
354
  let match = matchByMarker(context)
362
- context.metaInfo = `The mapping from from the expression being defined "${g({...context.from, paraphrase: true})}" to the definition phrase "${g({...context.to, paraphrase: true})}" is ${JSON.stringify(mappings)}`
355
+ context.metaInfo = `The mapping from from the expression being defined "${await g({...context.from, paraphrase: true})}" to the definition phrase "${await g({...context.to, paraphrase: true})}" is ${JSON.stringify(mappings)}`
363
356
  if (context.from.value) {
364
357
  match = matchByValue(context)
365
358
  }
@@ -378,29 +371,12 @@ let configStruct = {
378
371
  ],
379
372
  };
380
373
 
381
- const createConfig = () => {
382
- const config = new Config(configStruct, module)
383
- config.stop_auto_rebuild()
384
- config.add(gdefaults())
385
-
386
- config.initializer( ({config, addGenerator, isModule}) => {
387
- if (!isModule) {
388
- addGenerator({
389
- where: where(),
390
- match: ({context}) => context.marker == 'unknown',
391
- apply: ({context}) => `${context.word}`
392
- })
393
- }
394
- })
395
-
396
- config.restart_auto_rebuild()
397
- return config
398
- }
399
-
400
374
  knowledgeModule({
375
+ config,
376
+ includes: [gdefaults],
377
+
401
378
  module,
402
379
  description: 'Ways of defining new language elements',
403
- createConfig,
404
380
  test: {
405
381
  name: './meta.test.json',
406
382
  contents: meta_tests,
@@ -0,0 +1,2 @@
1
+ {
2
+ }
@@ -0,0 +1,135 @@
1
+ const { knowledgeModule, where } = require('./runtime').theprogrammablemind
2
+ const { defaultContextCheck } = require('./helpers')
3
+ const helpers = require('./helpers')
4
+ const stm = require('./stm')
5
+ const nameable_tests = require('./nameable.test.json')
6
+
7
+ class API {
8
+ initialize({ objects, km, kms }) {
9
+ this.objects = objects
10
+ this.objects.named = {}
11
+ }
12
+
13
+ // report is a context
14
+ setName(context, name) {
15
+ if (!context.stm) {
16
+ context.stm = {}
17
+ }
18
+ if (!context.stm.names) {
19
+ context.stm.names = []
20
+ }
21
+ context.stm.names.push(name)
22
+ }
23
+
24
+ get(type, name) {
25
+ return this.args.kms.stm.api.mentions({
26
+ context: type,
27
+ condition: (context) => {
28
+ if (context.stm && context.stm.names) {
29
+ return context.stm.names.includes(name)
30
+ }
31
+ }
32
+ })
33
+ }
34
+
35
+ getNamesByType(type) {
36
+ const contexts = this.args.kms.stm.api.getByType(type)
37
+ const names = new Set()
38
+ for (const context of contexts) {
39
+ if (context.stm.names) {
40
+ for (const name of context.stm.names) {
41
+ names.add(name)
42
+ }
43
+ }
44
+ }
45
+ return [...names]
46
+ }
47
+
48
+ getNames(nameable) {
49
+ return (nameable.stm && nameable.stm.names) || []
50
+ }
51
+
52
+ /*
53
+ getNames() {
54
+ const current = this.current()
55
+ console.log('getReportNames current', JSON.stringify(current, null, 2))
56
+ return Object.keys(this.objects.namedReports).map( (name) => {
57
+ const selected = (current.names || []).includes(name)
58
+ return { name, selected, id: name }
59
+ })
60
+ }
61
+ */
62
+
63
+ setCurrent(name) {
64
+ const context = this.objects.named[name]
65
+ if (context) {
66
+ this.args.km('stm').api.mentioned({ context })
67
+ }
68
+ }
69
+ }
70
+
71
+ const api = new API()
72
+
73
+ const config = {
74
+ name: 'nameable',
75
+ operators: [
76
+ "([call] ([nameable]) (name))",
77
+ { pattern: "([getNamesByType] (type))", development: true },
78
+ { pattern: "([m1])", development: true },
79
+ // { pattern: "([testPullFromContext] ([memorable]))", development: true }
80
+ ],
81
+ words: {
82
+ literals: {
83
+ // "m1": [{"id": "memorable", development: true, "initial": "{ value: 'm1' }" }],
84
+ // "m2": [{"id": "memorable", development: true, "initial": "{ value: 'm2' }" }],
85
+ },
86
+ },
87
+ bridges: [
88
+ {
89
+ id: 'm1',
90
+ isA: ['memorable', 'nameable'],
91
+ development: true,
92
+ },
93
+ {
94
+ id: 'getNamesByType',
95
+ development: true,
96
+ isA: ['verb'],
97
+ bridge: "{ ...next(operator), type: after[0] }",
98
+ semantic: async ({context, api}) => {
99
+ context.response = api.getNamesByType(context.type.value).join(" ")
100
+ context.isResponse = true
101
+ }
102
+ },
103
+ {
104
+ id: 'call',
105
+ isA: ['verb'],
106
+ bridge: "{ ...next(operator), nameable: after[0], name: after[1] }",
107
+ generatorp: async ({context, g}) => `call ${await g(context.nameable)} ${await g(context.name)}`,
108
+ semantic: async ({config, context, api, e}) => {
109
+ // TODO find report being referred to
110
+ const nameable = (await e(context.nameable)).evalue
111
+ const name = context.name.text
112
+ config.addWord(name, { id: nameable.marker, initial: `{ value: "${name}", pullFromContext: true, nameable_named: true }` })
113
+ api.setName(nameable, name)
114
+ }
115
+ },
116
+ { id: 'nameable', words: helpers.words('nameable')},
117
+ ]
118
+ }
119
+
120
+ knowledgeModule( {
121
+ config,
122
+ api: () => new API(),
123
+ includes: [stm],
124
+
125
+ module,
126
+ description: 'namable objects',
127
+ test: {
128
+ name: './nameable.test.json',
129
+ contents: nameable_tests,
130
+ checks: {
131
+ context: [...defaultContextCheck, 'pullFromContext'],
132
+ objects: ['mentioned', { km: 'stm' }],
133
+ },
134
+ },
135
+ })