tpmkms_4wp 9.5.1-beta.9 → 9.6.0-beta.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 (114) hide show
  1. package/common/animals.instance.json +130 -0
  2. package/common/animals.js +3 -5
  3. package/common/asking.js +12 -4
  4. package/common/avatar.test.json +1001 -860
  5. package/common/can.instance.json +2182 -5
  6. package/common/can.js +102 -39
  7. package/common/can.test.json +51307 -0
  8. package/common/colors.instance.json +142 -30
  9. package/common/colors.js +3 -6
  10. package/common/comparable.instance.json +31 -1
  11. package/common/comparable.js +3 -6
  12. package/common/concept.js +25 -27
  13. package/common/concept.test.json +142 -120
  14. package/common/conjunction.test.json +32 -42
  15. package/common/crew.instance.json +400 -126
  16. package/common/crew.js +3 -6
  17. package/common/dateTimeSelectors.instance.json +2 -2
  18. package/common/dateTimeSelectors.js +6 -9
  19. package/common/dateTimeSelectors.test.json +76935 -35739
  20. package/common/dates.instance.json +50 -84
  21. package/common/dates.js +3 -6
  22. package/common/dates.test.json +284 -287
  23. package/common/dialogues.js +33 -115
  24. package/common/dialogues.test.json +1248 -1152
  25. package/common/dimension.instance.json +21498 -566
  26. package/common/dimension.js +147 -52
  27. package/common/dimension.test.json +10979 -4625
  28. package/common/drone.instance.json +24709 -0
  29. package/common/drone.js +662 -0
  30. package/common/drone.test.json +30522 -0
  31. package/common/drone_v1.instance.json +24703 -0
  32. package/common/drone_v1.js +596 -0
  33. package/common/drone_v1.test.json +115538 -0
  34. package/common/edible.instance.json +365 -65
  35. package/common/edible.js +3 -5
  36. package/common/emotions.instance.json +57 -70
  37. package/common/emotions.js +3 -6
  38. package/common/errors.js +3 -3
  39. package/common/fastfood.instance.json +1270 -244
  40. package/common/fastfood.js +10 -12
  41. package/common/fastfood.test.json +6970 -6829
  42. package/common/formulas.instance.json +10 -0
  43. package/common/formulas.js +2 -1
  44. package/common/gdefaults.js +58 -13
  45. package/common/help.js +9 -9
  46. package/common/help.test.json +65 -11
  47. package/common/helpers/dialogues.js +9 -1
  48. package/common/helpers/properties.js +37 -18
  49. package/common/helpers.js +32 -2
  50. package/common/hierarchy.js +10 -8
  51. package/common/kirk.instance.json +10 -0
  52. package/common/kirk.js +4 -6
  53. package/common/kirk.test.json +600 -424
  54. package/common/latin.instance.json +10 -10
  55. package/common/latin.js +8 -10
  56. package/common/length.instance.json +34659 -3157
  57. package/common/length.js +11 -6
  58. package/common/length.test.json +54357 -2557
  59. package/common/math.instance.json +11 -1
  60. package/common/math.js +2 -1
  61. package/common/menus.instance.json +74 -7
  62. package/common/menus.js +3 -12
  63. package/common/meta.js +4 -5
  64. package/common/nameable.js +29 -15
  65. package/common/nameable.test.json +436 -0
  66. package/common/numbers.js +1 -1
  67. package/common/ordering.instance.json +24 -2
  68. package/common/ordering.js +3 -5
  69. package/common/ordering.test.json +104 -174
  70. package/common/people.instance.json +140 -315
  71. package/common/people.js +3 -5
  72. package/common/pipboy.instance.json +171 -57
  73. package/common/pipboy.js +2 -1
  74. package/common/pokemon.instance.json +135 -5
  75. package/common/pokemon.js +3 -5
  76. package/common/pressure.instance.json +3990 -1981
  77. package/common/pressure.js +3 -5
  78. package/common/pressure.test.json +433 -477
  79. package/common/properties.instance.json +15 -16
  80. package/common/properties.js +10 -9
  81. package/common/properties.test.json +9565 -6951
  82. package/common/rates.instance.json +59 -0
  83. package/common/rates.js +95 -0
  84. package/common/rates.test.json +27702 -0
  85. package/common/reminders.js +5 -8
  86. package/common/reminders.test.json +64635 -25787
  87. package/common/reports.instance.json +22 -2
  88. package/common/reports.js +3 -5
  89. package/common/scorekeeper.js +3 -6
  90. package/common/spock.instance.json +10 -0
  91. package/common/spock.js +4 -7
  92. package/common/spock.test.json +606 -430
  93. package/common/stm.js +37 -20
  94. package/common/temperature.instance.json +3162 -1153
  95. package/common/temperature.js +3 -5
  96. package/common/temperature.test.json +433 -477
  97. package/common/time.instance.json +24852 -0
  98. package/common/time.js +136 -139
  99. package/common/time.test.json +31876 -3757
  100. package/common/ui.instance.json +12 -5
  101. package/common/ui.js +4 -13
  102. package/common/weight.instance.json +10500 -4098
  103. package/common/weight.js +3 -5
  104. package/common/weight.test.json +2601 -2263
  105. package/common/words.instance.json +9 -0
  106. package/common/words.js +50 -0
  107. package/common/words.test.json +2 -0
  108. package/common/wp.instance.json +470 -58
  109. package/common/wp.js +6 -4
  110. package/common/wp.test.json +7385 -6906
  111. package/main.js +6 -2
  112. package/package.json +21 -6
  113. package/common/listener.js +0 -50
  114. 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
 
@@ -191,14 +275,25 @@ knowledgeModule({
191
275
 
192
276
  module,
193
277
  description: 'Used to define numeric temperature such as currency, temperature or weight',
194
- template: { template, instance },
278
+ instance,
279
+ template,
195
280
  test: {
196
281
  name: './dimension.test.json',
197
282
  contents: tests,
198
283
  checks: {
199
- objects: [{ km: 'properties' }],
284
+ objects: [
285
+ { km: 'properties' },
286
+ { path: ['measurementSystem'] },
287
+ ],
200
288
  context: [
201
- defaultContextCheck(),
289
+ defaultContextCheck({ marker: 'metric_system', exported: true }),
290
+ defaultContextCheck({ marker: 'convertToUnits', exported: true, extra: ['from', 'to'] }),
291
+ defaultContextCheck({
292
+ match: ({context, isA}) => isA(context.marker, 'unit'),
293
+ exported: true,
294
+ extra: ['dimension'],
295
+ }),
296
+ // defaultContextCheck(['dimension', 'response']),
202
297
  ],
203
298
  },
204
299
  },