ekms 9.5.1-beta.5 → 9.5.1-beta.7

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
@@ -284,7 +284,7 @@ const template = {
284
284
  ({ask, api}) => {
285
285
  // see if followup for drink is needed
286
286
 
287
- const hasDrink = (isA, item) => {
287
+ function hasDrink(isA, item) {
288
288
  let hasDrink = false
289
289
  for (const modification of (item.modifications || [])) {
290
290
  if (isA(modification.id, 'drink')) {
@@ -295,11 +295,11 @@ const template = {
295
295
  return hasDrink
296
296
  }
297
297
 
298
- const needsDrink = (item) => {
298
+ function needsDrink (item) {
299
299
  return item.needsDrink
300
300
  }
301
301
 
302
- const askAbout = ({api, isA}) => {
302
+ function askAbout({api, isA}) {
303
303
  const items = []
304
304
  for (const item of api.items()) {
305
305
  if (needsDrink(item) && !hasDrink(isA, item)) {
@@ -765,7 +765,7 @@ class State {
765
765
  return
766
766
  }
767
767
 
768
- const addSize = (item, data) => {
768
+ function addSize(item, data) {
769
769
  if (item.size) {
770
770
  data.size = item.size.value
771
771
  }
@@ -997,7 +997,7 @@
997
997
  "word": "formulas",
998
998
  "range": {
999
999
  "start": 0,
1000
- "end": 20
1000
+ "end": 7
1001
1001
  },
1002
1002
  "dead": true,
1003
1003
  "types": [
@@ -1,10 +1,9 @@
1
1
  const pluralize = require('pluralize')
2
- const { defaultContextCheck } = require('./helpers')
3
- const { knowledgeModule, where } = require('./runtime').theprogrammablemind
2
+ const { defaultContextCheck, getValue, isMany } = require('./helpers')
3
+ const { knowledgeModule, where, flatten } = require('./runtime').theprogrammablemind
4
4
  const tokenize = require('./tokenize.js')
5
5
  const gdefaults_tests = require('./gdefaults.test.json')
6
6
  const englishHelpers = require('./english_helpers.js')
7
- const { getValue, isMany } = require('./helpers.js')
8
7
  const helpers = require('./helpers')
9
8
 
10
9
  const config = {
@@ -152,14 +151,42 @@ const config = {
152
151
  {
153
152
  where: where(),
154
153
  priority: -1,
155
- match: ({context}) => context.evaluateWord && context.paraphrase && context.word && (context.number == 'many' || context.number > 1),
154
+ match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'one' && !context.imperative && !context.interpolate,
155
+ apply: ({context}) => {
156
+ const infinitive = englishHelpers.getInfinitive(context.word)
157
+ if (context.tense) {
158
+ const cases = englishHelpers.conjugateVerb(infinitive)
159
+ // console.log(JSON.stringify(cases, null, 2))
160
+ const def = cases.find((def) => def.tense == context.tense)
161
+ return def.word
162
+ } else {
163
+ return pluralize.plural(context.word)
164
+ }
165
+ },
166
+ },
167
+
168
+ {
169
+ where: where(),
170
+ priority: -1,
171
+ match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'many' && !context.imperative && !context.interpolate,
172
+ apply: ({context}) => {
173
+ const infinitive = englishHelpers.getInfinitive(context.word)
174
+ const cases = englishHelpers.conjugateVerb(infinitive)
175
+ return pluralize.singular(context.word)
176
+ },
177
+ },
178
+
179
+ {
180
+ where: where(),
181
+ priority: -1,
182
+ match: ({context}) => context.evaluateWord && context.paraphrase && context.word && (context.number == 'many' || context.number > 1) && !context.interpolate,
156
183
  apply: ({context}) => pluralize.plural(context.word),
157
184
  },
158
185
 
159
186
  {
160
187
  where: where(),
161
188
  priority: -1,
162
- match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'one' && !context.imperative,
189
+ match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'one' && !context.imperative && !context.interpolate,
163
190
  apply: ({context}) => {
164
191
  const infinitive = englishHelpers.getInfinitive(context.word)
165
192
  const cases = englishHelpers.conjugateVerb(infinitive)
@@ -170,7 +197,7 @@ const config = {
170
197
  {
171
198
  where: where(),
172
199
  priority: -1,
173
- match: ({context}) => context.evaluateWord && context.paraphrase && context.word && context.number == 'one',
200
+ match: ({context}) => context.evaluateWord && context.paraphrase && context.word && context.number == 'one' && !context.interpolate,
174
201
  apply: ({context}) => {
175
202
  return pluralize.singular(context.word)
176
203
  },
@@ -242,9 +269,10 @@ const config = {
242
269
  ],
243
270
  };
244
271
 
245
- const initializer = ({config}) => {
272
+ function initializer({config}) {
246
273
  config.addArgs((args) => {
247
274
  return {
275
+ flatten,
248
276
  number: (context) => isMany(context) ? "many" : "one",
249
277
  // number/gender/person etc
250
278
  gw: (context, { number: numberContext }) => {
@@ -255,14 +283,14 @@ const initializer = ({config}) => {
255
283
  args.insert({ marker: 'verbatim', verbatim: text, isResponse: true })
256
284
  },
257
285
  interpolate: async (interpolate, context) => {
258
- const evaluator = async (key) => {
286
+ async function evaluator(key) {
259
287
  if (Array.isArray(context[key])) {
260
288
  return args.gsp(context[key])
261
289
  } else {
262
290
  return args.gp(context[key])
263
291
  }
264
292
  }
265
- const getValue = (keyOrValue) => {
293
+ function getValue(keyOrValue) {
266
294
  if (typeof keyOrValue == 'string' && context[keyOrValue]) {
267
295
  return context[keyOrValue]
268
296
  }
@@ -295,6 +323,10 @@ const initializer = ({config}) => {
295
323
  Object.assign(value, element.context)
296
324
  }
297
325
  }
326
+ // if (!value?.number && element.number) {
327
+ if (value?.number !== 'infinitive' && element.number) {
328
+ value.number = isMany(context[element.number]) ? "many": "one"
329
+ }
298
330
  if (value) {
299
331
  strings.push(separator)
300
332
  strings.push(await args.gp(value))
package/common/help.js CHANGED
@@ -4,7 +4,7 @@ const dialogues = require('./dialogues')
4
4
  const help_tests = require('./help.test.json')
5
5
  const helpers = require('./helpers')
6
6
 
7
- const getHelp = (config, indent=2) => {
7
+ function getHelp(config, indent=2) {
8
8
  indent = ' '.repeat(indent)
9
9
  let help = ''
10
10
  if (config.tests.length == 0) {
@@ -82,7 +82,7 @@ const config = {
82
82
  },
83
83
  };
84
84
 
85
- const initializer = ({ config, addWord, kms }) => {
85
+ function initializer({ config, addWord, kms }) {
86
86
  const names = new Set()
87
87
  for (const name in kms) {
88
88
  names.add(name);
@@ -38,7 +38,7 @@ class API {
38
38
  const modifierIds = modifiers.map( (modifier) => this.args.kms.dialogues.api.toScopedId(modifier) )
39
39
  const modifiersObjectId = `${modifierIds.join("_")}_${objectId}`
40
40
 
41
- const toWord = (object) => {
41
+ function toWord(object) {
42
42
  if (typeof object == 'string') {
43
43
  return object
44
44
  }
@@ -1,7 +1,13 @@
1
1
  const { propertyToArray } = require('../helpers.js')
2
2
 
3
- const asList = (context) => {
4
- if (context.marker === 'list') {
3
+ function asList(context) {
4
+ if (Array.isArray(context)) {
5
+ return {
6
+ marker: 'list',
7
+ // types: [context.marker],
8
+ value: context
9
+ }
10
+ } else if (context.marker === 'list') {
5
11
  return context
6
12
  }
7
13
  return {
@@ -11,60 +17,64 @@ const asList = (context) => {
11
17
  }
12
18
  }
13
19
 
14
- const listable = (hierarchy) => (c, type) => {
15
- if (!c) {
16
- return false
17
- }
18
- if (hierarchy.isA(c.marker, type)) {
19
- return true
20
- }
21
- if (c.marker === 'list') {
22
- for (const t of c.types) {
23
- if (hierarchy.isA(t, type)) {
24
- return true
20
+ function listable(hierarchy) {
21
+ return (c, type) => {
22
+ if (!c) {
23
+ return false
24
+ }
25
+ if (hierarchy.isA(c.marker, type)) {
26
+ return true
27
+ }
28
+ if (c.marker === 'list') {
29
+ for (const t of c.types) {
30
+ if (hierarchy.isA(t, type)) {
31
+ return true
32
+ }
25
33
  }
26
34
  }
27
- }
28
- return false
29
- }
30
-
31
- const isA = (hierarchy) => (child, parent, { strict=false } = {}) => {
32
- if (!child || !parent) {
33
35
  return false
34
36
  }
37
+ }
35
38
 
36
- if (strict) {
37
- if (child.marker) {
38
- child = child.marker
39
- }
40
- if (parent.marker) {
41
- parent = parent.marker
39
+ function isA(hierarchy) {
40
+ return (child, parent, { strict=false } = {}) => {
41
+ if (!child || !parent) {
42
+ return false
42
43
  }
43
- return hierarchy.isA(child, parent)
44
- } else {
45
- const children = propertyToArray(child)
46
- for (const child of children) {
47
- let okay = false
48
- if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
49
- okay = true
50
- } else {
51
- for (const childT of child.types || [child]) {
52
- if (okay) {
53
- break
54
- }
55
- for (const parentT of parent.types || [parent]) {
56
- if (hierarchy.isA(childT, parentT)) {
57
- okay = true
44
+
45
+ if (strict) {
46
+ if (child.marker) {
47
+ child = child.marker
48
+ }
49
+ if (parent.marker) {
50
+ parent = parent.marker
51
+ }
52
+ return hierarchy.isA(child, parent)
53
+ } else {
54
+ const children = propertyToArray(child)
55
+ for (const child of children) {
56
+ let okay = false
57
+ if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
58
+ okay = true
59
+ } else {
60
+ for (const childT of child.types || [child]) {
61
+ if (okay) {
58
62
  break
59
63
  }
64
+ for (const parentT of parent.types || [parent]) {
65
+ if (hierarchy.isA(childT, parentT)) {
66
+ okay = true
67
+ break
68
+ }
69
+ }
60
70
  }
61
71
  }
72
+ if (!okay) {
73
+ return false
74
+ }
62
75
  }
63
- if (!okay) {
64
- return false
65
- }
76
+ return true
66
77
  }
67
- return true
68
78
  }
69
79
  }
70
80
 
@@ -86,8 +86,8 @@ function getTime(time) {
86
86
  return { hour, minute, second }
87
87
  }
88
88
 
89
- instantiate = (isA, now, context) => {
90
- const getType = (context, type) => {
89
+ function instantiate(isA, now, context) {
90
+ function getType(context, type) {
91
91
  if (context.marker == 'onDate_dates' && context.date?.marker == type) {
92
92
  return context.date
93
93
  } if (context.marker == type) {
@@ -92,7 +92,7 @@ class API {
92
92
  }
93
93
 
94
94
  // TODO handle the general case
95
- const fixUps = (concept) => {
95
+ function fixUps(concept) {
96
96
  if (concept == '*') {
97
97
  return '\\*'
98
98
  }
@@ -13,7 +13,7 @@ function getVariables(expression, isVariable = (expression) => typeof expression
13
13
  return []
14
14
  }
15
15
 
16
- const match = (values, head, value) => {
16
+ function match(values, head, value) {
17
17
  for (const prop in head) {
18
18
  if (head[prop] instanceof Function) {
19
19
  if (!head[prop](value[prop])) {
@@ -33,22 +33,24 @@ const match = (values, head, value) => {
33
33
  return true
34
34
  }
35
35
 
36
- const unify = (rule, value) => {
36
+ function unify(rule, value) {
37
37
  const values = { ...rule.values }
38
38
  if (match(values, rule.head(values), value)) {
39
39
  return rule.body(values)
40
40
  }
41
41
  }
42
42
 
43
- const f = (values, variable) => (value) => {
44
- if (!value) {
45
- throw new Error("Value not present")
46
- }
47
- if (values[variable] && values[variable] != value) {
48
- throw new Error("Variable already set to different value")
43
+ function f(values, variable) {
44
+ return (value) => {
45
+ if (!value) {
46
+ throw new Error("Value not present")
47
+ }
48
+ if (values[variable] && values[variable] != value) {
49
+ throw new Error("Variable already set to different value")
50
+ }
51
+ values[variable] = value
52
+ return true
49
53
  }
50
- values[variable] = value
51
- return true
52
54
  }
53
55
 
54
56
  const rules = [
@@ -74,7 +76,7 @@ const rules = [
74
76
  ]
75
77
 
76
78
  function solveFor(expression, variable, isVariable = (expression) => typeof expression.value != 'number') {
77
- const sameVar = (c1, c2) => {
79
+ function sameVar(c1, c2) {
78
80
  return c1.value == c2.value
79
81
  }
80
82
 
@@ -1,10 +1,10 @@
1
- const calculateLefts = (defs) => {
1
+ function calculateLefts(defs) {
2
2
  const lefts = {}
3
3
  calculateLeftsHelper(defs, lefts)
4
4
  return lefts
5
5
  }
6
6
 
7
- const calculateLeftsHelper = (defs, lefts) => {
7
+ function calculateLeftsHelper(defs, lefts) {
8
8
  if (Array.isArray(defs)) {
9
9
  let previous
10
10
  for (const def of defs) {
@@ -19,13 +19,13 @@ const calculateLeftsHelper = (defs, lefts) => {
19
19
  return lefts
20
20
  }
21
21
 
22
- const calculateRights = (defs) => {
22
+ function calculateRights(defs) {
23
23
  const rights = {}
24
24
  calculateRightsHelper(defs, rights)
25
25
  return rights
26
26
  }
27
27
 
28
- const calculateRightsHelper = (defs, rights) => {
28
+ function calculateRightsHelper(defs, rights) {
29
29
  if (Array.isArray(defs)) {
30
30
  let previous
31
31
  for (const def of defs) {
@@ -40,13 +40,13 @@ const calculateRightsHelper = (defs, rights) => {
40
40
  return rights
41
41
  }
42
42
 
43
- const calculateDowns = (defs) => {
43
+ function calculateDowns(defs) {
44
44
  const downs = {}
45
45
  calculateDownsHelper(defs, downs)
46
46
  return downs
47
47
  }
48
48
 
49
- const calculateDownsHelper = (defs, downs) => {
49
+ function calculateDownsHelper(defs, downs) {
50
50
  if (Array.isArray(defs)) {
51
51
  for (const def of defs) {
52
52
  calculateDownsHelper(def, downs)
@@ -72,13 +72,13 @@ const calculateDownsHelper = (defs, downs) => {
72
72
  return downs
73
73
  }
74
74
 
75
- const calculateUps = (defs) => {
75
+ function calculateUps(defs) {
76
76
  const ups = {}
77
77
  calculateUpsHelper(defs, ups)
78
78
  return ups
79
79
  }
80
80
 
81
- const calculateUpsHelper = (defs, ups) => {
81
+ function calculateUpsHelper(defs, ups) {
82
82
  if (Array.isArray(defs)) {
83
83
  for (const def of defs) {
84
84
  calculateUpsHelper(def, ups)
@@ -100,13 +100,13 @@ const calculateUpsHelper = (defs, ups) => {
100
100
  return ups
101
101
  }
102
102
 
103
- const calculateParents = (defs) => {
103
+ function calculateParents(defs) {
104
104
  const parents = {}
105
105
  calculateParentsHelper(defs, parents)
106
106
  return parents
107
107
  }
108
108
 
109
- const calculateParentsHelper = (defs, parents) => {
109
+ function calculateParentsHelper(defs, parents) {
110
110
  if (Array.isArray(defs)) {
111
111
  for (const def of defs) {
112
112
  parents[def.key] = def.key
@@ -123,13 +123,13 @@ const calculateParentsHelper = (defs, parents) => {
123
123
  return parents
124
124
  }
125
125
 
126
- const calculatePaths = (defs) => {
126
+ function calculatePaths(defs) {
127
127
  const paths = {}
128
128
  calculatePathsHelper(defs, paths)
129
129
  return paths
130
130
  }
131
131
 
132
- const calculatePathsHelper = (defs, paths) => {
132
+ function calculatePathsHelper(defs, paths) {
133
133
  if (Array.isArray(defs)) {
134
134
  for (const def of defs) {
135
135
  calculatePathsHelper(def, paths)
@@ -1,6 +1,6 @@
1
1
  const _ = require('lodash')
2
2
 
3
- const hashIndexesGet = (hash, indexes) => {
3
+ function hashIndexesGet(hash, indexes) {
4
4
  let value = hash
5
5
  for (const i of indexes) {
6
6
  value = value[i]
@@ -8,7 +8,7 @@ const hashIndexesGet = (hash, indexes) => {
8
8
  return value
9
9
  }
10
10
 
11
- const hashIndexesSet = (hash, indexes, value) => {
11
+ function hashIndexesSet(hash, indexes, value) {
12
12
  let currentValue = hash
13
13
  for (const i of indexes.slice(0, -1)) {
14
14
  if (!currentValue[i]) {
@@ -19,7 +19,7 @@ const hashIndexesSet = (hash, indexes, value) => {
19
19
  currentValue[indexes[indexes.length-1]] = value
20
20
  }
21
21
 
22
- const isPrefix = (prefix, fix) => {
22
+ function isPrefix(prefix, fix) {
23
23
  return prefix.every((element, index) => {
24
24
  return prefix[index] === fix[index]
25
25
  })
@@ -27,11 +27,11 @@ const isPrefix = (prefix, fix) => {
27
27
  }
28
28
 
29
29
  // assumes isPrefix is true
30
- const replacePrefix = (prefix, prefixPrime, fix) => {
30
+ function replacePrefix(prefix, prefixPrime, fix) {
31
31
  return prefixPrime.concat(fix.slice(prefix.length))
32
32
  }
33
33
 
34
- const compose = (m1s, m2s) => {
34
+ function compose(m1s, m2s) {
35
35
  return m2s.map( (m2) => {
36
36
  m1 = m1s.find( (m1) => isPrefix(m1.from, m2.from) )
37
37
  if (m1) {
@@ -48,7 +48,7 @@ const compose = (m1s, m2s) => {
48
48
  '[{"from":["two"],"to":["owner"]},{"from":["one"],"to":["ownee"]},{"from":["number"],"to":["number"]}]'
49
49
  */
50
50
 
51
- const translationMapping = (from, to) => {
51
+ function translationMapping(from, to) {
52
52
  const mappings = []
53
53
  if (from.atomic) {
54
54
  return mappings
@@ -89,7 +89,7 @@ const translationMapping = (from, to) => {
89
89
  return mappings
90
90
  }
91
91
 
92
- const translationMappings = (froms, to) => {
92
+ function translationMappings(froms, to) {
93
93
  const mappingss = []
94
94
  for (const from of froms) {
95
95
  mappingss.push(translationMapping(from, to))
@@ -97,7 +97,7 @@ const translationMappings = (froms, to) => {
97
97
  return mappingss
98
98
  }
99
99
 
100
- const translationMappingToInstantiatorMappings = (translationMapping, from , to) => {
100
+ function translationMappingToInstantiatorMappings(translationMapping, from , to) {
101
101
  return translationMapping.map( (tm) => {
102
102
  return {
103
103
  // match: ({context}) => context.value == to[tm.to].value,