tpmkms 9.8.0 → 9.9.0

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 (95) hide show
  1. package/common/actions.instance.json +10 -8
  2. package/common/actions.js +13 -11
  3. package/common/angle.instance.json +25 -17
  4. package/common/animals.instance.json +54 -28
  5. package/common/askfor.instance.json +89 -192
  6. package/common/askfor.js +49 -12
  7. package/common/asking.js +13 -5
  8. package/common/avatar.js +3 -3
  9. package/common/can.instance.json +32 -20
  10. package/common/can.js +2 -2
  11. package/common/colors.instance.json +44 -16
  12. package/common/colors.js +1 -1
  13. package/common/comparable.instance.json +25 -22
  14. package/common/compass.instance.json +9 -3
  15. package/common/concept.instance.json +14 -6
  16. package/common/concept.js +2 -0
  17. package/common/conjunction.js +17 -9
  18. package/common/control.js +10 -18
  19. package/common/countable.js +4 -3
  20. package/common/crew.instance.json +95 -27
  21. package/common/dateTimeSelectors.instance.json +4 -4
  22. package/common/dateTimeSelectors.js +4 -7
  23. package/common/dates.instance.json +52 -28
  24. package/common/dates.js +16 -11
  25. package/common/debug.instance.json +48 -0
  26. package/common/debug.js +50 -0
  27. package/common/debug.test.json +1 -0
  28. package/common/dialogues.js +126 -70
  29. package/common/dimension.instance.json +239 -495
  30. package/common/dimension.js +51 -9
  31. package/common/drone.instance.json +395 -84
  32. package/common/drone.js +43 -50
  33. package/common/drone_v1.instance.json +36 -12
  34. package/common/drone_v1.js +14 -9
  35. package/common/edible.instance.json +96 -32
  36. package/common/emotions.instance.json +15 -1
  37. package/common/evaluate.js +10 -13
  38. package/common/fastfood.instance.json +282 -100
  39. package/common/fastfood.js +30 -15
  40. package/common/formulas.instance.json +162 -24
  41. package/common/formulas.js +18 -9
  42. package/common/gdefaults.js +20 -96
  43. package/common/helpers/concept.js +2 -9
  44. package/common/helpers/conjunction.js +11 -1
  45. package/common/helpers/dialogues.js +48 -24
  46. package/common/helpers/gdefaults.js +15 -5
  47. package/common/helpers/properties.js +125 -326
  48. package/common/helpers.js +28 -58
  49. package/common/hierarchy.js +71 -41
  50. package/common/kirk.instance.json +3 -1
  51. package/common/latin.instance.json +10 -10
  52. package/common/latin.js +5 -5
  53. package/common/length.instance.json +247 -61
  54. package/common/math.instance.json +144 -5
  55. package/common/math.js +18 -5
  56. package/common/menus.instance.json +29 -11
  57. package/common/menus.js +8 -5
  58. package/common/meta.js +14 -13
  59. package/common/nameable.js +9 -5
  60. package/common/numbers.instance.json +5 -3
  61. package/common/numbers.js +28 -28
  62. package/common/ordering.instance.json +53 -4
  63. package/common/ordinals.js +25 -25
  64. package/common/people.instance.json +66 -12
  65. package/common/percentages.js +4 -2
  66. package/common/pipboy.instance.json +89 -44
  67. package/common/pipboy.js +21 -14
  68. package/common/pokemon.instance.json +39 -13
  69. package/common/pressure.instance.json +14 -6
  70. package/common/properties.instance.json +2370 -511
  71. package/common/properties.js +496 -78
  72. package/common/punctuation.js +1 -0
  73. package/common/rates.instance.json +2 -2
  74. package/common/rates.js +3 -3
  75. package/common/reminders.instance.json +16 -0
  76. package/common/reminders.js +24 -20
  77. package/common/reports.instance.json +11 -12
  78. package/common/reports.js +12 -12
  79. package/common/scorekeeper.js +20 -10
  80. package/common/sdefaults.js +30 -9
  81. package/common/spock.instance.json +3 -1
  82. package/common/stm.js +16 -21
  83. package/common/temperature.instance.json +19 -11
  84. package/common/testing.js +2 -2
  85. package/common/time.instance.json +104 -47
  86. package/common/time.js +9 -8
  87. package/common/ui.instance.json +4 -2
  88. package/common/ui.js +5 -5
  89. package/common/weight.instance.json +86 -21
  90. package/common/weight.js +5 -1
  91. package/common/words.js +113 -2
  92. package/common/wp.instance.json +125 -18
  93. package/common/wp.js +6 -2
  94. package/main.js +2 -0
  95. package/package.json +7 -3
@@ -3,6 +3,7 @@ const { interpolate } = require('./helpers/gdefaults')
3
3
  const { defaultContextCheck, getValue, isMany } = require('./helpers')
4
4
  const { debug, knowledgeModule, where, flatten } = require('./runtime').theprogrammablemind
5
5
  const tokenize = require('./tokenize.js')
6
+ const debugKM = require('./debug.js')
6
7
  const words = require('./words.js')
7
8
  const gdefaults_tests = require('./gdefaults.test.json')
8
9
  const englishHelpers = require('./english_helpers.js')
@@ -28,8 +29,8 @@ const config = {
28
29
  */
29
30
  {
30
31
  where: where(),
31
- match: ({context}) => context.isResponse && context.response,
32
- apply: ({context, gr}) => gr(context.response),
32
+ match: ({context}) => context.isResponse && context.evalue,
33
+ apply: ({context, gr}) => gr(context.evalue),
33
34
  },
34
35
 
35
36
  {
@@ -76,16 +77,13 @@ const config = {
76
77
 
77
78
  {
78
79
  where: where(),
79
- // match: ({context}) => context.evalue && !context.paraphrase,
80
80
  match: ({context, callId}) => context.evalue && !context.paraphrase,
81
- // match: ({context}) => context.evalue && context.isResponse,
82
81
  apply: async ({context, g}) => await g(context.evalue)
83
82
  },
84
83
 
85
84
  {
86
85
  where: where(),
87
86
  //({context}) => context.paraphrase && context.modifiers,
88
- // match: ({context}) => context.paraphrase && (context.modifiers || context.postModifiers),
89
87
  match: ({context}) => (context.modifiers || context.postModifiers),
90
88
  apply: async ({context, g, gs, callId}) => {
91
89
  const text = []
@@ -141,95 +139,17 @@ const config = {
141
139
  }
142
140
  },
143
141
 
144
- {
145
- where: where(),
146
- priority: -1,
147
- match: ({context}) => context.marker == 'modifies' && context.evaluateWord && context.paraphrase && context.number == 'one',
148
- apply: ({context}) => 'modifies'
149
- },
150
- {
151
- where: where(),
152
- priority: -1,
153
- match: ({context}) => context.marker == 'modifies' && context.evaluateWord && context.paraphrase && (context.number == 'many' || context.number > 1),
154
- apply: ({context}) => 'modify'
155
- },
156
-
157
- {
158
- where: where(),
159
- priority: -1,
160
- // match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'one' && !context.imperative && !context.interpolate,
161
- match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && !context.imperative && !context.interpolate,
162
- apply: ({context}) => {
163
- const infinitive = englishHelpers.getInfinitive(context.word)
164
- if (context.form == 'infinitive') {
165
- const cases = englishHelpers.conjugateVerb(infinitive)
166
- const def = cases.find((def) => def.form == context.form)
167
- return def.word
168
- } else if (context.tense) {
169
- const cases = englishHelpers.conjugateVerb(infinitive)
170
- const def = cases.find((def) => def.tense == context.tense)
171
- return def.word
172
- } else {
173
- return pluralize.plural(context.word)
174
- }
175
- },
176
- },
177
-
178
- /*
179
- {
180
- where: where(),
181
- priority: -1,
182
- match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'many' && !context.imperative && !context.interpolate,
183
- apply: ({context}) => {
184
- const infinitive = englishHelpers.getInfinitive(context.word)
185
- const cases = englishHelpers.conjugateVerb(infinitive)
186
- return pluralize.singular(context.word)
187
- },
188
- },
189
- */
190
- {
191
- where: where(),
192
- priority: -1,
193
- match: ({context}) => context.evaluateWord && context.paraphrase && context.word && (context.number == 'many' || context.number > 1) && !context.interpolate,
194
- apply: ({context}) => pluralize.plural(context.word),
195
- },
196
-
197
- {
198
- where: where(),
199
- priority: -1,
200
- match: ({context}) => context.evaluateWord && context.isVerb && context.paraphrase && context.word && context.number == 'one' && !context.imperative && !context.interpolate,
201
- apply: ({context}) => {
202
- const infinitive = englishHelpers.getInfinitive(context.word)
203
- const cases = englishHelpers.conjugateVerb(infinitive)
204
- return pluralize.plural(context.word)
205
- },
206
- },
207
-
208
- {
209
- where: where(),
210
- priority: -1,
211
- match: ({context}) => context.evaluateWord && context.paraphrase && context.word && context.number == 'one' && !context.interpolate,
212
- apply: ({context}) => {
213
- return pluralize.singular(context.word)
214
- },
215
- },
216
-
217
142
  {
218
143
  where: where(),
219
144
  match: ({context}) => context.paraphrase && context.word && (context.number == 'many' || context.number > 1) && !context.isModifier,
220
- apply: ({context}) => {
221
- // TODO make the sentence that the plural celcius is celcius work
222
- if (["fahrenheit", "celcius"].includes(context.word)) {
223
- return context.word
224
- }
225
- return pluralize.plural(context.word)
145
+ apply: ({context, kms}) => {
146
+ return kms.words.api.toPlural(context)
226
147
  }
227
148
  },
228
149
 
229
150
  {
230
151
  where: where(),
231
- // match: ({context}) => context.paraphrase && context.word && context.number == 'one',
232
- match: ({context}) => context.word !== null && context.number == 'one',
152
+ match: ({context}) => !!context.word && context.number == 'one',
233
153
  apply: ({context}) => {
234
154
  return pluralize.singular(context.word)
235
155
  }
@@ -237,9 +157,6 @@ const config = {
237
157
 
238
158
  {
239
159
  where: where(),
240
- // match: ({context}) => context.paraphrase && context.word,
241
- // match: ({context}) => context.word && !context.value,
242
- //match: ({context}) => context.word && typeof context.value == 'string',
243
160
  match: ({context}) => (context.paraphrase || typeof context.value == 'string') && context.word,
244
161
  apply: ({context}) => `${context.word}`
245
162
  },
@@ -256,6 +173,12 @@ const config = {
256
173
  apply: async ({context, gs}) => await gs(context.value)
257
174
  },
258
175
 
176
+ {
177
+ where: where(),
178
+ match: ({context, namespaced}) => context.marker == 'labelledValue' && context.useColon,
179
+ apply: async ({context, g, debug, callId, gp}) => `${await gp(context.label)}: ${await g(context.value, { assumed: { brief: true } })}`
180
+ },
181
+
259
182
  {
260
183
  where: where(),
261
184
  match: ({context, namespaced}) => context.marker == 'labelledValue',
@@ -282,7 +205,7 @@ const config = {
282
205
 
283
206
  {
284
207
  where: where(),
285
- match: ({context}) => context.marker == 'answerNotKnown',
208
+ match: ({context}) => context.marker === 'undefined',
286
209
  apply: ({context}) => 'That is not known',
287
210
  },
288
211
 
@@ -292,6 +215,12 @@ const config = {
292
215
  apply: ({context}) => context.marker,
293
216
  },
294
217
 
218
+ {
219
+ where: where(),
220
+ match: ({context}) => context.text,
221
+ apply: ({context}) => context.text,
222
+ },
223
+
295
224
  {
296
225
  where: where(),
297
226
  match: () => true,
@@ -319,11 +248,6 @@ function initializer({config}) {
319
248
  }
320
249
  },
321
250
  number: (context) => isMany(context) ? "many" : "one",
322
- // number/gender/person etc
323
- gw: (context, { number: numberContext }) => {
324
- const number = numberContext ? args.number(numberContext) : context.number;
325
- return args.gp( { ...context, evaluateWord: true, number } )
326
- },
327
251
  verbatim,
328
252
  say: verbatim,
329
253
  interpolate: interpolate(args),
@@ -333,7 +257,7 @@ function initializer({config}) {
333
257
 
334
258
  knowledgeModule({
335
259
  config,
336
- includes: [tokenize, words],
260
+ includes: [tokenize, words, debugKM],
337
261
  initializer,
338
262
 
339
263
  module,
@@ -49,14 +49,7 @@ class API {
49
49
  // TODO call evaluator to pick up overrides
50
50
  const objectSingular = pluralize.singular(objectWord)
51
51
  const objectPlural = pluralize.plural(objectWord)
52
- // config.addOperator({ pattern: `(${modifierIds.map((modifierId) => `(${modifierId}/*)`).join(' ')} [${modifiersObjectId}] (${objectId}/0))`, allowDups: true })
53
- if (false) {
54
- config.addOperator({ pattern: `(${modifierIds.map((modifierId) => `(${modifierId}/*)`).join(' ')} [${modifiersObjectId}] (${objectId}/*))`, allowDups: true })
55
- } else {
56
- config.addOperator({ pattern: `(${modifierIds.map((modifierId) => `(@==${modifierId})`).join(' ')} [${modifiersObjectId}] (@==${objectId}))`, allowDups: true })
57
- }
58
- // config.addOperator({ pattern: `(<${modifierId}|> ([${objectId}|]))`, allowDups: true })
59
- // config.addOperator({ pattern: `([${modifierObjectId}|])`, allowDups: true })
52
+ config.addOperator({ pattern: `(${modifierIds.map((modifierId) => `(@==${modifierId})`).join(' ')} [${modifiersObjectId}] (@==${objectId}))`, allowDups: true })
60
53
 
61
54
  const objectModifierConcept = `${objectId}_modifier`
62
55
  if (!config.exists(objectModifierConcept)) {
@@ -105,7 +98,7 @@ class API {
105
98
  id: modifiersObjectId,
106
99
  level: 0,
107
100
  convolution: true,
108
- isA: [{ parent: 'adjective', instance: true }],
101
+ isA: [{ parent: 'adjective', isInstance: true }],
109
102
  associator_return_type: [modifiersObjectId, 0],
110
103
  useForArgumentInference: false,
111
104
  // isA: ['adjective'],
@@ -59,6 +59,16 @@ function listable(hierarchy) {
59
59
  }
60
60
 
61
61
  function isA(hierarchy) {
62
+ const getId = (context) => {
63
+ if (typeof context === 'string') {
64
+ return context
65
+ }
66
+ if (context.marker === 'unknown') {
67
+ return context.value
68
+ }
69
+ return context.marker
70
+ }
71
+
62
72
  return (child, parent, { strict=false } = {}) => {
63
73
  const oneToOne = (child, parent) => {
64
74
  if (!child || !parent) {
@@ -77,7 +87,7 @@ function isA(hierarchy) {
77
87
  const children = propertyToArray(child)
78
88
  for (const child of children) {
79
89
  let okay = false
80
- if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
90
+ if (hierarchy.isA(getId(child), getId(parent))) {
81
91
  okay = true
82
92
  } else {
83
93
  for (const childT of child.types || [child]) {
@@ -1,5 +1,6 @@
1
+ const { flatten, debug } = require('../runtime').theprogrammablemind
1
2
  const pluralize = require('pluralize')
2
- const { indent, focus } = require('../helpers')
3
+ const { asList } = require('./conjunction.js')
3
4
 
4
5
  class API {
5
6
  initialize({ objects }) {
@@ -27,22 +28,13 @@ class API {
27
28
  }
28
29
  }
29
30
 
30
- warningNotEvaluated(log, value) {
31
- const description = 'WARNING from Dialogues KM: For semantics, implement an evaluations handler, set "value" property of the operator to the value.'
32
- const match = `({context}) => context.marker == '${value.marker}' && context.evaluate && <other conditions as you like>`
33
- const apply = `({context}) => <do stuff...>; context.value = <value>`
34
- const input = indent(JSON.stringify(value, null, 2), 2)
35
- const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
36
- log(indent(message, 4))
37
- }
38
-
39
31
  //
40
32
  // duck typing: for operators you want to use here
41
33
  //
42
34
  // 1. Use hierarchy to make them an instance of queryable. For example add hierarchy entry [<myClassId>, 'queryable']
43
35
  // 2. For semantics, if evaluate == true then set the 'value' property of the operator to the value.
44
36
  // 3. Generators will get contexts with 'response: true' set. Used for converting 'your' to 'my' to phrases like 'your car' or 'the car'.
45
- // 4. Generators will get contexts with 'instance: true' and value set. For converting values like a date to a string.
37
+ // 4. Generators will get contexts with 'isInstance: true' and value set. For converting values like a date to a string.
46
38
  //
47
39
 
48
40
  // used with context sensitive words like 'it', 'that' etc. for example if you have a sentence "create a tank"
@@ -56,17 +48,6 @@ class API {
56
48
  return this._objects.brief
57
49
  }
58
50
 
59
- async evaluateToConcept(value, context, log, s) {
60
- value.evaluate = { toConcept: true }
61
- const concept = await s(value)
62
- if (!concept.evalue && !concept.verbatim) {
63
- this.warningNotEvaluated(log, value);
64
- concept.evalue = concept.value
65
- }
66
- delete concept.evaluate
67
- return concept
68
- }
69
-
70
51
  setupObjectHierarchy(config, id, { types } = {}) {
71
52
  for (let type of types) {
72
53
  if (typeof type !== 'string') {
@@ -108,7 +89,7 @@ class API {
108
89
  }
109
90
 
110
91
  initial.value = source_value || concept
111
- await this.args.s({ value, makeObject: true, initial })
92
+ await this.args.e({ value, makeObject: true, initial })
112
93
  // config.addOperator({ pattern: `(["${fixUps(concept)}"])`, allowDups: true })
113
94
  config.addOperator({ pattern: `(["${concept}"|])`, allowDups: true })
114
95
  config.addBridge({ id: concept, level: 0, bridge: `{ ...operator, dead: true, value: or(operator.value, '${source_value || concept}') }` , allowDups: true })
@@ -151,6 +132,49 @@ class API {
151
132
  }
152
133
  }
153
134
 
135
+ function focus(context) {
136
+ function helper(context) {
137
+ let focusable = context?.focusable
138
+ if (!focusable && context.marker == 'list') {
139
+ focusable = ['value']
140
+ }
141
+ if (!focusable) {
142
+ return null
143
+ }
144
+ for (const property of focusable) {
145
+ if (Array.isArray(context[property])) {
146
+ const array = context[property]
147
+ const focussed = []
148
+ for (const value of array) {
149
+ const focus = helper(value)
150
+ if (focus) {
151
+ focussed.push(focus)
152
+ }
153
+ }
154
+ if (focussed.length > 0) {
155
+ return asList(focussed)
156
+ }
157
+ continue
158
+ }
159
+
160
+ let focus = helper(context[property])
161
+ if (!focus) {
162
+ const flat = flatten(['list'], context[property])[0]
163
+ for (const element of flat) {
164
+ if (element.focus) {
165
+ focus = context[property]
166
+ break
167
+ }
168
+ }
169
+ }
170
+ return focus
171
+ }
172
+ return null
173
+ }
174
+ return helper(context) || context
175
+ }
176
+
154
177
  module.exports = {
155
- API
178
+ API,
179
+ focus,
156
180
  }
@@ -1,3 +1,4 @@
1
+ const { getByPath, setByPath, } = require('../runtime').theprogrammablemind
1
2
  const helpers = require('../helpers')
2
3
 
3
4
  function interpolate(args) {
@@ -39,8 +40,13 @@ function interpolate(args) {
39
40
  strings.push(separator)
40
41
  strings.push(await args.gp({...context, interpolate: undefined}))
41
42
  separator = ' '
43
+ } else if (element.separator !== undefined && !element.values) {
44
+ separator = element.separator
42
45
  } else if (typeof element == 'string') {
43
- separator = element
46
+ if (separator) {
47
+ strings.push(separator)
48
+ }
49
+ strings.push(element)
44
50
  } else if (element.separator && element.values) {
45
51
  let ctr = 0
46
52
  const each = element.each
@@ -70,20 +76,24 @@ function interpolate(args) {
70
76
  separator = ' '
71
77
  }
72
78
  } else if (element.property) {
73
- value = context[element.property]
79
+ value = getByPath(context, element.property)
74
80
  if (value) {
75
81
  if (element.context) {
76
82
  value = { ...value, ...element.context }
77
83
  }
78
84
  async function handleProperty(value) {
79
- strings.push(separator)
80
85
  if (element.isQuantified && number && isLastElement) {
81
86
  value.number = number
82
87
  }
88
+ let str = ''
83
89
  if (Array.isArray(value)) {
84
- strings.push(await args.gsp(value))
90
+ str = await args.gsp(value)
85
91
  } else {
86
- strings.push(await args.gp(value))
92
+ str = await args.gp(value)
93
+ }
94
+ if (str) {
95
+ strings.push(separator)
96
+ strings.push(str)
87
97
  }
88
98
  separator = ' '
89
99
  }