tpmkms_4wp 9.5.1 → 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 (135) hide show
  1. package/common/animals.instance.json +151 -61
  2. package/common/animals.js +3 -5
  3. package/common/asking.js +116 -106
  4. package/common/avatar.test.json +1001 -860
  5. package/common/can.instance.json +2194 -0
  6. package/common/can.js +251 -0
  7. package/common/can.test.json +51307 -0
  8. package/common/characters.js +5 -5
  9. package/common/colors.instance.json +152 -12
  10. package/common/colors.js +3 -6
  11. package/common/comparable.instance.json +33 -3
  12. package/common/comparable.js +3 -6
  13. package/common/concept.js +25 -27
  14. package/common/concept.test.json +180 -144
  15. package/common/conjunction.js +13 -5
  16. package/common/conjunction.test.json +32 -42
  17. package/common/crew.instance.json +433 -173
  18. package/common/crew.js +4 -7
  19. package/common/crew.test.json +4148 -3324
  20. package/common/currency.js +1 -1
  21. package/common/dateTimeSelectors.instance.json +2 -2
  22. package/common/dateTimeSelectors.js +6 -9
  23. package/common/dateTimeSelectors.test.json +76935 -35739
  24. package/common/dates.instance.json +53 -3
  25. package/common/dates.js +3 -6
  26. package/common/dates.test.json +284 -287
  27. package/common/dialogues.js +43 -122
  28. package/common/dialogues.test.json +1248 -1152
  29. package/common/dimension.instance.json +21493 -561
  30. package/common/dimension.js +150 -55
  31. package/common/dimension.test.json +10979 -4625
  32. package/common/drone.instance.json +24709 -0
  33. package/common/drone.js +662 -0
  34. package/common/drone.test.json +30522 -0
  35. package/common/drone_v1.instance.json +24703 -0
  36. package/common/drone_v1.js +596 -0
  37. package/common/drone_v1.test.json +115538 -0
  38. package/common/edible.instance.json +388 -32
  39. package/common/edible.js +3 -5
  40. package/common/emotions.instance.json +85 -76
  41. package/common/emotions.js +4 -7
  42. package/common/emotions.test.json +242 -174
  43. package/common/english_helpers.js +336 -0
  44. package/common/errors.js +6 -6
  45. package/common/evaluate.js +2 -2
  46. package/common/events.js +8 -8
  47. package/common/fastfood.instance.json +1071 -393
  48. package/common/fastfood.js +14 -16
  49. package/common/fastfood.test.json +6970 -6829
  50. package/common/formulas.instance.json +11 -1
  51. package/common/formulas.js +3 -2
  52. package/common/gdefaults.js +111 -17
  53. package/common/help.js +12 -12
  54. package/common/help.test.json +65 -11
  55. package/common/helpers/concept.js +1 -1
  56. package/common/helpers/conjunction.js +54 -44
  57. package/common/helpers/dateTimeSelectors.js +2 -2
  58. package/common/helpers/dialogues.js +10 -2
  59. package/common/helpers/formulas.js +13 -11
  60. package/common/helpers/menus.js +12 -12
  61. package/common/helpers/meta.js +9 -9
  62. package/common/helpers/properties.js +186 -64
  63. package/common/helpers.js +167 -48
  64. package/common/hierarchy.js +12 -10
  65. package/common/kirk.instance.json +11 -1
  66. package/common/kirk.js +4 -6
  67. package/common/kirk.test.json +600 -424
  68. package/common/latin.instance.json +12 -12
  69. package/common/latin.js +12 -14
  70. package/common/length.instance.json +34660 -3158
  71. package/common/length.js +11 -6
  72. package/common/length.test.json +54357 -2557
  73. package/common/math.instance.json +39 -29
  74. package/common/math.js +49 -47
  75. package/common/menus.instance.json +77 -10
  76. package/common/menus.js +4 -13
  77. package/common/meta.js +80 -65
  78. package/common/nameable.js +36 -22
  79. package/common/nameable.test.json +436 -0
  80. package/common/numbers.js +1 -1
  81. package/common/ordering.instance.json +107 -19
  82. package/common/ordering.js +4 -6
  83. package/common/ordering.test.json +835 -417
  84. package/common/people.instance.json +176 -348
  85. package/common/people.js +9 -9
  86. package/common/people.test.json +4135 -3606
  87. package/common/pipboy.instance.json +187 -17
  88. package/common/pipboy.js +4 -4
  89. package/common/pokemon.instance.json +143 -13
  90. package/common/pokemon.js +4 -6
  91. package/common/pressure.instance.json +3610 -1601
  92. package/common/pressure.js +3 -5
  93. package/common/pressure.test.json +433 -477
  94. package/common/properties.instance.json +16 -17
  95. package/common/properties.js +32 -13
  96. package/common/properties.test.json +9565 -6951
  97. package/common/rates.instance.json +59 -0
  98. package/common/rates.js +95 -0
  99. package/common/rates.test.json +27702 -0
  100. package/common/reminders.instance.json +4 -4
  101. package/common/reminders.js +8 -11
  102. package/common/reminders.test.json +64635 -25787
  103. package/common/reports.instance.json +23 -3
  104. package/common/reports.js +21 -21
  105. package/common/scorekeeper.js +9 -12
  106. package/common/sdefaults.js +22 -2
  107. package/common/spock.instance.json +11 -1
  108. package/common/spock.js +4 -7
  109. package/common/spock.test.json +606 -430
  110. package/common/stgame.js +1 -1
  111. package/common/stm.js +41 -24
  112. package/common/tell.js +1 -1
  113. package/common/temperature.instance.json +3163 -1154
  114. package/common/temperature.js +3 -5
  115. package/common/temperature.test.json +433 -477
  116. package/common/tester.js +3 -3
  117. package/common/time.instance.json +24852 -0
  118. package/common/time.js +138 -141
  119. package/common/time.test.json +31876 -3757
  120. package/common/tokenize.js +5 -2
  121. package/common/ui.instance.json +12 -5
  122. package/common/ui.js +4 -13
  123. package/common/weight.instance.json +10501 -4099
  124. package/common/weight.js +3 -5
  125. package/common/weight.test.json +2601 -2263
  126. package/common/words.instance.json +9 -0
  127. package/common/words.js +50 -0
  128. package/common/words.test.json +2 -0
  129. package/common/wp.instance.json +548 -8
  130. package/common/wp.js +10 -8
  131. package/common/wp.test.json +7385 -6906
  132. package/main.js +6 -2
  133. package/package.json +25 -6
  134. package/common/listener.js +0 -50
  135. 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,27 +71,26 @@ 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/1 || number/1) [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
- { pattern: "([length])", development: true },
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
- { child: 'convertToUnits', parent: 'testingValue', development: true },
93
+ { child: 'convertToUnits', parent: 'testingValue', scope: "testing" },
74
94
  ],
75
95
  generators: [
76
96
  {
@@ -83,29 +103,21 @@ 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",
95
116
  isA: ['dimension'],
96
117
  bridge: "{ ...next(operator) }",
97
- development: true
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
  },