tpmkms_4wp 9.5.1-beta.9 → 9.6.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 (87) hide show
  1. package/common/asking.js +12 -4
  2. package/common/avatar.test.json +1001 -860
  3. package/common/can.instance.json +2162 -5
  4. package/common/can.js +101 -35
  5. package/common/can.test.json +51307 -0
  6. package/common/colors.instance.json +2 -30
  7. package/common/comparable.instance.json +1 -1
  8. package/common/concept.js +25 -27
  9. package/common/concept.test.json +142 -120
  10. package/common/conjunction.test.json +32 -42
  11. package/common/crew.instance.json +163 -113
  12. package/common/dateTimeSelectors.instance.json +2 -2
  13. package/common/dateTimeSelectors.js +3 -3
  14. package/common/dateTimeSelectors.test.json +76935 -35739
  15. package/common/dates.instance.json +0 -84
  16. package/common/dates.test.json +284 -287
  17. package/common/dialogues.js +31 -112
  18. package/common/dialogues.test.json +1171 -996
  19. package/common/dimension.instance.json +21374 -562
  20. package/common/dimension.js +145 -51
  21. package/common/dimension.test.json +8753 -3495
  22. package/common/drone.instance.json +23712 -0
  23. package/common/drone.js +448 -0
  24. package/common/drone.test.json +66665 -0
  25. package/common/edible.instance.json +9 -65
  26. package/common/emotions.instance.json +47 -70
  27. package/common/errors.js +3 -3
  28. package/common/fastfood.instance.json +758 -266
  29. package/common/fastfood.js +7 -7
  30. package/common/fastfood.test.json +6970 -6829
  31. package/common/gdefaults.js +58 -13
  32. package/common/help.js +9 -9
  33. package/common/help.test.json +65 -11
  34. package/common/helpers/dialogues.js +6 -1
  35. package/common/helpers/properties.js +36 -16
  36. package/common/helpers.js +32 -2
  37. package/common/hierarchy.js +3 -1
  38. package/common/kirk.test.json +600 -424
  39. package/common/latin.instance.json +10 -10
  40. package/common/latin.js +5 -5
  41. package/common/length.instance.json +27611 -2889
  42. package/common/length.js +6 -1
  43. package/common/length.test.json +45315 -3925
  44. package/common/math.instance.json +1 -1
  45. package/common/menus.instance.json +4 -7
  46. package/common/menus.js +1 -8
  47. package/common/meta.js +1 -0
  48. package/common/nameable.js +13 -6
  49. package/common/nameable.test.json +436 -0
  50. package/common/numbers.js +1 -1
  51. package/common/ordering.instance.json +4 -2
  52. package/common/ordering.test.json +104 -174
  53. package/common/people.instance.json +60 -315
  54. package/common/pipboy.instance.json +1 -57
  55. package/common/pokemon.instance.json +5 -5
  56. package/common/pressure.instance.json +3959 -1990
  57. package/common/pressure.test.json +433 -477
  58. package/common/properties.instance.json +5 -16
  59. package/common/properties.js +3 -3
  60. package/common/properties.test.json +9565 -6951
  61. package/common/rates.instance.json +59 -0
  62. package/common/rates.js +97 -0
  63. package/common/rates.test.json +27702 -0
  64. package/common/reminders.js +2 -2
  65. package/common/reminders.test.json +64635 -25787
  66. package/common/reports.instance.json +2 -2
  67. package/common/spock.test.json +606 -430
  68. package/common/stm.js +13 -2
  69. package/common/temperature.instance.json +3658 -1689
  70. package/common/temperature.test.json +433 -477
  71. package/common/time.instance.json +24762 -0
  72. package/common/time.js +135 -139
  73. package/common/time.test.json +31876 -3757
  74. package/common/ui.instance.json +2 -5
  75. package/common/ui.js +1 -8
  76. package/common/weight.instance.json +10359 -4077
  77. package/common/weight.test.json +2601 -2263
  78. package/common/words.instance.json +9 -0
  79. package/common/words.js +53 -0
  80. package/common/words.test.json +2 -0
  81. package/common/wp.instance.json +330 -58
  82. package/common/wp.js +4 -0
  83. package/common/wp.test.json +7385 -6906
  84. package/main.js +4 -2
  85. package/package.json +16 -5
  86. package/common/listener.js +0 -50
  87. package/common/listener.test.json +0 -142
@@ -1,5 +1,5 @@
1
- const { knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
- const { defaultObjectCheck, defaultContextCheck } = require('./helpers')
1
+ const { debug, knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
+ const { defaultObjectCheck, defaultContextCheck, defaultContextCheckProperties } = require('./helpers')
3
3
  const hierarchy = require('./hierarchy.js')
4
4
  const formulas = require('./formulas.js')
5
5
  const testing = require('./testing.js')
@@ -11,6 +11,14 @@ const instance = require('./dimension.instance.json')
11
11
  x fahrenheit equals (x-32)*5/9 + 32 fahrenheit
12
12
  10 celcius + 5
13
13
 
14
+ 1 meter 10 centimeters
15
+
16
+ 1 meter in feet and inches
17
+ 10 feet in meters and inches
18
+
19
+ show length in feet and inches
20
+ show length in meters and millimeters
21
+
14
22
  10 C
15
23
 
16
24
  use a digraph for calculating convertions
@@ -24,8 +32,21 @@ const instance = require('./dimension.instance.json')
24
32
  */
25
33
  class API {
26
34
 
27
- initialize({ config }) {
35
+ initialize({ config, objects }) {
28
36
  this._config = config
37
+ this._objects = objects
38
+ }
39
+
40
+ setMeasurementSystem(measurementSystem) {
41
+ this._objects.measurementSystem = measurementSystem
42
+ }
43
+
44
+ // if the user says 2 feet deduce english etc
45
+ deduceMeasurementSystem(utterance) {
46
+ }
47
+
48
+ getMeasurementSystem() {
49
+ return this._objects.measurementSystem
29
50
  }
30
51
 
31
52
  setup( {dimension, units} ) {
@@ -50,24 +71,23 @@ class API {
50
71
  }
51
72
  }
52
73
 
53
- const api = new API()
74
+ // eg, dimension == length; meters == unit; 2 meters == quantity
54
75
 
55
76
  const config = {
56
77
  name: 'dimension',
57
78
  operators: [
58
- "([dimension])",
79
+ "([quantity])",
59
80
  "([unit])",
60
- // "(([unit]) [kindOfDimension|of] ([dimension]))",
61
- "((amount/* || number/*) [amountOfDimension|] ([unit]))",
81
+ "((amount/* || number/*) [amountOfCoordinate|] ([unit]))",
62
82
  "(([amount]) [unit])",
63
- "((dimension) [convertToUnits|in] (unit))",
83
+ "((@<=quantity || context.possession == true) [convertToUnits|in] (unit))",
64
84
 
65
85
  "(([number]) [degree])",
66
86
  { pattern: "([length])", scope: "testing" },
67
87
  ],
68
88
  priorities: [
69
89
  // TODO this should have been calculated
70
- { "context": [['amountOfDimension', 0], ['convertToUnits', 0], ], "choose": [0] },
90
+ { "context": [['amountOfCoordinate', 0], ['convertToUnits', 0], ], "choose": [0] },
71
91
  ],
72
92
  hierarchy: [
73
93
  { child: 'convertToUnits', parent: 'testingValue', scope: "testing" },
@@ -83,12 +103,13 @@ const config = {
83
103
  {
84
104
  where: where(),
85
105
  id: "dimension",
106
+ },
107
+ {
108
+ where: where(),
109
+ id: "quantity",
110
+ isA: ["noun"],
86
111
  bridge: "{ ...next(operator) }",
87
- isA: [],
88
- generatorpr: {
89
- match: ({context}) => context.amount,
90
- apply: async ({context, gp, gr}) => `${await gr(context.amount)} ${await gp(context.unit)}`,
91
- },
112
+ generatorpr: async ({context, gp, gr}) => `${await gr(context.amount)} ${await gp(context.unit)}`,
92
113
  },
93
114
  {
94
115
  id: "length",
@@ -97,15 +118,6 @@ const config = {
97
118
  scope: "testing"
98
119
  },
99
120
  { id: "amount", },
100
- /*
101
- {
102
- id: "kindOfDimension",
103
- bridge: "{ ...next(operator), subclass: before[0], class: after[0], value: concat(before[0].marker.id, after[0].marker.id) }",
104
- // bridge: "{ ...next(operator), subclass: before[0], class: after[0], value: concat(before[0].marker, after[0].marker) }",
105
- isA: ['preposition'],
106
- generatorp: ({context, gp}) => `${gp(context.subclass)} ${context.word} ${gp(context.class)}`,
107
- },
108
- */
109
121
  {
110
122
  where: where(),
111
123
  id: "degree",
@@ -115,9 +127,9 @@ const config = {
115
127
  bridge: "{ ...next(operator), value: before[0].value, amount: before[0] }",
116
128
  },
117
129
  {
118
- id: "amountOfDimension",
130
+ id: "amountOfCoordinate",
119
131
  convolution: true,
120
- bridge: "{ marker: operator('dimension'), unit: after[0], value: before[0].value, amount: before[0] }"
132
+ bridge: "{ marker: next(operator('quantity')), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
121
133
  },
122
134
  {
123
135
  where: where(),
@@ -128,31 +140,53 @@ const config = {
128
140
  after: [['possession', 0], ['possession', 1]],
129
141
  generatorp: async ({context, g}) => `${await g(context.from)} ${context.word} ${await g(context.to)}`,
130
142
  // evaluator: ({context, kms, error}) => {
131
- evaluator: async ({context, kms, e, error}) => {
132
- /*
133
- error(({context, e}) => {
134
- context.evalue = 'dont know...'
135
- })
136
- */
143
+ evaluator: async ({context, kms, e, error, toArray, gp, gr, toList}) => {
137
144
  const from = context.from;
138
- const to = context.to;
145
+ const tos = toArray(context.to);
139
146
  let evalue;
140
147
  let efrom = from
141
148
  if (!from.unit) {
142
149
  efrom = (await e(from)).evalue
143
150
  }
144
- if (to.value == efrom.unit.value) {
145
- evalue = efrom.amount
146
- } else {
147
- const formula = kms.formulas.api.get(to, [efrom.unit])
148
- if (!formula) {
149
- const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }
150
- kms.stm.api.mentioned({ context: reason })
151
- error(reason)
151
+ async function convert(to) {
152
+ if (to.value == efrom.unit.value) {
153
+ evalue = efrom.amount
154
+ evalue.evalue = efrom.amount.value
155
+ } else {
156
+ const formula = kms.formulas.api.get(to, [efrom.unit])
157
+ if (!formula) {
158
+ const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }
159
+ kms.stm.api.mentioned({ context: reason })
160
+ error(reason)
161
+ }
162
+ kms.stm.api.setVariable(efrom.unit.value, efrom.amount)
163
+ evalue = await e(formula)
152
164
  }
153
- kms.stm.api.setVariable(efrom.unit.value, efrom.amount)
154
- evalue = await e(formula)
165
+ return evalue
166
+ }
167
+
168
+ let evalues = []
169
+ for (const to of tos) {
170
+ evalues.push({ value: await convert(to), to: structuredClone(to) })
171
+ }
172
+ evalues.sort((a, b) => a.evalue - b.evalue )
173
+
174
+ let fractionalPart = 0
175
+ let scale = 1
176
+ for (const evalue of evalues) {
177
+ const value = evalue.value.evalue * scale
178
+ const integerPart = Math.trunc(value)
179
+ fractionalPart = Math.abs(value - integerPart)
180
+ evalue.value.evalue = integerPart
181
+ scale = fractionalPart / value * scale
155
182
  }
183
+ // evalues[evalues.length-1].value.evalue = Number((integerPart * (1+scale)).toFixed(4))
184
+ evalues[evalues.length-1].value.evalue += fractionalPart
185
+ evalues[evalues.length-1].value.evalue = Number(evalues[evalues.length-1].value.evalue.toFixed(4))
186
+
187
+ // remove the zeros
188
+ evalues = evalues.filter( (evalue) => evalue.value.evalue )
189
+
156
190
  /*
157
191
  '{
158
192
  "marker":"dimension",
@@ -161,12 +195,21 @@ const config = {
161
195
  "amount":{"word":"degrees","number":"many","text":"10 degrees","marker":"degree","range":{"start":8,"end":17},"value":10,"amount":{"value":10,"text":"10","marker":"number","word":"10","range":{"start":8,"end":9},"types":["number"]}},
162
196
  "text":"10 degrees celcius","range":{"start":8,"end":25}}'
163
197
  */
164
- context.evalue = {
165
- paraphrase: true,
166
- marker: 'dimension',
167
- level: 1,
168
- unit: to,
169
- amount: { evalue, paraphrase: undefined }
198
+ evalues = evalues.map((evalue) => {
199
+ const number = evalue.value.evalue == 1 ? 'one' : 'many'
200
+ evalue.to.number = number
201
+ return {
202
+ paraphrase: true,
203
+ marker: 'quantity',
204
+ level: 1,
205
+ unit: evalue.to,
206
+ amount: { evalue: evalue.value, paraphrase: undefined }
207
+ }
208
+ })
209
+ if (evalues.length > 1) {
210
+ context.evalue = toList(evalues)
211
+ } else {
212
+ context.evalue = evalues[0]
170
213
  }
171
214
  },
172
215
  },
@@ -179,8 +222,49 @@ const config = {
179
222
 
180
223
  const template = {
181
224
  configs: [
182
- "dimension and unit are concepts",
225
+ "measurement modifies unit",
226
+ "dimension and measurement unit are concepts",
227
+ "unit means measurement unit",
228
+ ({apis}) => {
229
+ apis('properties').addHierarchyWatcher({
230
+ match: ({parentId, isA}) => isA(parentId, 'unit') && parentId.startsWith('unit_'),
231
+ apply: ({config, childId, parent, parentId}) => {
232
+ config.updateBridge(childId, ({ bridge }) => {
233
+ if (!bridge.init) {
234
+ bridge.init = {}
235
+ }
236
+ // bridge.init['dimension'] = parent.object.marker
237
+ bridge.init['dimension'] = parent.object.value
238
+ })
239
+ }
240
+ })
241
+ },
242
+ "metric modifies system",
243
+ "imperial modifies system",
244
+ "measurement modifies system",
245
+ "the metric system is a measurement system",
246
+ "the imperial system is a measurement system",
247
+ "imperial modifies unit",
248
+ "metric modifies unit",
249
+ "imperial unit is a unit",
250
+ "metric unit is a unit",
183
251
  config,
252
+ {
253
+ operators: [
254
+ "([useMeasurementSystem|use] (measurement_system))",
255
+ ],
256
+ bridges: [
257
+ {
258
+ id: 'useMeasurementSystem',
259
+ isA: ['verb'],
260
+ bridge: "{ ...next(operator), system: after[0], interpolate: [ { context: operator }, { property: 'system' } ] }",
261
+ semantic: ({context, api}) => {
262
+ api.setMeasurementSystem(context.system.value)
263
+ },
264
+ check: defaultContextCheckProperties(['system']),
265
+ },
266
+ ],
267
+ },
184
268
  ],
185
269
  }
186
270
 
@@ -196,9 +280,19 @@ knowledgeModule({
196
280
  name: './dimension.test.json',
197
281
  contents: tests,
198
282
  checks: {
199
- objects: [{ km: 'properties' }],
283
+ objects: [
284
+ { km: 'properties' },
285
+ { path: ['measurementSystem'] },
286
+ ],
200
287
  context: [
201
- defaultContextCheck(),
288
+ defaultContextCheck({ marker: 'metric_system', exported: true }),
289
+ defaultContextCheck({ marker: 'convertToUnits', exported: true, extra: ['from', 'to'] }),
290
+ defaultContextCheck({
291
+ match: ({context, isA}) => isA(context.marker, 'unit'),
292
+ exported: true,
293
+ extra: ['dimension'],
294
+ }),
295
+ // defaultContextCheck(['dimension', 'response']),
202
296
  ],
203
297
  },
204
298
  },