ekms 9.5.1-beta.5 → 9.5.1-beta.6

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 (70) hide show
  1. package/common/animals.instance.json +21 -61
  2. package/common/asking.js +102 -100
  3. package/common/can.instance.json +17 -0
  4. package/common/can.js +188 -0
  5. package/common/characters.js +3 -3
  6. package/common/colors.instance.json +38 -10
  7. package/common/comparable.instance.json +2 -2
  8. package/common/concept.test.json +54 -40
  9. package/common/conjunction.js +13 -5
  10. package/common/crew.instance.json +26 -26
  11. package/common/crew.js +1 -1
  12. package/common/currency.js +1 -1
  13. package/common/dates.instance.json +87 -3
  14. package/common/dialogues.js +11 -8
  15. package/common/dimension.instance.json +1 -1
  16. package/common/edible.instance.json +79 -95
  17. package/common/emotions.instance.json +6 -10
  18. package/common/emotions.js +1 -1
  19. package/common/english_helpers.js +277 -67
  20. package/common/fastfood.instance.json +235 -807
  21. package/common/fastfood.js +4 -4
  22. package/common/formulas.instance.json +1 -1
  23. package/common/gdefaults.js +41 -9
  24. package/common/help.js +2 -2
  25. package/common/helpers/concept.js +1 -1
  26. package/common/helpers/conjunction.js +54 -44
  27. package/common/helpers/dateTimeSelectors.js +2 -2
  28. package/common/helpers/dialogues.js +1 -1
  29. package/common/helpers/formulas.js +13 -11
  30. package/common/helpers/menus.js +12 -12
  31. package/common/helpers/meta.js +8 -8
  32. package/common/helpers/properties.js +76 -15
  33. package/common/helpers.js +82 -46
  34. package/common/hierarchy.js +3 -3
  35. package/common/kirk.instance.json +1 -1
  36. package/common/length.instance.json +2 -2
  37. package/common/math.instance.json +20 -20
  38. package/common/math.js +45 -44
  39. package/common/menus.instance.json +3 -3
  40. package/common/menus.js +1 -1
  41. package/common/meta.js +49 -33
  42. package/common/ordering.instance.json +16 -28
  43. package/common/ordering.js +1 -1
  44. package/common/ordering.test.json +354 -296
  45. package/common/people.instance.json +36 -47
  46. package/common/people.js +1 -1
  47. package/common/people.test.json +952 -681
  48. package/common/pipboy.instance.json +72 -16
  49. package/common/pokemon.instance.json +8 -8
  50. package/common/pokemon.js +1 -1
  51. package/common/pressure.instance.json +2 -2
  52. package/common/properties.instance.json +1 -1
  53. package/common/properties.js +16 -3
  54. package/common/reminders.js +1 -1
  55. package/common/reports.instance.json +3 -3
  56. package/common/reports.js +18 -16
  57. package/common/scorekeeper.js +4 -4
  58. package/common/sdefaults.js +22 -2
  59. package/common/spock.instance.json +1 -1
  60. package/common/stgame.js +1 -1
  61. package/common/stm.js +2 -2
  62. package/common/tell.js +1 -1
  63. package/common/temperature.instance.json +2 -2
  64. package/common/tester.js +3 -3
  65. package/common/time.js +3 -3
  66. package/common/tokenize.js +1 -1
  67. package/common/weight.instance.json +2 -2
  68. package/common/wp.instance.json +62 -6
  69. package/common/wp.js +4 -4
  70. package/package.json +4 -2
@@ -1,4 +1,5 @@
1
1
  const pluralize = require('pluralize')
2
+ const { conjugateVerb } = require('../english_helpers')
2
3
  const { unflatten, flattens, Digraph } = require('../runtime').theprogrammablemind
3
4
  const _ = require('lodash')
4
5
  const deepEqual = require('deep-equal')
@@ -28,7 +29,7 @@ class API {
28
29
  this._km = km
29
30
  this.__config = config
30
31
  this.digraph = new Digraph()
31
- const toJSON = (h) => {
32
+ function toJSON(h) {
32
33
  if (h.child && h.parent) {
33
34
  return h
34
35
  } else {
@@ -274,12 +275,14 @@ class API {
274
275
  relation,
275
276
  ordering,
276
277
  doAble,
278
+ flatten,
279
+ can,
277
280
  words = [],
278
281
  unflatten:unflattenArgs = [],
279
282
  focusable = [],
280
283
  edAble } = args;
281
284
 
282
- const createToCanonical = (concept) => {
285
+ function createToCanonical(concept) {
283
286
  if (typeof concept == 'string') {
284
287
  return { id: concept, isA: [] }
285
288
  } else {
@@ -346,7 +349,7 @@ class API {
346
349
 
347
350
  create.map( ({ id, isA }) => {
348
351
  if (id === operator) {
349
- const tagsToProps = (where, args, suffix='') => {
352
+ function tagsToProps(where, args, suffix='') {
350
353
  const i = 0;
351
354
  let r = ''
352
355
  for (const arg of args) {
@@ -367,16 +370,25 @@ class API {
367
370
  const imperative = (before.length == 0) ? "true" : "false"
368
371
  // const interpolate = "[" + before.map((arg) => `{ property: '${arg.tag}' }`).concat(`{ ...operator, evaluateWord: true, imperative: ${imperative}, isVerb: true, number: 'one' }`).concat(after.map((arg) => `{ property: '${arg.tag}' }`)).join(',') + "]"
369
372
  // const interpolateVerb = `{ property: "operator", context: { evaluateWord: true, imperative: ${imperative}, isVerb: true, number: 'one' } }`
370
- const interpolateVerb = `{ property: "operator" }`
373
+ let interpolateVerb
374
+ if (before.length > 0) {
375
+ interpolateVerb = `{ property: "operator", number: '${before[0].tag}' }`
376
+ } else {
377
+ interpolateVerb = `{ property: "operator" }`
378
+ }
371
379
  const interpolate = "[" + before.map((arg) => `{ property: '${arg.tag}' }`).concat(interpolateVerb).concat(after.map((arg) => `{ property: '${arg.tag}' }`)).join(',') + "]"
372
380
 
373
381
  const unflattenArgs = [ ...before.map( (arg) => arg.tag ), ...after.map( (arg) => arg.tag ) ]
374
382
  const focusable = [ ...before.map( (arg) => arg.tag ), ...after.map( (arg) => arg.tag ) ]
383
+ let flattenProperty = ''
384
+ if (flatten) {
385
+ flattenProperty = ", flatten: true, relation: true "
386
+ }
375
387
  config.addBridge({
376
388
  id: operator,
377
389
  level: 0,
378
390
  localHierarchy: [...localHierarchy, ['object', 'unknown']],
379
- bridge: `{ ... next(operator) ${doParams} ${beforeArgs} ${afterArgs}, operator: { ...operator, evaluateWord: true, imperative: ${imperative}, isVerb: true, number: 'one' }, unflatten: ${JSON.stringify(unflattenArgs)}, focusable: ${JSON.stringify(focusable)}, interpolate: ${interpolate} }`,
391
+ bridge: `{ ... next(operator) ${flattenProperty} ${doParams} ${beforeArgs} ${afterArgs}, operator: { ...operator, evaluateWord: true, imperative: ${imperative}, isVerb: true, number: 'one' }, unflatten: ${JSON.stringify(unflattenArgs)}, focusable: ${JSON.stringify(focusable)}, interpolate: ${interpolate} }`,
380
392
  allowDups: true
381
393
  })
382
394
  if (words.length > 0) {
@@ -396,6 +408,15 @@ class API {
396
408
  })
397
409
 
398
410
  if (words.length == 0) {
411
+ const createDef = createInit.find((def) => def.id == operator)
412
+ if (createDef && createDef.infinitive) {
413
+ const conjugation = conjugateVerb(createDef.infinitive)
414
+ if (can) {
415
+ const def = conjugation.find((def) => def.form == "pastParticiple")
416
+ config.addWord(def.word, { id: operator, initial: `{ value: '${operator}', tense: '${def.tense}' }`})
417
+ }
418
+ }
419
+
399
420
  const operatorPlural = pluralize.singular(operator)
400
421
  const operatorSingular = pluralize.plural(operator)
401
422
  config.addWord(operatorSingular, { id: operator, initial: `{ value: '${operator}', number: 'one' }`})
@@ -413,6 +434,18 @@ class API {
413
434
  config.addPriority({ "context": [[operator, 0], ['means', 0], ], "choose": [0] })
414
435
  config.addPriority({ "context": [['article', 0], [operator, 0], ], "choose": [0] })
415
436
 
437
+ if (can) {
438
+ const beforeIds = before.map((def) => def.id)
439
+ const afterIds = after.map((def) => def.id)
440
+ config.addHierarchy(operator, 'canableAction')
441
+ config.addAssociation({ context: [[afterIds[0], 0], ['whatCanQuestion', 0], [beforeIds[0], 0], ['make', 0]], choose: 1 })
442
+ config.addAssociation({ context: [[afterIds[0], 1], ['whatCanQuestion', 0], [beforeIds[0], 0], ['make', 0]], choose: 1 })
443
+ config.addAssociation({ context: [[afterIds[0], 0], ['whatCanQuestionPassive', 0], [beforeIds[0], 0], ['beCanPassive', 0], ['make', 0], ['byCanPassive', 0]], choose: 1 })
444
+ config.addAssociation({ context: [[afterIds[0], 1], ['whatCanQuestionPassive', 0], [beforeIds[0], 0], ['beCanPassive', 0], ['make', 0], ['byCanPassive', 0]], choose: 1 })
445
+ config.addAssociation({ context: [[afterIds[0], 0], ['canPassive', 0], ['beCanPassive', 0], ['make', 0], ['byCanPassive', 0], [beforeIds[0], 0]], choose: 1 })
446
+ config.addAssociation({ context: [[afterIds[0], 1], ['canPassive', 0], ['beCanPassive', 0], ['make', 0], ['byCanPassive', 0], [beforeIds[0], 0]], choose: 1 })
447
+ }
448
+
416
449
  if (false) {
417
450
  config.addGenerator({
418
451
  notes: 'ordering generator for paraphrase',
@@ -440,22 +473,50 @@ class API {
440
473
  config.addGenerator({
441
474
  notes: 'ordering generator for response',
442
475
  match: ({context}) => context.marker == operator && context.evalue && context.isResponse,
443
- apply: async ({context, g, km}) => {
476
+ apply: async ({context, g, km, flatten}) => {
444
477
  const brief = km("dialogues").api.getBrief()
445
478
 
446
479
  const { evalue } = context
447
480
  let yesno = ''
448
- if (!context.do.query || evalue.truthValueOnly || brief) {
449
- if (evalue.truthValue) {
481
+ let hasVariables = false
482
+ if (context.focusable) {
483
+ for (const f of context.focusable) {
484
+ if (context[f].query) {
485
+ hasVariables = true
486
+ break
487
+ }
488
+ }
489
+ }
490
+
491
+ // if (!context.do?.query || evalue.truthValueOnly || context.truthValueOnly || brief) {
492
+ if (evalue.truthValueOnly || context.truthValueOnly || context.wantsTruthValue || !hasVariables) {
493
+ function any(value, test) {
494
+ if (test(value)) {
495
+ return true
496
+ }
497
+ const values = flatten(['list'], value)[0]
498
+ for (const value of values) {
499
+ if (test(value)) {
500
+ return true
501
+ }
502
+ }
503
+ }
504
+ if (any(evalue, (value) => value.truthValue)) {
450
505
  yesno = 'yes'
451
- } else if (evalue.truthValue === false) {
506
+ } else if (evalue.truthValue === false || context.truthValueOnly) {
452
507
  yesno = 'no'
453
508
  }
454
509
  }
455
- if (evalue.truthValueOnly || brief) {
510
+ if (evalue.truthValueOnly) {
456
511
  return `${yesno}`
457
512
  } else {
458
- return `${yesno} ${await g(Object.assign({}, evalue, { paraphrase: true }))}`
513
+ const details = await g(Object.assign({}, evalue, { paraphrase: true }))
514
+ if (yesno) {
515
+ return `${yesno} ${details}`
516
+ }
517
+ else {
518
+ return details
519
+ }
459
520
  }
460
521
  }
461
522
  })
@@ -558,7 +619,6 @@ class API {
558
619
  match: ({context}) => context.marker == operator && context.query,
559
620
  apply: ({context, km, callId}) => {
560
621
  const api = km('properties').api
561
-
562
622
  context.evalue = {
563
623
  marker: 'list',
564
624
  value: unflatten(api.relation_get(context, before.concat(after).map( (arg) => arg.tag ) ))
@@ -568,8 +628,8 @@ class API {
568
628
  if (context.evalue.value.length == 0) {
569
629
  context.evalue.marker = 'answerNotKnown';
570
630
  context.evalue.value = [];
571
- context.evalue.marker = 'answerNotKnown';
572
- context.evalue.value = [];
631
+ } else {
632
+ // context.evalue.truthValue = true
573
633
  }
574
634
  }
575
635
  })
@@ -599,6 +659,7 @@ class API {
599
659
  relations = [relations]
600
660
  }
601
661
  for (const relation of relations) {
662
+ relation.truthValue = true
602
663
  this._objects.relations.push(relation)
603
664
  }
604
665
  }
@@ -642,7 +703,7 @@ class API {
642
703
  return value
643
704
  }
644
705
 
645
- relation_get(context, args) {
706
+ relation_get (context, args) {
646
707
  const andTheAnswerIs = []
647
708
  for (const relation of this._objects.relations) {
648
709
  if (this.relation_match(args, context, relation)) {
package/common/helpers.js CHANGED
@@ -1,13 +1,14 @@
1
1
  const pluralize = require('pluralize')
2
+ const { flatten } = require('./runtime').theprogrammablemind
2
3
 
3
- const unshiftL = (list, element, max) => {
4
+ function unshiftL(list, element, max) {
4
5
  if (list.length >= max) {
5
6
  list.pop()
6
7
  }
7
8
  list.unshift(element)
8
9
  }
9
10
 
10
- const pushL = (list, element, max) => {
11
+ function pushL(list, element, max) {
11
12
  if (list.length >= max) {
12
13
  list.shift()
13
14
  }
@@ -15,11 +16,11 @@ const pushL = (list, element, max) => {
15
16
  }
16
17
 
17
18
  // X pm today or tomorrow
18
- const millisecondsUntilHourOfDay = (newDate, hour) => {
19
+ function millisecondsUntilHourOfDay(newDate, hour) {
19
20
  const now = newDate()
20
21
  const target = newDate(now)
21
22
 
22
- const addHours = (date, h) => {
23
+ function addHours(date, h) {
23
24
  date.setTime(date.getTime() + (h*60*60*1000));
24
25
  }
25
26
  const hours = target.getHours()
@@ -34,11 +35,11 @@ const millisecondsUntilHourOfDay = (newDate, hour) => {
34
35
  return diff;
35
36
  }
36
37
 
37
- const indent = (string, indent) => {
38
+ function indent(string, indent) {
38
39
  return string.replace(/^/gm, ' '.repeat(indent));
39
40
  }
40
41
 
41
- const getCount = (context) => {
42
+ function getCount(context) {
42
43
  if (context.quantity) {
43
44
  return context.quantity.value
44
45
  }
@@ -47,13 +48,23 @@ const getCount = (context) => {
47
48
  }
48
49
  }
49
50
 
50
- const words = (word, additional = {}) => {
51
+ function words(word, additional = {}) {
51
52
  return [{ word: pluralize.singular(word), number: 'one', ...additional }, { word: pluralize.plural(word), number: 'many', ...additional }]
52
53
  }
53
54
 
54
- const isMany = (context) => {
55
- if (((context || {}).value || {}).marker == 'list' && (((context || {}).value || {}).value || []).length > 1) {
56
- return true
55
+ function isMany(context) {
56
+ if (!context) {
57
+ return
58
+ }
59
+ // if (((context || {}).value || {}).marker == 'list' && (((context || {}).value || {}).value || []).length > 1) {
60
+ const isList = context.marker == 'list' || context.value?.marker == 'list'
61
+ if (isList) {
62
+ if (context.value?.length > 1) {
63
+ return true
64
+ }
65
+ if (context.value?.value?.length > 1) {
66
+ return true
67
+ }
57
68
  }
58
69
 
59
70
  let number = context.number
@@ -77,13 +88,13 @@ const isMany = (context) => {
77
88
  return false
78
89
  }
79
90
 
80
- const requiredArgument = (value, name) => {
91
+ function requiredArgument(value, name) {
81
92
  if (!value) {
82
93
  throw new Error(`${name} is a required argument`)
83
94
  }
84
95
  }
85
96
 
86
- const chooseNumber = (context, one, many) => {
97
+ function chooseNumber(context, one, many) {
87
98
  if (isMany(context)) {
88
99
  return many;
89
100
  } else {
@@ -91,7 +102,7 @@ const chooseNumber = (context, one, many) => {
91
102
  }
92
103
  }
93
104
 
94
- const zip = (...arrays) => {
105
+ function zip(...arrays) {
95
106
  if (arrays == []) {
96
107
  return []
97
108
  }
@@ -107,15 +118,21 @@ const zip = (...arrays) => {
107
118
  }
108
119
 
109
120
 
110
- const focus = (context) => {
111
- const helper = (context) => {
121
+ function focus(context) {
122
+ function helper(context) {
112
123
  if (!context || !context.focusable) {
113
124
  return null
114
125
  }
115
126
  for (const property of context.focusable) {
116
127
  let focus = helper(context[property])
117
- if (!focus && (context[property] || {}).focus) {
118
- focus = context[property]
128
+ if (!focus) {
129
+ const flat = flatten(['list'], context[property])[0]
130
+ for (const element of flat) {
131
+ if (element.focus) {
132
+ focus = context[property]
133
+ break
134
+ }
135
+ }
119
136
  }
120
137
  return focus
121
138
  }
@@ -126,7 +143,7 @@ const focus = (context) => {
126
143
 
127
144
  // if property is a list make array of elements of the list, if not return an array with the property value
128
145
  // fromList
129
- const propertyToArray = (value) => {
146
+ function propertyToArray(value) {
130
147
  if (Array.isArray(value)) {
131
148
  return value
132
149
  } else if (value.marker == 'list') {
@@ -136,7 +153,23 @@ const propertyToArray = (value) => {
136
153
  }
137
154
  }
138
155
 
139
- wordNumber = (word, toPlural) => {
156
+ // values is marker: 'list' or some context
157
+ function concats(values) {
158
+ combined = []
159
+ for (const value of values) {
160
+ if (value.marker == 'list') {
161
+ combined = combined.concat(value.value)
162
+ } else {
163
+ combined.push(value)
164
+ }
165
+ }
166
+ return {
167
+ marker: 'list',
168
+ value: combined
169
+ }
170
+ }
171
+
172
+ function wordNumber(word, toPlural) {
140
173
  if (toPlural) {
141
174
  return pluralize.plural(word)
142
175
  } else {
@@ -144,14 +177,14 @@ wordNumber = (word, toPlural) => {
144
177
  }
145
178
  }
146
179
 
147
- const toEValue = (context) => {
180
+ function toEValue(context) {
148
181
  while( context.evalue ) {
149
182
  context = context.evalue
150
183
  }
151
184
  return context;
152
185
  }
153
186
 
154
- const defaultObjectCheck = (extra = []) => {
187
+ function defaultObjectCheck(extra = []) {
155
188
  return {
156
189
  objects: [
157
190
  {
@@ -162,11 +195,11 @@ const defaultObjectCheck = (extra = []) => {
162
195
  }
163
196
  }
164
197
 
165
- const defaultContextCheckProperties = (extra) => {
198
+ function defaultContextCheckProperties(extra) {
166
199
  return ['marker', 'text', 'verbatim', 'value', 'evalue', 'isResponse', { properties: 'modifiers' }, { properties: 'postModifiers' }, ...extra]
167
200
  }
168
201
 
169
- const defaultContextCheck = ({marker, extra = [], exported = false} = {}) => {
202
+ function defaultContextCheck({marker, extra = [], exported = false} = {}) {
170
203
  let match
171
204
  if (marker) {
172
205
  match = ({context}) => context.marker == marker
@@ -180,35 +213,37 @@ const defaultContextCheck = ({marker, extra = [], exported = false} = {}) => {
180
213
  }
181
214
  }
182
215
 
183
- const isA = (hierarchy) => (child, parent, { strict=false } = {}) => {
184
- if (!child || !parent) {
185
- return false
186
- }
187
-
188
- if (strict) {
189
- if (child.marker) {
190
- child = child.marker
191
- }
192
- if (parent.marker) {
193
- parent = parent.marker
194
- }
195
- return hierarchy.isA(child, parent)
196
- } else {
197
- if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
198
- return true
216
+ function isA(hierarchy) {
217
+ return (child, parent, { strict=false } = {}) => {
218
+ if (!child || !parent) {
219
+ return false
199
220
  }
200
- for (const childT of child.types || [child]) {
201
- for (const parentT of parent.types || [parent]) {
202
- if (hierarchy.isA(childT, parentT)) {
203
- return true
221
+
222
+ if (strict) {
223
+ if (child.marker) {
224
+ child = child.marker
225
+ }
226
+ if (parent.marker) {
227
+ parent = parent.marker
228
+ }
229
+ return hierarchy.isA(child, parent)
230
+ } else {
231
+ if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
232
+ return true
233
+ }
234
+ for (const childT of child.types || [child]) {
235
+ for (const parentT of parent.types || [parent]) {
236
+ if (hierarchy.isA(childT, parentT)) {
237
+ return true
238
+ }
204
239
  }
205
240
  }
241
+ return false
206
242
  }
207
- return false
208
243
  }
209
244
  }
210
245
 
211
- const getValue = (propertyPath, object) => {
246
+ function getValue(propertyPath, object) {
212
247
  if (!propertyPath) {
213
248
  return
214
249
  }
@@ -223,7 +258,7 @@ const getValue = (propertyPath, object) => {
223
258
  return value
224
259
  }
225
260
 
226
- const processTemplateString = async (template, evaluate) => {
261
+ async function processTemplateString(template, evaluate) {
227
262
  async function resolveWithCallback(strings, ...keys) {
228
263
  // const resolvedValues = await Promise.all(keys.map(key => lookupVariable(key)));
229
264
  const resolvedValues = await Promise.all(keys.map(async (key) => {
@@ -337,4 +372,5 @@ module.exports = {
337
372
  requiredArgument,
338
373
  isA,
339
374
  removeProp,
375
+ concats
340
376
  }
@@ -6,11 +6,11 @@ const pluralize = require('pluralize')
6
6
  const _ = require('lodash')
7
7
  const { isMany } = require('./helpers')
8
8
 
9
- const getTypes = ( km, concept, instance ) => {
9
+ function getTypes( km, concept, instance ) {
10
10
  const propertiesAPI = km('properties').api;
11
11
  const conceptAPI = km('concept').api;
12
12
  const digraph = propertiesAPI.digraph;
13
- const intersect = (set1, set2) => {
13
+ function intersect(set1, set2) {
14
14
  return new Set([...set1].filter(x => set2.has(x)))
15
15
  }
16
16
  const descendants = digraph.descendants(concept.value)
@@ -286,7 +286,7 @@ const config = {
286
286
  ]
287
287
  };
288
288
 
289
- const initializer = ({apis, hierarchy}) => {
289
+ function initializer({apis, hierarchy}) {
290
290
  apis('stm').addIsA( (child, parent) => {
291
291
  return hierarchy.isA(child, parent)
292
292
  })
@@ -1666,7 +1666,7 @@
1666
1666
  "dead": true,
1667
1667
  "range": {
1668
1668
  "start": 0,
1669
- "end": 11
1669
+ "end": 2
1670
1670
  },
1671
1671
  "types": [
1672
1672
  "self"
@@ -1123,7 +1123,7 @@
1123
1123
  "word": "length",
1124
1124
  "range": {
1125
1125
  "start": 0,
1126
- "end": 20
1126
+ "end": 5
1127
1127
  },
1128
1128
  "dead": true,
1129
1129
  "types": [
@@ -2756,7 +2756,7 @@
2756
2756
  "text": "meter centimeter foot and inch",
2757
2757
  "range": {
2758
2758
  "start": 0,
2759
- "end": 49
2759
+ "end": 29
2760
2760
  },
2761
2761
  "types": [
2762
2762
  "list",